teach lucet-wasi to be smarter about build failure modes
not only can sed fail (not likely), but if wasi-sdk is not present
the failure mode is kind of opaque
@@ -6,8 +6,13 @@ use std::process::{Command, Stdio};
fn main() {
let wasi_sdk =
Path::new(&env::var("WASI_SDK").unwrap_or("/opt/wasi-sdk".to_owned())).to_path_buf();
+
+ assert!(wasi_sdk.exists(), "wasi-sdk not present at {:?}", wasi_sdk);
+
let wasi_sdk_core_h = wasi_sdk.join("share/sysroot/include/wasi/core.h");
+ assert!(wasi_sdk_core_h.exists(), "wasi-sdk core.h not present at {:?}", wasi_sdk_core_h);
+
println!("cargo:rerun-if-changed={}", wasi_sdk_core_h.display());
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
@@ -17,13 +22,21 @@ fn main() {
// `bindgen` doesn't understand typed constant macros like `UINT8_C(123)`, so this fun regex
// strips them off to yield a copy of `wasi/core.h` with bare constants.
- Command::new("sed")
+ let sed_result = Command::new("sed")
.arg("-E")
.arg(r#"s/U?INT[0-9]+_C\(((0x)?[0-9]+)\)/\1/g"#)
.arg(wasi_sdk_core_h)
.stdout(Stdio::from(core_h))
.status()
- .unwrap();
+ .expect("can execute sed");
+
+ if !sed_result.success() {
+ // something failed, but how?
+ match sed_result.code() {
+ Some(code) => panic!("sed failed with code {}", code),
+ None => panic!("sed exited abnormally")
+ }
+ }
let host_builder = bindgen::Builder::default()
.clang_arg("-nostdinc")
