diff --git a/compiler/build/src/link.rs b/compiler/build/src/link.rs index da80187fd3..a5ce3379bd 100644 --- a/compiler/build/src/link.rs +++ b/compiler/build/src/link.rs @@ -42,26 +42,40 @@ pub fn link( pub fn rebuild_host(host_input_path: &Path) { let c_host_src = host_input_path.with_file_name("host.c"); let c_host_dest = host_input_path.with_file_name("c_host.o"); + let zig_host_src = host_input_path.with_file_name("host.zig"); let rust_host_src = host_input_path.with_file_name("host.rs"); let rust_host_dest = host_input_path.with_file_name("rust_host.o"); let cargo_host_src = host_input_path.with_file_name("Cargo.toml"); let host_dest = host_input_path.with_file_name("host.o"); let env_path = env::var("PATH").unwrap_or_else(|_| "".to_string()); - // Compile host.c - let output = Command::new("clang") - .env_clear() - .env("PATH", &env_path) - .args(&[ - "-c", - c_host_src.to_str().unwrap(), - "-o", - c_host_dest.to_str().unwrap(), - ]) - .output() - .unwrap(); - validate_output("host.c", "clang", output); + if zig_host_src.exists() { + // Compile host.zig + let output = Command::new("zig") + .env_clear() + .env("PATH", &env_path) + .args(&["build-obj", zig_host_src.to_str().unwrap()]) + .output() + .unwrap(); + + validate_output("host.zig", "zig", output); + } else { + // Compile host.c + let output = Command::new("clang") + .env_clear() + .env("PATH", &env_path) + .args(&[ + "-c", + c_host_src.to_str().unwrap(), + "-o", + c_host_dest.to_str().unwrap(), + ]) + .output() + .unwrap(); + + validate_output("host.c", "clang", output); + } if cargo_host_src.exists() { // Compile and link Cargo.toml, if it exists