Skip to content

Remove aot acting as wasm #115

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion .github/workflows/dep_build_wasm_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,4 @@ jobs:
with:
name: guest-modules
path: |
x64/release/*.wasm
x64/release/*.aot
4 changes: 1 addition & 3 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ build-rust-wasm-examples target=default-target: (mkdir-redist target)
rustup target add wasm32-unknown-unknown
cd ./src/rust_wasm_samples && cargo build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }}
cargo run -p hyperlight-wasm-aot compile ./src/rust_wasm_samples/target/wasm32-unknown-unknown/{{ target }}/rust_wasm_samples.wasm ./x64/{{ target }}/rust_wasm_samples.aot
cp ./x64/{{ target }}/rust_wasm_samples.aot ./x64/{{ target }}/rust_wasm_samples.wasm

build-rust-component-examples target=default-target: (compile-wit)
# use cargo component so we don't get all the wasi imports https://github.com/bytecodealliance/cargo-component?tab=readme-ov-file#relationship-with-wasm32-wasip2
# we also explicitly target wasm32-unknown-unknown since cargo component might try to pull in wasi imports https://github.com/bytecodealliance/cargo-component/issues/290
rustup target add wasm32-unknown-unknown
cd ./src/component_sample && cargo component build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }}
cargo run -p hyperlight-wasm-aot compile --component ./src/component_sample/target/wasm32-unknown-unknown/{{ target }}/component_sample.wasm ./x64/{{ target }}/component_sample.aot
cp ./x64/{{ target }}/component_sample.aot ./x64/{{ target }}/component_sample.wasm

check target=default-target:
cargo check --profile={{ if target == "debug" {"dev"} else { target } }}
Expand Down Expand Up @@ -95,7 +93,7 @@ test-seccomp target=default-target features="":
cargo test {{ if features =="" {'--no-default-features -F "kvm,mshv2,seccomp"'} else {"--no-default-features -F seccomp," + features } }} test_metrics --profile={{ if target == "debug" {"dev"} else { target } }} -- --ignored --test-threads=1
cargo test {{ if features =="" {'--no-default-features -F "kvm,mshv2,seccomp"'} else {"--no-default-features -F seccomp," + features } }} test_gather_metrics --profile={{ if target == "debug" {"dev"} else { target } }} -- --ignored --test-threads=1

examples-ci target=default-target features="": (build-rust-wasm-examples target)
examples-ci target=default-target features="": (build-rust-wasm-examples target) (build-wasm-examples target)
cargo run {{ if features =="" {''} else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example helloworld
cargo run {{ if features =="" {''} else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example hostfuncs
cargo run {{ if features =="" {''} else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example rust_wasm_examples
Expand Down
16 changes: 6 additions & 10 deletions src/hyperlight_wasm/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ fn get_time_since_boot_microsecond() -> Result<i64> {
fn wasm_guest_call_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("wasm_guest_functions");

let bench_guest_function = |b: &mut Bencher<'_>, ext| {
let mut loaded_wasm_sandbox = get_loaded_wasm_sandbox(ext);
let bench_guest_function = |b: &mut Bencher<'_>| {
let mut loaded_wasm_sandbox = get_loaded_wasm_sandbox();

b.iter(|| {
loaded_wasm_sandbox
Expand All @@ -38,12 +38,8 @@ fn wasm_guest_call_benchmark(c: &mut Criterion) {
});
};

group.bench_function("wasm_guest_call", |b: &mut Bencher<'_>| {
bench_guest_function(b, "wasm");
});

group.bench_function("wasm_guest_call_aot", |b: &mut Bencher<'_>| {
bench_guest_function(b, "aot");
bench_guest_function(b);
});

group.finish();
Expand All @@ -52,7 +48,7 @@ fn wasm_guest_call_benchmark(c: &mut Criterion) {
fn wasm_sandbox_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("wasm_sandboxes");
let create_wasm_sandbox = || {
get_loaded_wasm_sandbox("wasm");
get_loaded_wasm_sandbox();
};

group.bench_function("create_sandbox", |b| {
Expand All @@ -66,7 +62,7 @@ fn wasm_sandbox_benchmark(c: &mut Criterion) {
group.finish();
}

fn get_loaded_wasm_sandbox(ext: &str) -> LoadedWasmSandbox {
fn get_loaded_wasm_sandbox() -> LoadedWasmSandbox {
let mut sandbox = SandboxBuilder::new().build().unwrap();

sandbox
Expand All @@ -79,7 +75,7 @@ fn get_loaded_wasm_sandbox(ext: &str) -> LoadedWasmSandbox {
let wasm_sandbox = sandbox.load_runtime().unwrap();

wasm_sandbox
.load_module(format!("../../x64/release/RunWasm.{ext}",))
.load_module("../../x64/release/RunWasm.aot")
.unwrap()
}

Expand Down
18 changes: 6 additions & 12 deletions src/hyperlight_wasm/benches/benchmarks_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ impl bindings::example::runcomponent::RuncomponentImports for State {
fn wasm_component_guest_call_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("wasm_component_guest_functions");

let bench_guest_function = |b: &mut Bencher<'_>, ext| {
let (sb, rt) = get_loaded_wasm_sandbox(ext);
let bench_guest_function = |b: &mut Bencher<'_>| {
let (sb, rt) = get_loaded_wasm_sandbox();
let mut wrapped = bindings::RuncomponentSandbox { sb, rt };
let instance = bindings::example::runcomponent::RuncomponentExports::guest(&mut wrapped);

Expand All @@ -56,12 +56,8 @@ fn wasm_component_guest_call_benchmark(c: &mut Criterion) {
});
};

group.bench_function("wasm_guest_call", |b: &mut Bencher<'_>| {
bench_guest_function(b, "wasm");
});

group.bench_function("wasm_guest_call_aot", |b: &mut Bencher<'_>| {
bench_guest_function(b, "aot");
bench_guest_function(b);
});

group.finish();
Expand All @@ -70,7 +66,7 @@ fn wasm_component_guest_call_benchmark(c: &mut Criterion) {
fn wasm_component_sandbox_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("wasm_component_sandboxes");
let create_wasm_sandbox = || {
get_loaded_wasm_sandbox("wasm");
get_loaded_wasm_sandbox();
};

group.bench_function("create_sandbox", |b| {
Expand All @@ -84,9 +80,7 @@ fn wasm_component_sandbox_benchmark(c: &mut Criterion) {
group.finish();
}

fn get_loaded_wasm_sandbox(
ext: &str,
) -> (
fn get_loaded_wasm_sandbox() -> (
LoadedWasmSandbox,
Arc<Mutex<bindings::RuncomponentResources<State>>>,
) {
Expand All @@ -97,7 +91,7 @@ fn get_loaded_wasm_sandbox(
let sb = sandbox.load_runtime().unwrap();

let sb = sb
.load_module(format!("../../x64/release/runcomponent.{ext}",))
.load_module("../../x64/release/runcomponent.aot")
.unwrap();
(sb, rt)
}
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_wasm/examples/component_example/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn main() {

let sb = sb.load_runtime().unwrap();

let mod_path = get_wasm_module_path("component_sample.wasm").unwrap();
let mod_path = get_wasm_module_path("component_sample.aot").unwrap();
let sb = sb.load_module(mod_path).unwrap();

let mut wrapped = bindings::ExampleSandbox { sb, rt };
Expand Down
12 changes: 1 addition & 11 deletions src/hyperlight_wasm/examples/helloworld/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,12 @@ fn get_time_since_boot_microsecond() -> Result<i64> {
}

fn main() -> Result<()> {
let tests = vec![
(
"HelloWorld.wasm",
"HelloWorld",
"Message from Rust Example to Wasm Function".to_string(),
),
let tests = [
(
"HelloWorld.aot",
"HelloWorld",
"Message from Rust Example to Wasm Function".to_string(),
),
(
"RunWasm.wasm",
"Echo",
"Message from Rust Example to Wasm Function".to_string(),
),
(
"RunWasm.aot",
"Echo",
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_wasm/examples/hostfuncs/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn main() {
let wasm_sandbox = proto_wasm_sandbox.load_runtime().unwrap();

let mut loaded_wasm_sandbox = {
let mod_path = get_wasm_module_path("rust_wasm_samples.wasm").unwrap();
let mod_path = get_wasm_module_path("rust_wasm_samples.aot").unwrap();
wasm_sandbox.load_module(mod_path)
}
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_wasm/examples/metrics/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn main() -> Result<()> {
let wasm_sandbox = wasm_sandbox.load_runtime()?;

let mut loaded_wasm_sandbox =
wasm_sandbox.load_module(get_wasm_module_path("rust_wasm_samples.wasm")?)?;
wasm_sandbox.load_module(get_wasm_module_path("rust_wasm_samples.aot")?)?;

loaded_wasm_sandbox
.call_guest_function::<i32>("add", (5i32, 10i32))
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_wasm/examples/rust_wasm_examples/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn main() -> Result<()> {
proto_wasm_sandbox.register("TestHostFunc", host_func)?;

let wasm_sandbox = proto_wasm_sandbox.load_runtime()?;
let mod_path = get_wasm_module_path("rust_wasm_samples.wasm")?;
let mod_path = get_wasm_module_path("rust_wasm_samples.aot")?;

// Load the Wasm module into the sandbox
let mut loaded_wasm_sandbox = wasm_sandbox.load_module(mod_path)?;
Expand Down
8 changes: 0 additions & 8 deletions src/hyperlight_wasm/scripts/build-wasm-examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ if [ -f "/.dockerenv" ] || grep -q docker /proc/1/cgroup; then
# Build the wasm file with wasi-libc for wasmtime
/opt/wasi-sdk/bin/clang -flto -ffunction-sections -mexec-model=reactor -O3 -z stack-size=4096 -Wl,--initial-memory=65536 -Wl,--export=__data_end -Wl,--export=__heap_base,--export=malloc,--export=free,--export=__wasm_call_ctors -Wl,--strip-all,--no-entry -Wl,--allow-undefined -Wl,--gc-sections -o ${OUTPUT_DIR}/${FILENAME%.*}-wasi-libc.wasm ${FILENAME}

# Build AOT for Wasmtime; note that Wasmtime does not support
# interpreting, so its wasm binary is secretly an AOT binary.
cargo run -p hyperlight-wasm-aot compile ${OUTPUT_DIR}/${FILENAME%.*}-wasi-libc.wasm ${OUTPUT_DIR}/${FILENAME%.*}.aot
cp ${OUTPUT_DIR}/${FILENAME%.*}.aot ${OUTPUT_DIR}/${FILENAME%.*}.wasm
done

for WIT_FILE in ${PWD}/components/*.wit; do
Expand All @@ -43,7 +40,6 @@ if [ -f "/.dockerenv" ] || grep -q docker /proc/1/cgroup; then

# Build AOT for Wasmtime
cargo run -p hyperlight-wasm-aot compile --component ${OUTPUT_DIR}/${COMPONENT_NAME}-p2.wasm ${OUTPUT_DIR}/${COMPONENT_NAME}.aot
cp ${OUTPUT_DIR}/${COMPONENT_NAME}.aot ${OUTPUT_DIR}/${COMPONENT_NAME}.wasm
done

else
Expand All @@ -62,10 +58,7 @@ else
# Build the wasm file with wasi-libc for wasmtime
docker run --rm -i -v "${PWD}:/tmp/host" -v "${OUTPUT_DIR}:/tmp/output/" wasm-clang-builder:latest /opt/wasi-sdk/bin/clang -flto -ffunction-sections -mexec-model=reactor -O3 -z stack-size=4096 -Wl,--initial-memory=65536 -Wl,--export=__data_end -Wl,--export=__heap_base,--export=malloc,--export=free,--export=__wasm_call_ctors -Wl,--strip-all,--no-entry -Wl,--allow-undefined -Wl,--gc-sections -o /tmp/output/${FILENAME%.*}-wasi-libc.wasm /tmp/host/${FILENAME}

# Build AOT for Wasmtime; note that Wasmtime does not support
# interpreting, so its wasm binary is secretly an AOT binary.
cargo run -p hyperlight-wasm-aot compile ${OUTPUT_DIR}/${FILENAME%.*}-wasi-libc.wasm ${OUTPUT_DIR}/${FILENAME%.*}.aot
cp ${OUTPUT_DIR}/${FILENAME%.*}.aot ${OUTPUT_DIR}/${FILENAME%.*}.wasm
done

echo Building components
Expand All @@ -89,7 +82,6 @@ else

# Build AOT for Wasmtime
cargo run -p hyperlight-wasm-aot compile --component ${OUTPUT_DIR}/${COMPONENT_NAME}-p2.wasm ${OUTPUT_DIR}/${COMPONENT_NAME}.aot
cp ${OUTPUT_DIR}/${COMPONENT_NAME}.aot ${OUTPUT_DIR}/${COMPONENT_NAME}.wasm
done
fi

Expand Down
103 changes: 47 additions & 56 deletions src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,26 +145,23 @@ mod tests {

#[test]
fn test_call_guest_functions_with_default_config_multiple_times() {
for ext in [".aot", ".wasm"].iter() {
let mut sandbox = ProtoWasmSandbox::default();
let mut sandbox = ProtoWasmSandbox::default();

sandbox
.register(
"GetTimeSinceBootMicrosecond",
get_time_since_boot_microsecond,
)
.unwrap();

let wasm_sandbox = sandbox.load_runtime().unwrap();
let loaded_wasm_sandbox: LoadedWasmSandbox = {
let name = format!("RunWasm{}", ext);
let mod_path = get_wasm_module_path(&name).unwrap();
wasm_sandbox.load_module(mod_path)
}
sandbox
.register(
"GetTimeSinceBootMicrosecond",
get_time_since_boot_microsecond,
)
.unwrap();

call_funcs(loaded_wasm_sandbox, 1000);
let wasm_sandbox = sandbox.load_runtime().unwrap();
let loaded_wasm_sandbox: LoadedWasmSandbox = {
let mod_path = get_wasm_module_path("RunWasm.aot").unwrap();
wasm_sandbox.load_module(mod_path)
}
.unwrap();

call_funcs(loaded_wasm_sandbox, 1000);
}

#[test]
Expand Down Expand Up @@ -253,7 +250,7 @@ mod tests {
let wasm_sandbox = wq.pop().unwrap();
println!("Loading module on thread {}", i);
let loaded_wasm_sandbox: LoadedWasmSandbox = {
let mod_path = get_wasm_module_path("RunWasm.wasm").unwrap();
let mod_path = get_wasm_module_path("RunWasm.aot").unwrap();
wasm_sandbox.load_module(mod_path)
}
.unwrap();
Expand All @@ -270,31 +267,28 @@ mod tests {

#[test]
fn test_call_guest_functions_with_custom_config_multiple_times() {
for ext in [".aot", ".wasm"].iter() {
let mut sandbox = SandboxBuilder::new()
.with_guest_stack_size(32 * 1024)
.with_guest_heap_size(128 * 1024)
.build()
.unwrap();

sandbox
.register(
"GetTimeSinceBootMicrosecond",
get_time_since_boot_microsecond,
)
.unwrap();

let wasm_sandbox = sandbox.load_runtime().unwrap();
let mut sandbox = SandboxBuilder::new()
.with_guest_stack_size(32 * 1024)
.with_guest_heap_size(128 * 1024)
.build()
.unwrap();

let loaded_wasm_sandbox: LoadedWasmSandbox = {
let name = format!("RunWasm{}", ext);
let mod_path = get_wasm_module_path(&name).unwrap();
wasm_sandbox.load_module(mod_path)
}
sandbox
.register(
"GetTimeSinceBootMicrosecond",
get_time_since_boot_microsecond,
)
.unwrap();

call_funcs(loaded_wasm_sandbox, 1000);
let wasm_sandbox = sandbox.load_runtime().unwrap();

let loaded_wasm_sandbox: LoadedWasmSandbox = {
let mod_path = get_wasm_module_path("RunWasm.aot").unwrap();
wasm_sandbox.load_module(mod_path)
}
.unwrap();

call_funcs(loaded_wasm_sandbox, 1000);
}

#[test]
Expand All @@ -316,30 +310,27 @@ mod tests {
Ok(0i32)
};

for ext in [".aot", ".wasm"].iter() {
let mut proto_wasm_sandbox = SandboxBuilder::new().build().unwrap();
let mut proto_wasm_sandbox = SandboxBuilder::new().build().unwrap();

proto_wasm_sandbox
.register("HostFuncWithBufferAndLength", host_func)
.unwrap();
proto_wasm_sandbox
.register("HostFuncWithBufferAndLength", host_func)
.unwrap();

let wasm_sandbox = proto_wasm_sandbox.load_runtime().unwrap();
let wasm_sandbox = proto_wasm_sandbox.load_runtime().unwrap();

let mut loaded_wasm_sandbox: LoadedWasmSandbox = {
let name = format!("HostFunction{}", ext);
let mod_path = get_wasm_module_path(&name).unwrap();
wasm_sandbox.load_module(mod_path)
}
.unwrap();
let mut loaded_wasm_sandbox: LoadedWasmSandbox = {
let mod_path = get_wasm_module_path("HostFunction.aot").unwrap();
wasm_sandbox.load_module(mod_path)
}
.unwrap();

// Call a guest function that calls a host function that takes a buffer and a length
// Call a guest function that calls a host function that takes a buffer and a length

let r: i32 = loaded_wasm_sandbox
.call_guest_function("PassBufferAndLengthToHost", ())
.unwrap();
let r: i32 = loaded_wasm_sandbox
.call_guest_function("PassBufferAndLengthToHost", ())
.unwrap();

assert_eq!(r, 0);
}
assert_eq!(r, 0);
}

fn call_funcs(
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_wasm/src/sandbox/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mod tests {

let wasm_sandbox = sandbox.load_runtime().unwrap();
let loaded_wasm_sandbox: LoadedWasmSandbox = {
let mod_path = get_wasm_module_path("RunWasm.wasm").unwrap();
let mod_path = get_wasm_module_path("RunWasm.aot").unwrap();
wasm_sandbox.load_module(mod_path).unwrap()
};
loaded_wasm_sandbox.unload_module().unwrap();
Expand Down
Loading
Loading