Skip to content

Commit 5dbaba2

Browse files
committed
Update host to use wasi 0.2.9
- Prepare for multiple guest components - Upgrade the rust version used - Move hyperlight wit file under a `wit/host` directory Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
1 parent 78685ea commit 5dbaba2

File tree

11 files changed

+854
-664
lines changed

11 files changed

+854
-664
lines changed

Cargo.lock

Lines changed: 715 additions & 552 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ cargo build
6363
Build the guest component:
6464
```sh
6565
cargo component build --release \
66-
--manifest-path guest/Cargo.toml \
66+
--manifest-path guest_rust/Cargo.toml \
6767
--target-dir target
6868
```
6969

@@ -73,11 +73,11 @@ AOT compile it:
7373
cargo install hyperlight-wasm-aot
7474
hyperlight-wasm-aot compile --component \
7575
target/wasm32-wasip1/release/sample_wasi_http_rust.wasm \
76-
target/wasm32-wasip1/release/sample_wasi_http_rust.bin
76+
out/sample_wasi_http_rust.aot
7777
```
7878

7979
You can then run the server:
8080

8181
```sh
82-
cargo run -- target/wasm32-wasip1/release/sample_wasi_http_rust.bin
82+
cargo run -- out/sample_wasi_http_rust.aot
8383
```
Lines changed: 63 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use wstd::http::body::{BodyForthcoming, IncomingBody};
22
use wstd::http::server::{Finished, Responder};
33
use wstd::http::{IntoBody, Request, Response, StatusCode};
4-
use wstd::io::{copy, empty, AsyncWrite};
4+
use wstd::io::{AsyncWrite, copy, empty};
55
use wstd::time::{Duration, Instant};
66

77
#[wstd::http_server]
@@ -19,7 +19,7 @@ async fn main(req: Request<IncomingBody>, res: Responder) -> Finished {
1919

2020
async fn home(_req: Request<IncomingBody>, res: Responder) -> Finished {
2121
// To send a single string as the response body, use `res::respond`.
22-
res.respond(Response::new("Hello, wasi:http/proxy world!\n".into_body()))
22+
res.respond(Response::new("Hello, Rust wasi:http world!\n".into_body()))
2323
.await
2424
}
2525

@@ -97,4 +97,4 @@ async fn proxy(_req: Request<IncomingBody>, res: Responder) -> Finished {
9797
let mut body = res.start_response(Response::new(BodyForthcoming));
9898
let result = copy(upstream_res.body_mut(), &mut body).await;
9999
Finished::finish(body, result, None)
100-
}
100+
}

justfile

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
11
TARGET_DIR := justfile_directory() + "/target"
22
BIN_DIR := TARGET_DIR + "/bin"
3-
GUEST_DIR := justfile_directory() + "/guest"
3+
OUT_DIR := justfile_directory() + "/out"
4+
default-target := "release"
45

56
default: run
67

7-
install-cargo-component:
8-
test -f {{ BIN_DIR }}/cargo-component || \
9-
cargo install cargo-component \
10-
--root {{ TARGET_DIR }}
11-
12-
build-component: install-cargo-component
13-
test -f {{ TARGET_DIR }}/wasm32-wasip1/release/sample_wasi_http_rust.wasm || \
14-
cargo-component build --release \
15-
--manifest-path {{ GUEST_DIR }}/Cargo.toml \
16-
--target-dir {{ TARGET_DIR }}
8+
make-out-dir:
9+
mkdir -p {{ OUT_DIR }}
1710

1811
install-hyperlight-wasm-aot:
1912
test -f {{ BIN_DIR }}/hyperlight-wasm-aot || \
2013
cargo install hyperlight-wasm-aot \
14+
--locked \
15+
--version 0.9.0 \
2116
--root {{ TARGET_DIR }}
2217

23-
aot-component: build-component install-hyperlight-wasm-aot
24-
{{ BIN_DIR }}/hyperlight-wasm-aot compile --component \
25-
{{ TARGET_DIR }}/wasm32-wasip1/release/sample_wasi_http_rust.wasm \
26-
{{ TARGET_DIR }}/wasm32-wasip1/release/sample_wasi_http_rust.bin
18+
build-rust-component target=default-target: make-out-dir install-hyperlight-wasm-aot
19+
cargo component build \
20+
--profile={{ if target == "debug" { "dev" } else { target } }} \
21+
--manifest-path guest_rust/Cargo.toml \
22+
--target-dir {{ TARGET_DIR }}
23+
cp {{ TARGET_DIR }}/wasm32-wasip1/{{ target }}/sample_wasi_http_rust.wasm {{ OUT_DIR }}/sample_wasi_http_rust.wasm
24+
cd {{ OUT_DIR }} && {{ BIN_DIR }}/hyperlight-wasm-aot compile --component sample_wasi_http_rust.wasm
2725

2826
install-wasm-tools:
2927
test -f {{ BIN_DIR }}/wasm-tools || \
3028
cargo install wasm-tools \
3129
--root {{ TARGET_DIR }}
3230

3331
make-wit-world: install-wasm-tools
34-
test -f hyperlight-world.wasm || \
35-
{{ BIN_DIR }}/wasm-tools component wit hyperlight.wit -w -o hyperlight-world.wasm
32+
{{ BIN_DIR }}/wasm-tools component wit wit/host/hyperlight.wit -w -o hyperlight-world.wasm
3633

3734
build: make-wit-world
3835
cargo build
3936

40-
run: build aot-component
41-
cargo run -- {{ TARGET_DIR }}/wasm32-wasip1/release/sample_wasi_http_rust.bin
37+
run: build build-rust-component
38+
cargo run -- {{ OUT_DIR }}/sample_wasi_http_rust.aot
39+

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[toolchain]
2-
channel = "1.87.0"
2+
channel = "1.89.0"

src/types/random.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ impl wasi::random::Random for WasiImpl {
88
getrandom::fill(&mut buf).unwrap();
99
buf
1010
}
11+
fn get_random_u64(&mut self) -> u64 {
12+
getrandom::u64().unwrap()
13+
}
1114
}

0 commit comments

Comments
 (0)