Fixed build script: was not waiting for subcommands to finish
This commit is contained in:
parent
8a97cf48a7
commit
1dac90f0d2
|
|
@ -8,3 +8,6 @@ publish = false
|
|||
nix = { version = "0.29.0", features = ["process", "ptrace"] }
|
||||
thiserror = "2.0.12"
|
||||
color-eyre = "0.6.3"
|
||||
|
||||
[build-dependencies]
|
||||
color-eyre = "0.6.3"
|
||||
37
build.rs
37
build.rs
|
|
@ -1,22 +1,41 @@
|
|||
use color_eyre::eyre::eyre;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
let assembly_exe_path = &format!("{}/asmprog", std::env::var("OUT_DIR").unwrap());
|
||||
fn main() -> color_eyre::Result<()> {
|
||||
color_eyre::install()?;
|
||||
|
||||
println!("Building example assembly program");
|
||||
let assembly_exe_path = &format!("{}/asmprog", std::env::var("OUT_DIR")?);
|
||||
let assembly_obj_path = &format!("{}.o", assembly_exe_path);
|
||||
Command::new("nasm")
|
||||
|
||||
let status = Command::new("nasm")
|
||||
.args(&["-f", "elf64", "src/prog.nasm", "-o", assembly_obj_path])
|
||||
.spawn().expect("nasm build failed");
|
||||
Command::new("ld")
|
||||
.status()?;
|
||||
if !status.success() {
|
||||
return Err(eyre!("Nasm build failed"));
|
||||
}
|
||||
|
||||
let status = Command::new("ld")
|
||||
.args(&[assembly_obj_path, "-o", assembly_exe_path])
|
||||
.spawn().expect("linking failed");
|
||||
.status()?;
|
||||
if !status.success() {
|
||||
return Err(eyre!("Linking assembly program failed"));
|
||||
}
|
||||
|
||||
println!("cargo:rustc-env=ASM_PROG_PATH={}", assembly_exe_path);
|
||||
println!("cargo:rerun-if-changed=src/prog.nasm");
|
||||
|
||||
let c_exe_path = &format!("{}/cprog", std::env::var("OUT_DIR").unwrap());
|
||||
Command::new("gcc")
|
||||
|
||||
println!("Building example C program");
|
||||
let c_exe_path = &format!("{}/cprog", std::env::var("OUT_DIR")?);
|
||||
let status = Command::new("gcc")
|
||||
.args(&["-o", c_exe_path, "src/prog.c"])
|
||||
.spawn().expect("C program compilation failed");
|
||||
.status()?;
|
||||
if !status.success() {
|
||||
return Err(eyre!("C program compilation failed"));
|
||||
}
|
||||
println!("cargo:rustc-env=C_PROG_PATH={}", c_exe_path);
|
||||
println!("cargo:rerun-if-changed=src/prog.c");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue