(
wasm: &[u8],
path: Option<&Path>,
target: Option<Triple>,
output: impl AsRef<Path>,
)
| 5 | use wasmtime::{CodeBuilder, Config, Engine, Result, error::Context as _}; |
| 6 | |
| 7 | pub fn compile_cranelift( |
| 8 | wasm: &[u8], |
| 9 | path: Option<&Path>, |
| 10 | target: Option<Triple>, |
| 11 | output: impl AsRef<Path>, |
| 12 | ) -> Result<()> { |
| 13 | let mut config = Config::new(); |
| 14 | config.debug_info(true); |
| 15 | if let Some(target) = target { |
| 16 | config.target(&target.to_string())?; |
| 17 | } |
| 18 | let engine = Engine::new(&config)?; |
| 19 | let module = CodeBuilder::new(&engine) |
| 20 | .wasm_binary_or_text(wasm, path)? |
| 21 | .compile_module()?; |
| 22 | let bytes = module.serialize()?; |
| 23 | |
| 24 | let mut file = File::create(output).context("failed to create object file")?; |
| 25 | file.write_all(&bytes) |
| 26 | .context("failed to write object file")?; |
| 27 | |
| 28 | Ok(()) |
| 29 | } |
no test coverage detected