diff --git a/compiler+runtime/include/cpp/jank/runtime/context.hpp b/compiler+runtime/include/cpp/jank/runtime/context.hpp index b7eccbc8c..b9c4c1453 100644 --- a/compiler+runtime/include/cpp/jank/runtime/context.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/context.hpp @@ -141,7 +141,7 @@ namespace jank::runtime /* TODO: This needs to be a dynamic var. */ native_unordered_map> module_dependencies; - native_persistent_string output_dir; + native_persistent_string binary_cache_dir; module::loader module_loader; var_ptr current_file_var{}; diff --git a/compiler+runtime/include/cpp/jank/util/cli.hpp b/compiler+runtime/include/cpp/jank/util/cli.hpp index 7eae043a6..17e3ee6d5 100644 --- a/compiler+runtime/include/cpp/jank/util/cli.hpp +++ b/compiler+runtime/include/cpp/jank/util/cli.hpp @@ -28,7 +28,6 @@ namespace jank::util::cli native_vector libs; /* Compilation. */ - native_transient_string compilation_path{ "classes" }; native_integer optimization_level{}; /* Run command. */ diff --git a/compiler+runtime/include/cpp/jank/util/dir.hpp b/compiler+runtime/include/cpp/jank/util/dir.hpp index d7fa9493f..0747aeb48 100644 --- a/compiler+runtime/include/cpp/jank/util/dir.hpp +++ b/compiler+runtime/include/cpp/jank/util/dir.hpp @@ -7,7 +7,13 @@ namespace jank::util native_persistent_string const &user_home_dir(); native_persistent_string const &user_cache_dir(); native_persistent_string const &user_config_dir(); - native_persistent_string const &binary_cache_dir(); + native_persistent_string const & + binary_cache_dir(native_integer const optimization_level, + native_vector const &includes, + native_vector const &defines); - native_persistent_string const &binary_version(); + native_persistent_string const & + binary_version(native_integer const optimization_level, + native_vector const &includes, + native_vector const &defines); } diff --git a/compiler+runtime/src/cpp/jank/runtime/context.cpp b/compiler+runtime/src/cpp/jank/runtime/context.cpp index dcb72a871..e461e0706 100644 --- a/compiler+runtime/src/cpp/jank/runtime/context.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/context.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include @@ -23,6 +22,7 @@ #include #include #include +#include #include #include @@ -41,7 +41,9 @@ namespace jank::runtime context::context(util::cli::options const &opts) : jit_prc{ opts } - , output_dir{ opts.compilation_path } + , binary_cache_dir{ util::binary_cache_dir(opts.optimization_level, + opts.include_dirs, + opts.define_macros) } , module_loader{ *this, opts.module_path } { auto const core(intern_ns(make_box("clojure.core"))); @@ -296,7 +298,7 @@ namespace jank::runtime { profile::timer const timer{ fmt::format("write_module {}", codegen_ctx->module_name) }; boost::filesystem::path const module_path{ - fmt::format("{}/{}.o", output_dir, module::module_to_path(codegen_ctx->module_name)) + fmt::format("{}/{}.o", binary_cache_dir, module::module_to_path(codegen_ctx->module_name)) }; boost::filesystem::create_directories(module_path.parent_path()); diff --git a/compiler+runtime/src/cpp/jank/runtime/module/loader.cpp b/compiler+runtime/src/cpp/jank/runtime/module/loader.cpp index 1e9892866..49544731b 100644 --- a/compiler+runtime/src/cpp/jank/runtime/module/loader.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/module/loader.cpp @@ -289,10 +289,10 @@ namespace jank::runtime::module native_transient_string paths{ ps }; paths += fmt::format(":{}", (jank_path / "classes").string()); paths += fmt::format(":{}", (jank_path / "../src/jank").string()); - paths += fmt::format(":{}", rt_ctx.output_dir); + paths += fmt::format(":{}", rt_ctx.binary_cache_dir); this->paths = paths; - //fmt::println("module paths: {}", paths); + // fmt::println("module paths: {}", paths); size_t start{}; size_t i{ paths.find(module_separator, start) }; diff --git a/compiler+runtime/src/cpp/jank/util/cli.cpp b/compiler+runtime/src/cpp/jank/util/cli.cpp index cda025942..4975e7a7f 100644 --- a/compiler+runtime/src/cpp/jank/util/cli.cpp +++ b/compiler+runtime/src/cpp/jank/util/cli.cpp @@ -21,9 +21,6 @@ namespace jank::util::cli fmt::format( "A {} separated list of directories, JAR files, and ZIP files to search for modules.", runtime::module::loader::module_separator)); - cli.add_option("--output-dir", - opts.compilation_path, - "The base directory where compiled modules are written."); cli.add_flag("--profile", opts.profiler_enabled, "Enable compiler and runtime profiling."); cli.add_option("--profile-output", opts.profiler_file, diff --git a/compiler+runtime/src/cpp/jank/util/dir.cpp b/compiler+runtime/src/cpp/jank/util/dir.cpp index 5eec1db6b..f57002875 100644 --- a/compiler+runtime/src/cpp/jank/util/dir.cpp +++ b/compiler+runtime/src/cpp/jank/util/dir.cpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace jank::util { @@ -61,7 +62,10 @@ namespace jank::util return res; } - native_persistent_string const &binary_cache_dir() + native_persistent_string const & + binary_cache_dir(native_integer const optimization_level, + native_vector const &includes, + native_vector const &defines) { static native_persistent_string res; if(!res.empty()) @@ -69,7 +73,8 @@ namespace jank::util return res; } - return res = fmt::format("{}/{}", user_cache_dir(), binary_version()); + return res + = fmt::format("{}/{}", "target", binary_version(optimization_level, includes, defines)); } /* The binary version is composed of two things: @@ -83,7 +88,10 @@ namespace jank::util * every module. I think this is much safer than trying to reconcile ABI * changes more granularly. */ - native_persistent_string const &binary_version() + native_persistent_string const & + binary_version(native_integer const optimization_level, + native_vector const &includes, + native_vector const &defines) { static native_persistent_string res; if(!res.empty()) @@ -91,8 +99,25 @@ namespace jank::util return res; } - auto const input( - fmt::format("{}.{}.{}", JANK_VERSION, clang::getClangRevision(), JANK_JIT_FLAGS)); + string_builder sb; + for(auto const &inc : includes) + { + sb(inc); + } + + sb("."); + + for(auto const &def : defines) + { + sb(def); + } + + auto const input(fmt::format("{}.{}.{}.{}.{}", + JANK_VERSION, + clang::getClangRevision(), + JANK_JIT_FLAGS, + optimization_level, + sb.release())); res = fmt::format("{}-{}", llvm::sys::getDefaultTargetTriple(), util::sha256(input)); //fmt::println("binary_version {}", res);