Skip to content

Commit 3b36e14

Browse files
committed
Rename eval-expression to evalexpression in calcualtor component to work around bug in hyperlight-wasm and also use release profiles for wasm components so we do not need to plug wasi interfaces with wasi-virt stubs
Signed-off-by: Mark Rossett <[email protected]>
1 parent ccdc6a3 commit 3b36e14

File tree

5 files changed

+24
-31
lines changed

5 files changed

+24
-31
lines changed

Justfile

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
build-adder:
2-
cd components/adder && cargo component build
2+
cd components/adder && cargo component build --release
33

44
init-subtractor:
5-
cd components/subtractor && npm install
5+
cd components/subtractor && npm install
66

77
build-subtractor:
8-
cd components/subtractor && npm run build:component
8+
cd components/subtractor && npm run build:component
99

1010
build-calculator:
11-
cd components/calculator && cargo component build
11+
cd components/calculator && cargo component build --release
1212

1313
build-component: build-adder build-subtractor build-calculator
14-
# Virtualize the calculator component
15-
wasm-tools print ./components/calculator/target/wasm32-wasip1/debug/calculator.wasm -o calculator.wat
16-
sed -i 's/@0.2.3/@0.2.1/g' calculator.wat
17-
wasm-tools parse calculator.wat -o calculator.hack.wasm
18-
wasi-virt --out calculator.virtualized.wasm calculator.hack.wasm
19-
# Virtualize the adder component
20-
wasm-tools print ./components/adder/target/wasm32-wasip1/debug/adder.wasm -o adder.wat
21-
sed -i 's/@0.2.3/@0.2.1/g' adder.wat
22-
wasm-tools parse adder.wat -o adder.hack.wasm
23-
wasi-virt --out adder.virtualized.wasm adder.hack.wasm
24-
# compose the components
25-
wac plug calculator.virtualized.wasm \
26-
--plug ./adder.virtualized.wasm \
14+
# compose the wasm components
15+
wac plug ./components/calculator/target/wasm32-wasip1/release/calculator.wasm \
16+
--plug ./components/adder/target/wasm32-wasip1/release/adder.wasm \
2717
--plug ./components/subtractor/subtractor.wasm \
2818
--output calculator-composed.wasm
19+
# ahead-of-time compile the composed component
20+
hyperlight-wasm-aot compile --component calculator-composed.wasm ./example/calculator-composed.bin
21+

components/calculator/src/bindings.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,30 +102,30 @@ pub mod exports {
102102
}
103103
#[doc(hidden)]
104104
#[allow(non_snake_case)]
105-
pub unsafe fn _export_eval_expression_cabi<T: Guest>(
105+
pub unsafe fn _export_evalexpression_cabi<T: Guest>(
106106
arg0: i32,
107107
arg1: i32,
108108
arg2: i32,
109109
) -> i32 {
110110
#[cfg(target_arch = "wasm32")] _rt::run_ctors_once();
111-
let result0 = T::eval_expression(
111+
let result0 = T::evalexpression(
112112
Op::_lift(arg0 as u8),
113113
arg1 as u32,
114114
arg2 as u32,
115115
);
116116
_rt::as_i32(result0)
117117
}
118118
pub trait Guest {
119-
fn eval_expression(op: Op, x: u32, y: u32) -> u32;
119+
fn evalexpression(op: Op, x: u32, y: u32) -> u32;
120120
}
121121
#[doc(hidden)]
122122
macro_rules! __export_hyperlight_wasm_examples_calculator_calculate_cabi {
123123
($ty:ident with_types_in $($path_to_types:tt)*) => {
124124
const _ : () = { #[unsafe (export_name =
125-
"hyperlight-wasm-examples:calculator/calculate#eval-expression")]
126-
unsafe extern "C" fn export_eval_expression(arg0 : i32, arg1 :
125+
"hyperlight-wasm-examples:calculator/calculate#evalexpression")]
126+
unsafe extern "C" fn export_evalexpression(arg0 : i32, arg1 :
127127
i32, arg2 : i32,) -> i32 { unsafe { $($path_to_types)*::
128-
_export_eval_expression_cabi::<$ty > (arg0, arg1, arg2) } } };
128+
_export_evalexpression_cabi::<$ty > (arg0, arg1, arg2) } } };
129129
};
130130
}
131131
#[doc(hidden)]
@@ -238,13 +238,13 @@ pub(crate) use __export_calculator_impl as export;
238238
)]
239239
#[doc(hidden)]
240240
#[allow(clippy::octal_escapes)]
241-
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 440] = *b"\
242-
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xb7\x02\x01A\x02\x01\
241+
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 439] = *b"\
242+
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xb6\x02\x01A\x02\x01\
243243
A\x06\x01B\x02\x01@\x02\x01xy\x01yy\0y\x04\0\x03add\x01\0\x03\0'hyperlight-wasm-\
244244
examples:calculator/add\x05\0\x01B\x02\x01@\x02\x01xy\x01yy\0y\x04\0\x08subtract\
245245
\x01\0\x03\0,hyperlight-wasm-examples:calculator/subtract\x05\x01\x01B\x04\x01m\x02\
246-
\x03add\x08subtract\x04\0\x02op\x03\0\0\x01@\x03\x02op\x01\x01xy\x01yy\0y\x04\0\x0f\
247-
eval-expression\x01\x02\x04\0-hyperlight-wasm-examples:calculator/calculate\x05\x02\
246+
\x03add\x08subtract\x04\0\x02op\x03\0\0\x01@\x03\x02op\x01\x01xy\x01yy\0y\x04\0\x0e\
247+
evalexpression\x01\x02\x04\0-hyperlight-wasm-examples:calculator/calculate\x05\x02\
248248
\x04\0.hyperlight-wasm-examples:calculator/calculator\x04\0\x0b\x10\x01\0\x0acal\
249249
culator\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.22\
250250
7.1\x10wit-bindgen-rust\x060.41.0";

components/calculator/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use bindings::hyperlight_wasm_examples::calculator::subtract::subtract;
88
struct Component;
99

1010
impl Guest for Component {
11-
fn eval_expression(op: Op, x: u32, y: u32) -> u32 {
11+
fn evalexpression(op: Op, x: u32, y: u32) -> u32 {
1212
match op {
1313
Op::Add => add(x,y),
1414
Op::Subtract => subtract(x, y),

components/subtractor/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"@bytecodealliance/jco": "^1.10.2"
55
},
66
"scripts": {
7-
"build:component": "jco componentize --wit ../../wit --world-name subtractor subtractor.js -d all -o subtractor.wasm"
7+
"build:component": "jco componentize --wit ../../wit/calculator.wit --world-name subtractor subtractor.js -d all -o subtractor.wasm"
88
}
9-
}
9+
}

wit/calculator.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface calculate {
2121
add,
2222
subtract,
2323
}
24-
eval-expression: func(op: op, x:u32, y:u32) -> u32;
24+
evalexpression: func(op: op, x:u32, y:u32) -> u32;
2525
}
2626

2727
world calculator {

0 commit comments

Comments
 (0)