Compile a component, return the path of the binary:
(
&self,
wasm: &Path,
adapter: &[u8],
adapter_mtime: Option<&SystemTime>,
component_path: &Path,
)
| 274 | |
| 275 | // Compile a component, return the path of the binary: |
| 276 | fn compile_component( |
| 277 | &self, |
| 278 | wasm: &Path, |
| 279 | adapter: &[u8], |
| 280 | adapter_mtime: Option<&SystemTime>, |
| 281 | component_path: &Path, |
| 282 | ) { |
| 283 | // If the component exists and was last updated after the inputs that |
| 284 | // make it up then there's no need to recreate it. |
| 285 | if let Some(wasm_mtime) = mtime(wasm) |
| 286 | && let Some(adapter_mtime) = adapter_mtime |
| 287 | && let Some(component_mtime) = mtime(&component_path) |
| 288 | && wasm_mtime < component_mtime |
| 289 | && *adapter_mtime < component_mtime |
| 290 | { |
| 291 | println!("reusing cached component for {wasm:?}"); |
| 292 | return; |
| 293 | } |
| 294 | println!("creating a component from {wasm:?}"); |
| 295 | let module = fs::read(wasm).expect("read wasm module"); |
| 296 | let component = ComponentEncoder::default() |
| 297 | .module(module.as_slice()) |
| 298 | .unwrap() |
| 299 | .validate(true) |
| 300 | .adapter("wasi_snapshot_preview1", adapter) |
| 301 | .unwrap() |
| 302 | .encode() |
| 303 | .expect("module can be translated to a component"); |
| 304 | fs::write(&component_path, component).expect("write component to disk"); |
| 305 | } |
| 306 | |
| 307 | fn build_non_rust_tests(&mut self, tests: &mut Vec<Test>) { |
| 308 | const ASSETS_REL_SRC_DIR: &'static str = "../src/bin"; |