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

Method execute

src/commands/compile.rs:52–103  ·  view source on GitHub ↗

Executes the command.

(mut self)

Source from the content-addressed store, hash-verified

50impl CompileCommand {
51 /// Executes the command.
52 pub fn execute(mut self) -> Result<()> {
53 self.common.init_logging()?;
54
55 let mut config = self.common.config(None)?;
56
57 if let Some(path) = self.emit_clif {
58 if !path.exists() {
59 std::fs::create_dir(&path)?;
60 }
61
62 if !path.is_dir() {
63 bail!(
64 "the path passed for '--emit-clif' ({}) must be a directory",
65 path.display()
66 );
67 }
68
69 config.emit_clif(&path);
70 }
71
72 let engine = Engine::new(&config)?;
73
74 if self.module.file_name().is_none() {
75 bail!(
76 "'{}' is not a valid input module path",
77 self.module.display()
78 );
79 }
80
81 let mut code = CodeBuilder::new(&engine);
82 code.wasm_binary_or_text_file(&self.module)?;
83
84 let output = self.output.take().unwrap_or_else(|| {
85 let mut output: PathBuf = self.module.file_name().unwrap().into();
86 output.set_extension("cwasm");
87 output
88 });
89
90 let output_bytes = match code.hint() {
91 #[cfg(feature = "component-model")]
92 Some(CodeHint::Component) => code.compile_component_serialized()?,
93 #[cfg(not(feature = "component-model"))]
94 Some(CodeHint::Component) => {
95 bail!("component model support was disabled at compile time")
96 }
97 Some(CodeHint::Module) | None => code.compile_module_serialized()?,
98 };
99 fs::write(&output, output_bytes)
100 .with_context(|| format!("failed to write output: {}", output.display()))?;
101
102 Ok(())
103 }
104}
105
106#[cfg(all(test, not(miri)))]

Callers 4

test_successful_compileFunction · 0.45
test_x64_flags_compileFunction · 0.45
test_x64_presets_compileFunction · 0.45

Calls 15

OkFunction · 0.85
init_loggingMethod · 0.80
existsMethod · 0.80
is_dirMethod · 0.80
emit_clifMethod · 0.80
file_nameMethod · 0.80
hintMethod · 0.80
with_contextMethod · 0.80
newFunction · 0.50

Tested by 4

test_successful_compileFunction · 0.36
test_x64_flags_compileFunction · 0.36
test_x64_presets_compileFunction · 0.36