Add build.rs to rebuild plugins, and a test plugin
This commit is contained in:
parent
5b40734f80
commit
8aef8ab259
8 changed files with 163 additions and 11 deletions
47
crates/plugin_runtime/build.rs
Normal file
47
crates/plugin_runtime/build.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
let base = Path::new("../../plugins");
|
||||
|
||||
// println!("cargo:rerun-if-changed=../../plugins/*");
|
||||
println!("cargo:warning=Rebuilding plugins...");
|
||||
|
||||
let _ = std::fs::remove_dir_all(base.join("bin"));
|
||||
let _ =
|
||||
std::fs::create_dir_all(base.join("bin")).expect("Could not make plugins bin directory");
|
||||
|
||||
std::process::Command::new("cargo")
|
||||
.args([
|
||||
"build",
|
||||
"--release",
|
||||
"--target",
|
||||
"wasm32-wasi",
|
||||
"--manifest-path",
|
||||
base.join("Cargo.toml").to_str().unwrap(),
|
||||
])
|
||||
.status()
|
||||
.expect("Could not build plugins");
|
||||
|
||||
let binaries = std::fs::read_dir(base.join("target/wasm32-wasi/release"))
|
||||
.expect("Could not find compiled plugins in target");
|
||||
println!("cargo:warning={:?}", binaries);
|
||||
|
||||
for file in binaries {
|
||||
let is_wasm = || {
|
||||
let path = file.ok()?.path();
|
||||
if path.extension()? == "wasm" {
|
||||
Some(path)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(path) = is_wasm() {
|
||||
std::fs::copy(&path, base.join("bin").join(path.file_name().unwrap()))
|
||||
.expect("Could not copy compiled plugin to bin");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: create .wat versions
|
||||
// TODO: optimize with wasm-opt
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue