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

Support hermetic build environment #2683

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

ffortier
Copy link

@ffortier ffortier commented Dec 5, 2024

In order to support hermetic build tools like bazel, I had to resolve the lib path when compiling the libraries.rs instead of baking the absolute path from the build/main.rs file. Bazel will create a temporary sandbox to compile and execute the build script and a different sandbox to compile the resulting code.

Bonus (should be a separate PR):

The function Machine::run_module_predicate is now private to the crate so we can't do the following anymore:

  1. Create a custom Machine
  2. Load additional modules
  3. Run the repl on the pre-configured machine.

So by exporting the repl atom, we can replace this code in 0.9.4

let mut wam = Machine::new(MachineConfig::default());

wam.load_module_string("customlib", include_str!("customlib.pl").to_string());
wam.run_module_predicate(atom!("$toplevel"), (atom!("repl"), 0))

with

let mut wam = Machine::new(MachineConfig::default());

wam.load_module_string("customlib", include_str!("customlib.pl").to_string());
wam.run_query("use_module(library('$toplevel')), repl.".to_string())?;

…s instead of during he build.rs execution to support different build tools (bazel in this case)
let path = format!("{}{}", MAIN_SEPARATOR_STR, lib_path.display());
writeln!(
libraries,
"m.insert(\"{name}\", include_str!(concat!(env!(\"CARGO_MANIFEST_DIR\"), {path:?})));"
Copy link
Contributor

@Skgland Skgland Dec 5, 2024

Choose a reason for hiding this comment

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

Oh, I like it. This is a lot simpler than my implementation from #2457. Not sure how I missed using concat!(...) and env!(CARGO_MANIFEST_DIR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants