repositories / smith
smith
There are many coding harnesses - but this one is fast
owned by admin
xtask/tests/e2e_guest_build.rs
Raw//! Guest build respects target-generic CPU defaults (`SMH-SPEC-WASM0001`, `SMH-SPEC-SPEC0001`).
use std::{fs, path::PathBuf, time::Duration};
#[test]
fn e2e_guest_build_ignores_inherited_native_cpu_flags_without_changing_lockfile() {
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..");
let lockfile = root.join("Cargo.lock");
let lock_before = fs::read(&lockfile).unwrap();
let scratch = Scratch(std::env::temp_dir().join(format!(
"smith-dependency-guest-build-{}",
std::process::id()
)));
fs::create_dir_all(&scratch.0).unwrap();
let output = assert_cmd::Command::new("cargo")
.current_dir(&root)
.env_remove("RUSTFLAGS")
.env_remove("CARGO_ENCODED_RUSTFLAGS")
.args([
"build",
"--locked",
"--offline",
"--target",
"wasm32-wasip2",
"-p",
"smith-plugin-echo",
"--config",
"build.rustflags=[\"-C\",\"target-cpu=native\"]",
"--target-dir",
])
.arg(&scratch.0)
.timeout(Duration::from_secs(120))
.output()
.unwrap();
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(output.status.success(), "cargo build failed:\n{stderr}");
assert!(
!stderr.contains("not a recognized processor")
&& !stderr.contains("not a recognized feature"),
"guest build inherited native CPU flags:\n{stderr}"
);
assert_eq!(fs::read(lockfile).unwrap(), lock_before);
}
struct Scratch(PathBuf);
impl Drop for Scratch {
fn drop(&mut self) {
fs::remove_dir_all(&self.0).unwrap();
}
}