@@ -12,7 +12,7 @@ OUTPUT_DIR=$(realpath $OUTPUT_DIR)
1212
1313if [ -f " /.dockerenv" ] || grep -q docker /proc/1/cgroup; then
1414 # running in a container so use the installed wasi-sdk as the devcontainer has this installed
15- for FILENAME in $( find . -name ' *.c' )
15+ for FILENAME in $( find . -name ' *.c' -not -path ' ./components/* ' )
1616 do
1717 echo Building ${FILENAME}
1818 # Build the wasm file with wasi-libc for wasmtime
@@ -23,6 +23,29 @@ if [ -f "/.dockerenv" ] || grep -q docker /proc/1/cgroup; then
2323 cargo run -p hyperlight-wasm-aot compile ${OUTPUT_DIR} /${FILENAME% .* } -wasi-libc.wasm ${OUTPUT_DIR} /${FILENAME% .* } .aot
2424 cp ${OUTPUT_DIR} /${FILENAME% .* } .aot ${OUTPUT_DIR} /${FILENAME% .* } .wasm
2525 done
26+
27+ for WIT_FILE in ${PWD} /components/* .wit; do
28+ COMPONENT_NAME=$( basename ${WIT_FILE} .wit)
29+ echo Building component: ${COMPONENT_NAME}
30+
31+ # Generate bindings for the component
32+ wit-bindgen c ${WIT_FILE} --out-dir ${PWD} /components/bindings
33+
34+ # Build the wasm file with wasi-libc for wasmtime
35+ /opt/wasi-sdk/bin/wasm32-wasip2-clang \
36+ -ffunction-sections -mexec-model=reactor -O3 -z stack-size=4096 \
37+ -Wl,--initial-memory=65536 -Wl,--export=__data_end -Wl,--export=__heap_base,--export=malloc,--export=free,--export=__wasm_call_ctors \
38+ -Wl,--strip-all,--no-entry -Wl,--allow-undefined -Wl,--gc-sections \
39+ -o ${OUTPUT_DIR} /${COMPONENT_NAME} -p2.wasm \
40+ ${PWD} /components/${COMPONENT_NAME} .c \
41+ ${PWD} /components/bindings/${COMPONENT_NAME} .c \
42+ ${PWD} /components/bindings/${COMPONENT_NAME} _component_type.o
43+
44+ # Build AOT for Wasmtime
45+ cargo run -p hyperlight-wasm-aot compile --component ${OUTPUT_DIR} /${COMPONENT_NAME} -p2.wasm ${OUTPUT_DIR} /${COMPONENT_NAME} .aot
46+ cp ${OUTPUT_DIR} /${COMPONENT_NAME} .aot ${OUTPUT_DIR} /${COMPONENT_NAME} .wasm
47+ done
48+
2649else
2750 # not running in a container so use the docker image to build the wasm files
2851 echo Building docker image that has Wasm sdk. Should be quick if preivoulsy built and no changes to dockerfile.
0 commit comments