mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
setup copying zig bitcode to the target directory
This commit is contained in:
parent
4523e90bc7
commit
4220b02913
3 changed files with 36 additions and 0 deletions
|
@ -16,6 +16,7 @@ lazy_static = "1.4.0"
|
|||
[build-dependencies]
|
||||
# dunce can be removed once ziglang/zig#5109 is fixed
|
||||
dunce = "1.0.2"
|
||||
fs_extra = "1.2.0"
|
||||
|
||||
[target.'cfg(target_os = "macos")'.build-dependencies]
|
||||
tempfile = "3.2.0"
|
||||
|
|
|
@ -67,6 +67,8 @@ fn main() {
|
|||
"builtins-wasm32.o",
|
||||
);
|
||||
|
||||
copy_zig_builtins_to_target_dir(&bitcode_path);
|
||||
|
||||
get_zig_files(bitcode_path.as_path(), &|path| {
|
||||
let path: &Path = path;
|
||||
println!(
|
||||
|
@ -144,6 +146,38 @@ fn generate_bc_file(bitcode_path: &Path, zig_object: &str, file_name: &str) {
|
|||
);
|
||||
}
|
||||
|
||||
fn copy_zig_builtins_to_target_dir(bitcode_path: &Path) {
|
||||
// To enable roc to find the zig biultins, we want them to be moved to a folder next to the roc executable.
|
||||
// So if <roc_folder>/roc is the executable. The zig files will be in <roc_folder>/lib/*.zig
|
||||
|
||||
// Currently we have the OUT_DIR variable which points to `/target/debug/build/roc_builtins-*/out/`.
|
||||
// So we just need to shed a 3 of the outer layers to get `/target/debug/` and then add `lib`.
|
||||
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||
let target_profile_dir = Path::new(&out_dir)
|
||||
.parent()
|
||||
.and_then(|path| path.parent())
|
||||
.and_then(|path| path.parent())
|
||||
.unwrap()
|
||||
.join("lib");
|
||||
|
||||
let zig_src_dir = bitcode_path.join("src");
|
||||
|
||||
std::fs::create_dir_all(&target_profile_dir).unwrap_or_else(|err| {
|
||||
panic!(
|
||||
"Failed to create output library directory for zig bitcode {:?}: {:?}",
|
||||
target_profile_dir, err
|
||||
);
|
||||
});
|
||||
let mut options = fs_extra::dir::CopyOptions::new();
|
||||
options.overwrite = true;
|
||||
fs_extra::dir::copy(&zig_src_dir, &target_profile_dir, &options).unwrap_or_else(|err| {
|
||||
panic!(
|
||||
"Failed to copy zig bitcode files {:?} to {:?}: {:?}",
|
||||
zig_src_dir, target_profile_dir, err
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
fn run_command<S, I: Copy, P: AsRef<Path> + Copy>(path: P, command_str: &str, args: I)
|
||||
where
|
||||
I: IntoIterator<Item = S>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue