(&self, path: PathBuf, name: String)
| 350 | } |
| 351 | |
| 352 | fn build_c_or_cpp_test(&self, path: PathBuf, name: String) -> Option<Test> { |
| 353 | println!("compiling {path:?}"); |
| 354 | println!("cargo:rerun-if-changed={}", path.display()); |
| 355 | let contents = std::fs::read_to_string(&path).unwrap(); |
| 356 | let config = |
| 357 | wasmtime_test_util::wast::parse_test_config::<CTestConfig>(&contents, "//!").unwrap(); |
| 358 | |
| 359 | if config.skip { |
| 360 | return None; |
| 361 | } |
| 362 | |
| 363 | // The debug tests relying on these assets are ignored by default, |
| 364 | // so we cannot force the requirement of having a working WASI SDK |
| 365 | // install on everyone. At the same time, those tests (due to their |
| 366 | // monolithic nature), are always compiled, so we still have to |
| 367 | // produce the path constants. To solve this, we move the failure |
| 368 | // of missing WASI SDK from compile time to runtime by producing |
| 369 | // fake paths (that themselves will serve as diagnostic messages). |
| 370 | let wasi_sdk_path = match env::var_os("WASI_SDK_PATH") { |
| 371 | Some(path) => PathBuf::from(path), |
| 372 | None => { |
| 373 | return Some(Test { |
| 374 | name, |
| 375 | core_wasm: None, |
| 376 | }); |
| 377 | } |
| 378 | }; |
| 379 | |
| 380 | let wasm_path = self.out_dir.join(&name).with_extension("wasm"); |
| 381 | |
| 382 | let mut cmd = Command::new(wasi_sdk_path.join("bin/wasm32-wasip1-clang")); |
| 383 | cmd.arg(&path); |
| 384 | for file in config.extra_files.iter() { |
| 385 | cmd.arg(path.parent().unwrap().join(file)); |
| 386 | } |
| 387 | cmd.arg("-g"); |
| 388 | cmd.args(&config.flags); |
| 389 | cmd.arg("-o"); |
| 390 | cmd.arg(&wasm_path); |
| 391 | // If optimizations are enabled, clang will look for wasm-opt in PATH |
| 392 | // and run it. This will strip DWARF debug info, which we don't want. |
| 393 | cmd.env("PATH", ""); |
| 394 | println!("running: {cmd:?}"); |
| 395 | let result = cmd.status().expect("failed to spawn clang"); |
| 396 | assert!(result.success()); |
| 397 | |
| 398 | if config.dwp { |
| 399 | let mut dwp = Command::new(wasi_sdk_path.join("bin/llvm-dwp")); |
| 400 | dwp.arg("-e") |
| 401 | .arg(&wasm_path) |
| 402 | .arg("-o") |
| 403 | .arg(self.out_dir.join(&name).with_extension("dwp")); |
| 404 | assert!(dwp.status().expect("failed to spawn llvm-dwp").success()); |
| 405 | } |
| 406 | |
| 407 | return Some(Test { |
| 408 | name, |
| 409 | core_wasm: Some(wasm_path), |
no test coverage detected