test_gen: update build script for easier debug

This commit is contained in:
Brian Carroll 2022-07-10 01:04:39 +01:00 committed by Folkert
parent e402f1c9d8
commit 6da71008cb
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C

View file

@ -45,48 +45,36 @@ fn build_wasm_linking_test_host() {
fs::remove_file(host_wasm).unwrap();
}
Command::new("zig")
.args([
"build-obj",
"-target",
"wasm32-freestanding-musl",
host_source,
&format!("-femit-bin={}", host_wasm),
])
.output()
.unwrap();
run_zig(&[
"build-obj",
"-target",
"wasm32-freestanding-musl",
host_source,
&format!("-femit-bin={}", host_wasm),
]);
let host_obj_path = PathBuf::from("build").join("wasm_linking_test_host.o");
let host_obj = host_obj_path.to_str().unwrap();
Command::new("zig")
.args([
"build-obj",
host_source,
&format!("-femit-bin={}", &host_obj),
])
.output()
.unwrap();
run_zig(&[
"build-obj",
host_source,
&format!("-femit-bin={}", &host_obj),
]);
let import_obj_path = PathBuf::from("build").join("wasm_linking_host_imports.o");
let import_obj = import_obj_path.to_str().unwrap();
Command::new("zig")
.args([
"build-obj",
import_source,
&format!("-femit-bin={}", &import_obj),
])
.output()
.unwrap();
run_zig(&[
"build-obj",
import_source,
&format!("-femit-bin={}", &import_obj),
]);
Command::new("zig")
.args([
"build-exe",
host_obj,
import_obj,
&format!("-femit-bin={}", host_native),
])
.output()
.unwrap();
run_zig(&[
"build-exe",
host_obj,
import_obj,
&format!("-femit-bin={}", host_native),
]);
}
fn build_wasm_test_host() {
@ -105,20 +93,17 @@ fn build_wasm_test_host() {
let mut outfile = PathBuf::from(build_dir).join(PLATFORM_FILENAME);
outfile.set_extension("wasm");
Command::new(&zig_executable())
.args([
"wasm-ld",
bitcode::BUILTINS_WASM32_OBJ_PATH,
platform_path.to_str().unwrap(),
WASI_COMPILER_RT_PATH,
WASI_LIBC_PATH,
"-o",
outfile.to_str().unwrap(),
"--no-entry",
"--relocatable",
])
.output()
.unwrap();
run_zig(&[
"wasm-ld",
bitcode::BUILTINS_WASM32_OBJ_PATH,
platform_path.to_str().unwrap(),
WASI_COMPILER_RT_PATH,
WASI_LIBC_PATH,
"-o",
outfile.to_str().unwrap(),
"--no-entry",
"--relocatable",
]);
}
fn zig_executable() -> String {
@ -132,17 +117,14 @@ fn build_wasm_platform(out_dir: &str, source_path: &str) -> PathBuf {
let mut outfile = PathBuf::from(out_dir).join(PLATFORM_FILENAME);
outfile.set_extension("o");
Command::new(&zig_executable())
.args([
"build-lib",
"-target",
"wasm32-wasi",
"-lc",
source_path,
&format!("-femit-bin={}", outfile.to_str().unwrap()),
])
.output()
.unwrap();
run_zig(&[
"build-lib",
"-target",
"wasm32-wasi",
"-lc",
source_path,
&format!("-femit-bin={}", outfile.to_str().unwrap()),
]);
outfile
}
@ -154,3 +136,10 @@ fn feature_is_enabled(feature_name: &str) -> bool {
);
env::var(cargo_env_var).is_ok()
}
// Run cargo with -vv to see commands printed out
fn run_zig(args: &[&str]) {
let zig = zig_executable();
println!("{} {}", zig, args.join(" "));
Command::new(&zig).args(args).output().unwrap();
}