@@ -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.
3356
3457 docker build --build-arg GCC_VERSION=12 --build-arg WASI_SDK_VERSION_FULL=25.0 --cache-from ghcr.io/hyperlight-dev/wasm-clang-builder:latest -t wasm-clang-builder:latest . 2> ${OUTPUT_DIR} /dockerbuild.log
3558
36- for FILENAME in $( find . -name ' *.c' )
59+ for FILENAME in $( find . -name ' *.c' -not -path ' ./components/* ' )
3760 do
3861 echo Building ${FILENAME}
3962 # Build the wasm file with wasi-libc for wasmtime
40- 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}
63+ 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}
4164
4265 # Build AOT for Wasmtime; note that Wasmtime does not support
4366 # interpreting, so its wasm binary is secretly an AOT binary.
4467 cargo run -p hyperlight-wasm-aot compile ${OUTPUT_DIR} /${FILENAME% .* } -wasi-libc.wasm ${OUTPUT_DIR} /${FILENAME% .* } .aot
4568 cp ${OUTPUT_DIR} /${FILENAME% .* } .aot ${OUTPUT_DIR} /${FILENAME% .* } .wasm
4669 done
70+
71+ echo Building components
72+ # Iterate over all .wit files in the components folder
73+ for WIT_FILE in ${PWD} /components/* .wit; do
74+ COMPONENT_NAME=$( basename ${WIT_FILE} .wit)
75+ echo Building component: ${COMPONENT_NAME}
76+
77+ # Generate bindings for the component
78+ wit-bindgen c ${WIT_FILE} --out-dir ${PWD} /components/bindings
79+
80+ # Build the wasm file with wasi-libc for wasmtime
81+ docker run --rm -i -v " ${PWD} :/tmp/host" -v " ${OUTPUT_DIR} :/tmp/output/" wasm-clang-builder:latest /opt/wasi-sdk/bin/wasm32-wasip2-clang \
82+ -ffunction-sections -mexec-model=reactor -O3 -z stack-size=4096 \
83+ -Wl,--initial-memory=65536 -Wl,--export=__data_end -Wl,--export=__heap_base,--export=malloc,--export=free,--export=__wasm_call_ctors \
84+ -Wl,--strip-all,--no-entry -Wl,--allow-undefined -Wl,--gc-sections \
85+ -o /tmp/output/${COMPONENT_NAME} -p2.wasm \
86+ /tmp/host/components/${COMPONENT_NAME} .c \
87+ /tmp/host/components/bindings/${COMPONENT_NAME} .c \
88+ /tmp/host/components/bindings/${COMPONENT_NAME} _component_type.o
89+
90+ # Build AOT for Wasmtime
91+ cargo run -p hyperlight-wasm-aot compile --component ${OUTPUT_DIR} /${COMPONENT_NAME} -p2.wasm ${OUTPUT_DIR} /${COMPONENT_NAME} .aot
92+ cp ${OUTPUT_DIR} /${COMPONENT_NAME} .aot ${OUTPUT_DIR} /${COMPONENT_NAME} .wasm
93+ done
4794fi
4895
4996popd
0 commit comments