Skip to content

Commit f89292f

Browse files
committed
bump upstream packages
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
1 parent c3f1d56 commit f89292f

5 files changed

Lines changed: 63 additions & 65 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ name = "hyperlight-wasm-http-example"
33
edition = "2024"
44

55
[dependencies]
6-
hyperlight-component-macro = { git="https://github.com/jprendes/hyperlight.git", rev="081053cbf8821997445f2f40c79818e14e6f3062" }
7-
hyperlight-common = { git="https://github.com/jprendes/hyperlight.git", rev="081053cbf8821997445f2f40c79818e14e6f3062" }
8-
hyperlight-host = { git="https://github.com/jprendes/hyperlight.git", rev="081053cbf8821997445f2f40c79818e14e6f3062", default-features = false, features = [ "kvm", "mshv2" ] }
9-
hyperlight-wasm = { git="https://github.com/jprendes/hyperlight-wasm.git", rev="2ac973b881939edbd7c0167d6b09055a52548680" }
6+
hyperlight-component-macro = { git="https://github.com/jprendes/hyperlight.git", rev="3d459364116e2e3c5b7c37598625fdf0fb540217" }
7+
hyperlight-common = { git="https://github.com/jprendes/hyperlight.git", rev="3d459364116e2e3c5b7c37598625fdf0fb540217" }
8+
hyperlight-host = { git="https://github.com/jprendes/hyperlight.git", rev="3d459364116e2e3c5b7c37598625fdf0fb540217", default-features = false, features = [ "kvm", "mshv2" ] }
9+
hyperlight-wasm = { git="https://github.com/jprendes/hyperlight-wasm.git", rev="134d8fc355ef842ace918777a758349342241c9d" }
1010

1111
hyper = "1.7"
1212
reqwest = { version = "0.12", features = ["stream", "gzip", "brotli", "deflate", "rustls-tls", "blocking"] }
@@ -16,6 +16,3 @@ anyhow = "1.0"
1616
http-body-util = "0.1"
1717
hyper-util = { version = "0.1", features = ["full"] }
1818
getrandom = "0.3.3"
19-
20-
[features]
21-
use-macro = []

README.md

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,61 +14,68 @@ server](https://github.com/bytecodealliance/sample-wasi-http-rust).
1414

1515
1. [Rust](https://www.rust-lang.org/tools/install), including the `x86_64-unknown-none` target (which may be installed via e.g. `rustup target add x86_64-unknown-none`)
1616
2. `clang`
17-
3. [`wasm-tools`](https://github.com/bytecodealliance/wasm-tools)
18-
4. If you are fetching the sample binary from an OCI registry,
19-
[`wkg`](https://crates.io/crates/wkg/0.10.0).
20-
5. [`hyperlight-wasm-aot`](https://github.com/hyperlight-dev/hyperlight-wasm)
21-
6. [`just`](https://github.com/casey/just) (optional, but recommended)
17+
3. [`just`](https://github.com/casey/just) (optional, but recommended)
2218

23-
`wasm-tools`, `wkg`, and `hyperlight-wasm-aot` will be automaticall installed if they are not present.
19+
If you want to follow the manual build instructions, you will also need:
20+
4. [`wasm-tools`](https://github.com/bytecodealliance/wasm-tools)
21+
5. If you are fetching the sample binary from an OCI registry,
22+
[`wkg`](https://crates.io/crates/wkg/0.10.0).
23+
6. [`hyperlight-wasm-aot`](https://github.com/hyperlight-dev/hyperlight-wasm) from [this commit](https://github.com/jprendes/hyperlight-wasm/tree/134d8fc35)
2424

25-
## Building
25+
## Simply setup
2626

27-
The easy way is to just run
27+
### Building
2828

2929
```sh
3030
just build
3131
```
3232

33-
The manual way is as follows.
33+
### Running
34+
35+
```sh
36+
just run
37+
```
38+
39+
From another terminal, you can then test the server:
40+
41+
```sh
42+
curl http://localhost:3000/
43+
curl -w'\n' -d "hola mundo" http://127.0.0.1:3000/echo
44+
curl -I -H "x-language: spanish" http://127.0.0.1:3000/echo-headers
45+
```
46+
47+
## Manual setup
48+
49+
### Building
3450

3551
Compile the WIT and set the environment variables used when building
3652
(both the host and the guest):
3753

3854
```sh
3955
wasm-tools component wit hyperlight.wit -w -o hyperlight-world.wasm
40-
export WIT_WORLD=$PWD/hyperlight-world.wasm
4156
```
4257

4358
Build:
4459
```
4560
cargo build
4661
```
4762

48-
## Running
49-
50-
The easy way is to just run
51-
52-
```sh
53-
just run
54-
```
55-
56-
The manual way is as follows.
63+
### Running
5764

5865
Get an `sample_wasi_http_rust.wasm` from [the sample
5966
repo](https://github.com/bytecodealliance/sample-wasi-http-rust), either
60-
by building it or by fetching it from the OCI registry (`wkg oci pull
61-
ghcr.io/bytecodealliance/sample-wasi-http-rust/sample-wasi-http-rust:latest -o sample_wasi_http_rust.wasm`).
67+
by building it or by fetching it from the OCI registry
68+
(`wkg oci pull ghcr.io/bytecodealliance/sample-wasi-http-rust/sample-wasi-http-rust:latest -o sample_wasi_http_rust.wasm`).
6269

6370
AOT compile it:
6471

6572
```sh
66-
cargo install hyperlight-wasm-aot
73+
cargo install hyperlight-wasm-aot --git https://github.com/jprendes/hyperlight-wasm.git --rev 134d8fc35
6774
hyperlight-wasm-aot compile --component sample_wasi_http_rust.wasm sample_wasi_http_rust.bin
6875
```
6976

7077
You can then run the server:
7178

7279
```sh
73-
cargo run # or target/debug/echo
80+
cargo run -- sample_wasi_http_rust.bin
7481
```

justfile

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,51 @@
22
install-wkg:
33
#!/bin/bash
44
set -euox pipefail
5-
if ! command -v wkg > /dev/null; then
6-
cargo install wkg
5+
if ! [[ -f {{ justfile_directory() }}/target/bin/wkg ]]; then
6+
cargo install wkg \
7+
--root {{ justfile_directory() }}/target
78
fi
89

910
get-component: install-wkg
1011
#!/bin/bash
1112
set -euox pipefail
1213
if ! [[ -f sample_wasi_http_rust.wasm ]]; then
13-
wkg oci pull \
14+
{{ justfile_directory() }}/target/bin/wkg oci pull \
1415
ghcr.io/bytecodealliance/sample-wasi-http-rust/sample-wasi-http-rust:latest \
1516
-o sample_wasi_http_rust.wasm
1617
fi
1718

1819
install-hyperlight-wasm-aot:
1920
#!/bin/bash
2021
set -euox pipefail
21-
if ! command -v hyperlight-wasm-aot > /dev/null; then
22-
cargo install hyperlight-wasm-aot
22+
if ! [[ -f {{ justfile_directory() }}/target/bin/hyperlight-wasm-aot ]]; then
23+
cargo install hyperlight-wasm-aot \
24+
--git https://github.com/jprendes/hyperlight-wasm.git \
25+
--rev 134d8fc355ef842ace918777a758349342241c9d \
26+
--root {{ justfile_directory() }}/target
2327
fi
2428

2529
aot-component: get-component install-hyperlight-wasm-aot
2630
#!/bin/bash
2731
set -euox pipefail
28-
hyperlight-wasm-aot compile --component sample_wasi_http_rust.wasm sample_wasi_http_rust.bin
32+
{{ justfile_directory() }}/target/bin/hyperlight-wasm-aot compile --component sample_wasi_http_rust.wasm sample_wasi_http_rust.bin
2933

3034
install-wasm-tools:
3135
#!/bin/bash
3236
set -euox pipefail
33-
if ! command -v wasm-tools > /dev/null; then
34-
cargo install wasm-tools
37+
if ! [[ -f {{ justfile_directory() }}/target/bin/wasm-tools ]]; then
38+
cargo install wasm-tools \
39+
--root {{ justfile_directory() }}/target
3540
fi
3641

3742
make-wit-world: install-wasm-tools
3843
#!/bin/bash
3944
set -euox pipefail
4045
if ! [[ -f hyperlight-world.wasm ]]; then
41-
wasm-tools component wit hyperlight.wit -w -o hyperlight-world.wasm
46+
{{ justfile_directory() }}/target/bin/wasm-tools component wit hyperlight.wit -w -o hyperlight-world.wasm
4247
fi
4348

44-
generate-bindings: make-wit-world
45-
#!/bin/bash
46-
set -euox pipefail
47-
if ! [[ -f {{ justfile_directory() }}/src/bindings.rs ]]; then
48-
export WIT_WORLD={{ justfile_directory() }}/hyperlight-world.wasm
49-
export HYPERLIGHT_COMPONENT_MACRO_DEBUG={{ justfile_directory() }}/src/bindings.rs
50-
cargo build --features=use-macro || true
51-
git apply --no-index {{ justfile_directory() }}/bindings.patch
52-
fi
53-
54-
build: generate-bindings
49+
build: make-wit-world
5550
#!/bin/bash
5651
set -euox pipefail
5752
export WIT_WORLD={{ justfile_directory() }}/hyperlight-world.wasm

src/main.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
extern crate alloc;
22

3-
#[cfg(feature = "use-macro")]
43
mod bindings {
54
hyperlight_component_macro::host_bindgen!();
65
}
76

8-
// the bindings mod is like the above definition, but with an extra line that the
9-
// macro is currently missing:
10-
// let mut rts = self.rt.lock().unwrap();
11-
// without that line, the generated code doesn't compile
12-
// See bindings.patch for the diff
13-
#[cfg(not(feature = "use-macro"))]
14-
mod bindings;
15-
167
mod resource;
178
mod types;
189
mod worker;
@@ -34,6 +25,14 @@ use worker::RUNTIME;
3425
use crate::bindings::wasi::http::IncomingHandler;
3526

3627
fn main() {
28+
let args = std::env::args().collect::<Vec<_>>();
29+
if args.len() != 2 {
30+
eprintln!("Usage: {} <AOT_WASM_FILE>", args[0]);
31+
std::process::exit(1);
32+
}
33+
34+
let wasm_path = &args[1];
35+
3736
let builder = hyperlight_wasm::SandboxBuilder::new()
3837
.with_guest_heap_size(30 * 1024 * 1024)
3938
.with_guest_stack_size(1 * 1024 * 1024);
@@ -51,7 +50,7 @@ fn main() {
5150
let rt = bindings::register_host_functions(&mut sb, state);
5251

5352
let sb = sb.load_runtime().unwrap();
54-
let sb = sb.load_module("sample_wasi_http_rust.bin").unwrap();
53+
let sb = sb.load_module(wasm_path).unwrap();
5554

5655
let sb = bindings::RootSandbox { sb, rt };
5756
let sb = Arc::new(Mutex::new(sb));

0 commit comments

Comments
 (0)