Skip to content

Commit df35fab

Browse files
authored
Compile hyperlight guest c api with cargo hyperlight (#1192)
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 091fe7f commit df35fab

6 files changed

Lines changed: 19 additions & 29 deletions

File tree

Justfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ build target=default-target:
4242
# build testing guest binaries
4343
guests: build-and-move-rust-guests build-and-move-c-guests
4444

45+
ensure-cargo-hyperlight:
46+
command -v cargo-hyperlight >/dev/null 2>&1 || cargo install --locked cargo-hyperlight
47+
4548
witguest-wit:
4649
command -v wasm-tools >/dev/null 2>&1 || cargo install --locked wasm-tools
4750
cd src/tests/rust_guests/witguest && wasm-tools component wit guest.wit -w -o interface.wasm
4851
cd src/tests/rust_guests/witguest && wasm-tools component wit two_worlds.wit -w -o twoworlds.wasm
4952

50-
build-rust-guests target=default-target features="": (witguest-wit)
51-
command -v cargo-hyperlight >/dev/null 2>&1 || cargo install --locked cargo-hyperlight
53+
build-rust-guests target=default-target features="": (witguest-wit) (ensure-cargo-hyperlight)
5254
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 } }}
5355
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 } }}
5456
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)
259261
clippyw target=default-target: (witguest-wit)
260262
{{ cargo-cmd }} clippy --all-targets --all-features --target x86_64-pc-windows-gnu --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings
261263

262-
clippy-guests target=default-target: (witguest-wit)
263-
command -v cargo-hyperlight >/dev/null 2>&1 || cargo install --locked cargo-hyperlight
264+
clippy-guests target=default-target: (witguest-wit) (ensure-cargo-hyperlight)
264265
cd src/tests/rust_guests/simpleguest && cargo hyperlight clippy --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings
265266
cd src/tests/rust_guests/witguest && cargo hyperlight clippy --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings
266267

@@ -314,7 +315,7 @@ tar-headers: (build-rust-capi) # build-rust-capi is a dependency because we need
314315
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
315316

316317
tar-static-lib: (build-rust-capi "release") (build-rust-capi "debug")
317-
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
318+
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
318319

319320
# Create release notes for the given tag. The expected format is a v-prefixed version number, e.g. v0.2.0
320321
# For prereleases, the version should be "dev-latest"

c.just

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ c-flags-release-elf := '-O3'
1010

1111
build-c-guests target=default-target: (build-rust-capi target) (compile-c-guest target) (link-c-guest target)
1212

13-
build-rust-capi target=default-target:
14-
cd src/hyperlight_guest_capi && cargo build --profile {{ if target == "debug" { "dev" } else { target } }}
13+
build-rust-capi target=default-target: (ensure-cargo-hyperlight)
14+
cd src/hyperlight_guest_capi && cargo hyperlight build --profile {{ if target == "debug" { "dev" } else { target } }}
1515

1616
compile-c-guest target=default-target:
1717
# elf
1818
cd src/tests/c_guests/c_simpleguest && {{ mkdir }} "./out/{{target}}" && clang -c {{ c-compile-options-elf }} {{ if target == "debug" { c-flags-debug-elf } else { c-flags-release-elf } }} main.c {{c-include-flags-elf}} -o "out/{{ target }}/main.o"
1919

2020
link-c-guest target=default-target:
2121
# elf
22-
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}}"
22+
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}}"
2323

2424
move-c-guests target=default-target:
2525
# elf

src/hyperlight_guest_capi/.cargo/config.toml

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/hyperlight_host/tests/integration_test.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -849,10 +849,6 @@ fn test_if_guest_is_able_to_get_bool_return_values_from_host() {
849849

850850
/// Tests whether host is able to return Float/f32 as return type
851851
/// or not
852-
/// Adding Ignore attribute, due known issues with float and double
853-
/// calculations - see Github issue #179. Once it is fixed we can
854-
/// remove ignore attribute
855-
#[ignore]
856852
#[test]
857853
fn test_if_guest_is_able_to_get_float_return_values_from_host() {
858854
let mut sbox1 = new_uninit_c().unwrap();
@@ -870,10 +866,6 @@ fn test_if_guest_is_able_to_get_float_return_values_from_host() {
870866

871867
/// Tests whether host is able to return Double/f64 as return type
872868
/// or not
873-
/// Adding Ignore attribute, due known issues with float and double
874-
/// calculations - see Github issue #179. Once it is fixed we can
875-
/// remove ignore attribute
876-
#[ignore]
877869
#[test]
878870
fn test_if_guest_is_able_to_get_double_return_values_from_host() {
879871
let mut sbox1 = new_uninit_c().unwrap();

src/hyperlight_host/tests/sandbox_host_tests.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ fn pass_byte_array() {
4545
}
4646

4747
#[test]
48-
#[ignore = "Fails with mismatched float only when c .exe guest?!"]
4948
fn float_roundtrip() {
5049
let doubles = [
5150
0.0,
@@ -83,8 +82,11 @@ fn float_roundtrip() {
8382
for f in doubles.iter() {
8483
let res: f64 = sandbox.call("EchoDouble", *f).unwrap();
8584

85+
// Use == for comparison (handles -0.0 == 0.0) with special case for NaN.
86+
// Note: FlatBuffers doesn't preserve -0.0 (-0.0 round-trips to 0.0) because FlatBuffers skips
87+
// storing values equal to the default (as an optimization), and -0.0 == 0.0 in IEEE 754.
8688
assert!(
87-
res.total_cmp(f).is_eq(),
89+
(res.is_nan() && f.is_nan()) || res == *f,
8890
"Expected {:?} but got {:?}",
8991
f,
9092
res
@@ -93,8 +95,11 @@ fn float_roundtrip() {
9395
for f in floats.iter() {
9496
let res: f32 = sandbox.call("EchoFloat", *f).unwrap();
9597

98+
// Use == for comparison (handles -0.0 == 0.0) with special case for NaN.
99+
// Note: FlatBuffers doesn't preserve -0.0 (-0.0 round-trips to 0.0) because FlatBuffers skips
100+
// storing values equal to the default (as an optimization), and -0.0 == 0.0 in IEEE 754.
96101
assert!(
97-
res.total_cmp(f).is_eq(),
102+
(res.is_nan() && f.is_nan()) || res == *f,
98103
"Expected {:?} but got {:?}",
99104
f,
100105
res

src/tests/rust_guests/witguest/Cargo.lock

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

0 commit comments

Comments
 (0)