Skip to content

Commit

Permalink
build: Use build.rs instead of dynamic command.
Browse files Browse the repository at this point in the history
  • Loading branch information
langyo committed Oct 21, 2023
1 parent f0d3741 commit defa6bf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions examples/proxy_wasmtime_example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.1.0"
authors = ["Langyo <langyo.china@gmail.com>"]
edition = "2021"
publish = false
build = "build.rs"

[workspace]
members = [".", "module"]
Expand Down
1 change: 1 addition & 0 deletions examples/proxy_wasmtime_example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
Run this demo by [wasmtime](https://wasmtime.dev/) with the following command:

```bash
cargo build --target wasm32-wasi --package module --release
cargo run
```
16 changes: 16 additions & 0 deletions examples/proxy_wasmtime_example/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::{env, path::Path, process::Command};

fn main() {
// Build the wasm component binary
let pwd = Path::new(env!("CARGO_MANIFEST_DIR")).to_path_buf();
Command::new("cargo")
.current_dir(pwd.clone())
.arg("build")
.arg("--target")
.arg("wasm32-wasi")
.arg("--package")
.arg("module")
.arg("--release")
.status()
.unwrap();
}
14 changes: 1 addition & 13 deletions examples/proxy_wasmtime_example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,9 @@ use {
};

fn main() -> Result<()> {
// Build the wasm component binary
let pwd = Path::new(env!("CARGO_MANIFEST_DIR")).to_path_buf();
Command::new("cargo")
.current_dir(pwd.clone())
.arg("build")
.arg("--target")
.arg("wasm32-wasi")
.arg("--package")
.arg("module")
.arg("--release")
.status()
.unwrap();

// Transfer the wasm binary to wasm component binary
let adapter = include_bytes!("../res/wasi_snapshot_preview1.command.wasm");
let pwd = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).to_path_buf();
let component = pwd.join("target/wasm32-wasi/release/module.wasm");
let component = std::fs::read(component)?;
let component = &ComponentEncoder::default()
Expand Down

0 comments on commit defa6bf

Please sign in to comment.