diff --git a/Justfile b/Justfile index b3dda3629..e11c16ec3 100644 --- a/Justfile +++ b/Justfile @@ -42,13 +42,15 @@ build target=default-target: # build testing guest binaries guests: build-and-move-rust-guests build-and-move-c-guests +ensure-cargo-hyperlight: + command -v cargo-hyperlight >/dev/null 2>&1 || cargo install --locked cargo-hyperlight + witguest-wit: command -v wasm-tools >/dev/null 2>&1 || cargo install --locked wasm-tools cd src/tests/rust_guests/witguest && wasm-tools component wit guest.wit -w -o interface.wasm cd src/tests/rust_guests/witguest && wasm-tools component wit two_worlds.wit -w -o twoworlds.wasm -build-rust-guests target=default-target features="": (witguest-wit) - command -v cargo-hyperlight >/dev/null 2>&1 || cargo install --locked cargo-hyperlight +build-rust-guests target=default-target features="": (witguest-wit) (ensure-cargo-hyperlight) cd src/tests/rust_guests/simpleguest && cargo hyperlight build {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} cd src/tests/rust_guests/dummyguest && cargo hyperlight build {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} cd src/tests/rust_guests/witguest && cargo hyperlight build {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} @@ -259,8 +261,7 @@ clippy target=default-target: (witguest-wit) clippyw target=default-target: (witguest-wit) {{ cargo-cmd }} clippy --all-targets --all-features --target x86_64-pc-windows-gnu --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings -clippy-guests target=default-target: (witguest-wit) - command -v cargo-hyperlight >/dev/null 2>&1 || cargo install --locked cargo-hyperlight +clippy-guests target=default-target: (witguest-wit) (ensure-cargo-hyperlight) cd src/tests/rust_guests/simpleguest && cargo hyperlight clippy --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings cd src/tests/rust_guests/witguest && cargo hyperlight clippy --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings @@ -314,7 +315,7 @@ tar-headers: (build-rust-capi) # build-rust-capi is a dependency because we need tar -zcvf include.tar.gz -C {{root}}/src/hyperlight_guest_bin/third_party/ musl/include musl/arch/x86_64 printf/printf.h -C {{root}}/src/hyperlight_guest_capi include tar-static-lib: (build-rust-capi "release") (build-rust-capi "debug") - tar -zcvf hyperlight-guest-c-api-linux.tar.gz -C {{root}}/target/x86_64-unknown-none/ release/libhyperlight_guest_capi.a -C {{root}}/target/x86_64-unknown-none/ debug/libhyperlight_guest_capi.a + tar -zcvf hyperlight-guest-c-api-linux.tar.gz -C {{root}}/target/x86_64-hyperlight-none/ release/libhyperlight_guest_capi.a -C {{root}}/target/x86_64-hyperlight-none/ debug/libhyperlight_guest_capi.a # Create release notes for the given tag. The expected format is a v-prefixed version number, e.g. v0.2.0 # For prereleases, the version should be "dev-latest" diff --git a/c.just b/c.just index aeed36808..cda6f9b1c 100644 --- a/c.just +++ b/c.just @@ -10,8 +10,8 @@ c-flags-release-elf := '-O3' build-c-guests target=default-target: (build-rust-capi target) (compile-c-guest target) (link-c-guest target) -build-rust-capi target=default-target: - cd src/hyperlight_guest_capi && cargo build --profile {{ if target == "debug" { "dev" } else { target } }} +build-rust-capi target=default-target: (ensure-cargo-hyperlight) + cd src/hyperlight_guest_capi && cargo hyperlight build --profile {{ if target == "debug" { "dev" } else { target } }} compile-c-guest target=default-target: # elf @@ -19,7 +19,7 @@ compile-c-guest target=default-target: link-c-guest target=default-target: # elf - cd src/tests/c_guests/c_simpleguest && ld.lld -o out/{{target}}/simpleguest {{c-linker-options-elf}} out/{{target}}/main.o -l hyperlight_guest_capi -L "{{justfile_directory()}}/target/x86_64-unknown-none/{{target}}" + cd src/tests/c_guests/c_simpleguest && ld.lld -o out/{{target}}/simpleguest {{c-linker-options-elf}} out/{{target}}/main.o -l hyperlight_guest_capi -L "{{justfile_directory()}}/target/x86_64-hyperlight-none/{{target}}" move-c-guests target=default-target: # elf diff --git a/src/hyperlight_guest_capi/.cargo/config.toml b/src/hyperlight_guest_capi/.cargo/config.toml deleted file mode 100644 index 17370bff2..000000000 --- a/src/hyperlight_guest_capi/.cargo/config.toml +++ /dev/null @@ -1,8 +0,0 @@ -[build] -target = "x86_64-unknown-none" - -[profile.release] -panic = "abort" - -[profile.dev] -panic = "abort" diff --git a/src/hyperlight_host/tests/integration_test.rs b/src/hyperlight_host/tests/integration_test.rs index 3bc29d98b..9a395ee81 100644 --- a/src/hyperlight_host/tests/integration_test.rs +++ b/src/hyperlight_host/tests/integration_test.rs @@ -849,10 +849,6 @@ fn test_if_guest_is_able_to_get_bool_return_values_from_host() { /// Tests whether host is able to return Float/f32 as return type /// or not -/// Adding Ignore attribute, due known issues with float and double -/// calculations - see Github issue #179. Once it is fixed we can -/// remove ignore attribute -#[ignore] #[test] fn test_if_guest_is_able_to_get_float_return_values_from_host() { let mut sbox1 = new_uninit_c().unwrap(); @@ -870,10 +866,6 @@ fn test_if_guest_is_able_to_get_float_return_values_from_host() { /// Tests whether host is able to return Double/f64 as return type /// or not -/// Adding Ignore attribute, due known issues with float and double -/// calculations - see Github issue #179. Once it is fixed we can -/// remove ignore attribute -#[ignore] #[test] fn test_if_guest_is_able_to_get_double_return_values_from_host() { let mut sbox1 = new_uninit_c().unwrap(); diff --git a/src/hyperlight_host/tests/sandbox_host_tests.rs b/src/hyperlight_host/tests/sandbox_host_tests.rs index 669f717de..6d040f061 100644 --- a/src/hyperlight_host/tests/sandbox_host_tests.rs +++ b/src/hyperlight_host/tests/sandbox_host_tests.rs @@ -45,7 +45,6 @@ fn pass_byte_array() { } #[test] -#[ignore = "Fails with mismatched float only when c .exe guest?!"] fn float_roundtrip() { let doubles = [ 0.0, @@ -83,8 +82,11 @@ fn float_roundtrip() { for f in doubles.iter() { let res: f64 = sandbox.call("EchoDouble", *f).unwrap(); + // Use == for comparison (handles -0.0 == 0.0) with special case for NaN. + // Note: FlatBuffers doesn't preserve -0.0 (-0.0 round-trips to 0.0) because FlatBuffers skips + // storing values equal to the default (as an optimization), and -0.0 == 0.0 in IEEE 754. assert!( - res.total_cmp(f).is_eq(), + (res.is_nan() && f.is_nan()) || res == *f, "Expected {:?} but got {:?}", f, res @@ -93,8 +95,11 @@ fn float_roundtrip() { for f in floats.iter() { let res: f32 = sandbox.call("EchoFloat", *f).unwrap(); + // Use == for comparison (handles -0.0 == 0.0) with special case for NaN. + // Note: FlatBuffers doesn't preserve -0.0 (-0.0 round-trips to 0.0) because FlatBuffers skips + // storing values equal to the default (as an optimization), and -0.0 == 0.0 in IEEE 754. assert!( - res.total_cmp(f).is_eq(), + (res.is_nan() && f.is_nan()) || res == *f, "Expected {:?} but got {:?}", f, res diff --git a/src/tests/rust_guests/witguest/Cargo.lock b/src/tests/rust_guests/witguest/Cargo.lock index 9d08d029b..3cd3633a1 100644 --- a/src/tests/rust_guests/witguest/Cargo.lock +++ b/src/tests/rust_guests/witguest/Cargo.lock @@ -427,9 +427,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.43" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a" +checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" dependencies = [ "proc-macro2", ]