Skip to content

Commit

Permalink
Include bytes at compile time in compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
redoC-A2k committed May 31, 2024
1 parent 350339f commit ed50b9b
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions JS/wasm/crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,22 @@ fn main() -> Result<()> {
}

println!("\nStarting to build arakoo compatible module");
let wasm: Vec<u8> =
if let Ok(wasm_bytes) = std::fs::read(concat!(env!("OUT_DIR"), "/engine.wasm")) {
wasm_bytes
} else {
// Provide a fallback wasm binary if the file is not found
panic!("Engine wasm not found");
};
// let wasm: Vec<u8> =
// if let Ok(wasm_bytes) = std::fs::read(concat!(env!("OUT_DIR"), "/engine.wasm")) {
// wasm_bytes
// } else {
// // Provide a fallback wasm binary if the file is not found
// panic!("Engine wasm not found");
// };
let wasm: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/engine.wasm"));

println!("Preinitializing using Wizer");
let mut wasm = Wizer::new()
.allow_wasi(true)?
.inherit_stdio(true)
.wasm_bulk_memory(true)
.inherit_env(true)
.run(wasm.as_slice())?;
.run(wasm)?;

let codegen_config = CodegenConfig {
optimization_level: 3,
Expand All @@ -72,13 +73,12 @@ fn main() -> Result<()> {
}

println!("Adapting module for component model");
let adapter_path = concat!(env!("OUT_DIR"), "/adapter.wasm");
wasm = ComponentEncoder::default()
.validate(true)
.module(&wasm)?
.adapter(
"wasi_snapshot_preview1",
&fs::read(adapter_path).expect("Unable to read adapter"),
include_bytes!(concat!(env!("OUT_DIR"), "/adapter.wasm"))
)?
.encode()?;

Expand Down

0 comments on commit ed50b9b

Please sign in to comment.