Merge branch 'trunk' into linker

This commit is contained in:
Brendan Hansknecht 2021-09-11 22:55:07 -07:00
commit 1d23f4c0d2
28 changed files with 683 additions and 324 deletions

View file

@ -59,6 +59,22 @@ fn find_zig_str_path() -> PathBuf {
panic!("cannot find `str.zig`")
}
fn find_wasi_libc_path() -> PathBuf {
let wasi_libc_path = PathBuf::from("compiler/builtins/bitcode/wasi-libc.a");
if std::path::Path::exists(&wasi_libc_path) {
return wasi_libc_path;
}
// when running the tests, we start in the /cli directory
let wasi_libc_path = PathBuf::from("../compiler/builtins/bitcode/wasi-libc.a");
if std::path::Path::exists(&wasi_libc_path) {
return wasi_libc_path;
}
panic!("cannot find `wasi-libc.a`")
}
#[cfg(not(target_os = "macos"))]
pub fn build_zig_host_native(
env_path: &str,
@ -617,6 +633,7 @@ fn link_wasm32(
_link_type: LinkType,
) -> io::Result<(Child, PathBuf)> {
let zig_str_path = find_zig_str_path();
let wasi_libc_path = find_wasi_libc_path();
let child = Command::new("zig9")
// .env_clear()
@ -624,9 +641,10 @@ fn link_wasm32(
.args(&["build-exe"])
.args(input_paths)
.args([
// include wasi libc
// using `-lc` is broken in zig 8 (and early 9) in combination with ReleaseSmall
wasi_libc_path.to_str().unwrap(),
&format!("-femit-bin={}", output_path.to_str().unwrap()),
// include libc
"-lc",
"-target",
"wasm32-wasi-musl",
"--pkg-begin",
@ -634,7 +652,8 @@ fn link_wasm32(
zig_str_path.to_str().unwrap(),
"--pkg-end",
"--strip",
// "-O", "ReleaseSmall",
"-O",
"ReleaseSmall",
// useful for debugging
// "-femit-llvm-ir=/home/folkertdev/roc/roc/examples/benchmarks/platform/host.ll",
])