MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / build_non_rust_tests

Method build_non_rust_tests

crates/test-programs/artifacts/build.rs:307–350  ·  view source on GitHub ↗
(&mut self, tests: &mut Vec<Test>)

Source from the content-addressed store, hash-verified

305 }
306
307 fn build_non_rust_tests(&mut self, tests: &mut Vec<Test>) {
308 const ASSETS_REL_SRC_DIR: &'static str = "../src/bin";
309 println!("cargo:rerun-if-changed={ASSETS_REL_SRC_DIR}");
310
311 let entries = fs::read_dir(ASSETS_REL_SRC_DIR)
312 .unwrap()
313 .map(|e| e.unwrap())
314 .collect::<Vec<_>>();
315 let mut c_tests = entries
316 .par_iter()
317 .flat_map(|entry| {
318 let path = entry.path();
319 let name = path.file_stem().unwrap().to_str().unwrap().to_owned();
320 match path.extension().and_then(|s| s.to_str()) {
321 // Compile C/C++ tests with clang
322 Some("c") | Some("cc") => self.build_c_or_cpp_test(path, name),
323
324 // just a header, part of another test.
325 Some("h") => None,
326
327 // Convert the text format to binary and use it as a test.
328 Some("wat") => {
329 let wasm = wat::parse_file(&path).unwrap();
330 let core_wasm = self.out_dir.join(&name).with_extension("wasm");
331 fs::write(&core_wasm, &wasm).unwrap();
332 Some(Test {
333 name,
334 core_wasm: Some(core_wasm),
335 })
336 }
337
338 // these are built above in `build_rust_tests`
339 Some("rs") => None,
340
341 // Prevent stray files for now that we don't understand.
342 Some(_) => panic!("unknown file extension on {path:?}"),
343
344 None => unreachable!("no extension in path {path:?}"),
345 }
346 })
347 .collect::<Vec<_>>();
348 c_tests.sort_by_key(|t| t.name.clone());
349 tests.extend(c_tests);
350 }
351
352 fn build_c_or_cpp_test(&self, path: PathBuf, name: String) -> Option<Test> {
353 println!("compiling {path:?}");

Callers 1

buildMethod · 0.80

Calls 11

read_dirFunction · 0.85
to_strMethod · 0.80
build_c_or_cpp_testMethod · 0.80
sort_by_keyMethod · 0.80
writeFunction · 0.50
mapMethod · 0.45
unwrapMethod · 0.45
pathMethod · 0.45
joinMethod · 0.45
cloneMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected