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

Method build_adapter

crates/test-programs/artifacts/build.rs:220–273  ·  view source on GitHub ↗

Build the WASI Preview 1 adapter, and get the binary:

(
        &mut self,
        generated_code: &mut String,
        name: &str,
        features: &[&str],
    )

Source from the content-addressed store, hash-verified

218
219 // Build the WASI Preview 1 adapter, and get the binary:
220 fn build_adapter(
221 &mut self,
222 generated_code: &mut String,
223 name: &str,
224 features: &[&str],
225 ) -> (Vec<u8>, Option<SystemTime>) {
226 let mut cmd = cargo();
227 cmd.arg("build")
228 .arg("--release")
229 .arg("-vv")
230 .arg("--package=wasi-preview1-component-adapter")
231 .arg("--target=wasm32-unknown-unknown")
232 .env("CARGO_BUILD_BUILD_DIR", &self.out_dir)
233 .env("CARGO_TARGET_DIR", &self.out_dir.join(name))
234 .env("RUSTFLAGS", rustflags())
235 .env_remove("CARGO_ENCODED_RUSTFLAGS");
236 for f in features {
237 cmd.arg(f);
238 }
239 eprintln!("running: {cmd:?}");
240 let status = cmd.status().unwrap();
241 assert!(status.success());
242
243 let artifact = self
244 .out_dir
245 .join(name)
246 .join("wasm32-unknown-unknown")
247 .join("release")
248 .join("wasi_snapshot_preview1.wasm");
249 let adapter = self
250 .out_dir
251 .join(format!("wasi_snapshot_preview1.{name}.wasm"));
252
253 if let Ok(prev) = std::fs::read(&adapter)
254 && let Ok(cur) = std::fs::read(&artifact)
255 && prev == cur
256 {
257 // nothing to do ...
258 } else {
259 if adapter.exists() {
260 fs::remove_file(&adapter).unwrap();
261 }
262 std::fs::hard_link(&artifact, &adapter)
263 .or_else(|_| std::fs::copy(&artifact, &adapter).map(|_| ()))
264 .unwrap();
265 }
266 self.read_deps_of(&artifact);
267 println!("wasi {name} adapter: {:?}", &adapter);
268 generated_code.push_str(&format!(
269 "pub const ADAPTER_{}: &'static str = {adapter:?};\n",
270 name.to_shouty_snake_case(),
271 ));
272 (fs::read(&adapter).unwrap(), mtime(&adapter))
273 }
274
275 // Compile a component, return the path of the binary:
276 fn compile_component(

Callers 1

buildMethod · 0.80

Calls 13

mtimeFunction · 0.85
statusMethod · 0.80
existsMethod · 0.80
read_deps_ofMethod · 0.80
cargoFunction · 0.70
rustflagsFunction · 0.70
readFunction · 0.50
envMethod · 0.45
argMethod · 0.45
joinMethod · 0.45
unwrapMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected