Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip compiling and serializing embedded wraps when building in docs.rs #245

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
);
}
}
}
Loading