Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compilation): compilation directory depends on more cli flags #270

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler+runtime/include/cpp/jank/runtime/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ namespace jank::runtime
/* TODO: This needs to be a dynamic var. */
native_unordered_map<native_persistent_string, native_vector<native_persistent_string>>
module_dependencies;
native_persistent_string output_dir;
native_persistent_string binary_cache_dir;
module::loader module_loader;

var_ptr current_file_var{};
Expand Down
1 change: 0 additions & 1 deletion compiler+runtime/include/cpp/jank/util/cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ namespace jank::util::cli
native_vector<native_persistent_string> libs;

/* Compilation. */
native_transient_string compilation_path{ "classes" };
native_integer optimization_level{};

/* Run command. */
Expand Down
10 changes: 8 additions & 2 deletions compiler+runtime/include/cpp/jank/util/dir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<native_persistent_string> const &includes,
native_vector<native_persistent_string> const &defines);

native_persistent_string const &binary_version();
native_persistent_string const &
binary_version(native_integer const optimization_level,
native_vector<native_persistent_string> const &includes,
native_vector<native_persistent_string> const &defines);
}
9 changes: 6 additions & 3 deletions compiler+runtime/src/cpp/jank/runtime/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <llvm/TargetParser/Host.h>

#include <fmt/compile.h>
#include <regex>

#include <jank/native_persistent_string/fmt.hpp>
#include <jank/read/lex.hpp>
Expand All @@ -23,6 +22,7 @@
#include <jank/util/mapped_file.hpp>
#include <jank/util/process_location.hpp>
#include <jank/util/clang_format.hpp>
#include <jank/util/dir.hpp>
#include <jank/codegen/llvm_processor.hpp>
#include <jank/profile/time.hpp>

Expand All @@ -41,7 +41,10 @@ namespace jank::runtime

context::context(util::cli::options const &opts)
: jit_prc{ opts }
, output_dir{ opts.compilation_path }
, binary_cache_dir{ fmt::format(
"{}/{}",
util::binary_cache_dir(opts.optimization_level, opts.include_dirs, opts.define_macros),
"classes") }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for classes at all. That's a carry-over from the JVM.

, module_loader{ *this, opts.module_path }
{
auto const core(intern_ns(make_box<obj::symbol>("clojure.core")));
Expand Down Expand Up @@ -296,7 +299,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());

Expand Down
4 changes: 2 additions & 2 deletions compiler+runtime/src/cpp/jank/runtime/module/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
Expand Down
3 changes: 0 additions & 3 deletions compiler+runtime/src/cpp/jank/util/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,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,
Expand Down
36 changes: 31 additions & 5 deletions compiler+runtime/src/cpp/jank/util/dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <jank/native_persistent_string/fmt.hpp>
#include <jank/util/dir.hpp>
#include <jank/util/sha256.hpp>
#include <jank/util/string_builder.hpp>

namespace jank::util
{
Expand Down Expand Up @@ -61,15 +62,20 @@ 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<native_persistent_string> const &includes,
native_vector<native_persistent_string> const &defines)
{
static native_persistent_string res;
if(!res.empty())
{
return res;
}

return res = fmt::format("{}/{}", user_cache_dir(), binary_version());
return res = fmt::format("{}/{}",
user_cache_dir(),
binary_version(optimization_level, includes, defines));
Comment on lines -72 to +78
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I was wrong, Saket. This is not going to work. If two separate projects both have ns a, with different code, then compiling one project first, then going to compile the other project could result in loading the first project's a when you go to compile the second.

This could work fine for dependencies from maven, but we don't have a good way to distinguish them from project sources right now. To mitigate this, let's put the binary cache dir in target/<binary version>, relative to the current directory. This is what leiningen does. So we should just be able to replace user_cache_dir here with "target".

}

/* The binary version is composed of two things:
Expand All @@ -83,16 +89,36 @@ 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<native_persistent_string> const &includes,
native_vector<native_persistent_string> const &defines)
{
static native_persistent_string res;
if(!res.empty())
{
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);
Expand Down