Skip to content

Commit

Permalink
skip compiling and serializing embedded wraps when building in docs.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
pileks committed Oct 5, 2023
1 parent 0b89c29 commit d7afbcf
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packages/default-config/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use std::fs;
use polywrap_wasm::{self, wasm_module::WasmModule};
use std::fs;

fn main() {
// If the package is being built by docs.rs, we skip compiling and serializing the embedded wraps
if std::env::var("DOCS_RS").is_ok() {
return;
}

// Compile and serialize all wasm modules in the src/embeds directory
// It's faster to deserialize from a serialized module than to compile from a wasm file
for directory in fs::read_dir("./src/embeds").unwrap().into_iter() {
Expand All @@ -14,8 +19,15 @@ fn main() {
let compiled_module = WasmModule::WasmBytecode(wasm.into()).compile().unwrap();
let serialized_module = compiled_module.serialize().unwrap();

fs::write(format!("{}/wrap.serialized", directory.path().to_str().unwrap()), serialized_module.serialize_for_storage()).unwrap();
fs::write(
format!("{}/wrap.serialized", directory.path().to_str().unwrap()),
serialized_module.serialize_for_storage(),
)
.unwrap();

println!("cargo:rerun-if-changed={}", format!("{}/wrap.wasm", directory.path().to_str().unwrap()));
println!(
"cargo:rerun-if-changed={}",
format!("{}/wrap.wasm", directory.path().to_str().unwrap())
);
}
}
}

0 comments on commit d7afbcf

Please sign in to comment.