Skip to content

Commit 021bf6d

Browse files
committed
Add Support to other scripts
Signed-off-by: James Sturtevant <[email protected]>
1 parent 086d43b commit 021bf6d

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/hyperlight_wasm/scripts/build-wasm-examples.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ OUTPUT_DIR=$(realpath $OUTPUT_DIR)
1212

1313
if [ -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+
2649
else
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.

src/wasmsamples/compile-wasm.bat

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ for /R "%1" %%i in (*.c) do (
3131
copy %2\%%~ni.aot %2\%%~ni.wasm
3232
)
3333

34+
echo Building components
35+
for %%j in (%~1\components\*.wit) do (
36+
set "COMPONENT_NAME=%%~nj"
37+
echo Building component: !COMPONENT_NAME!
38+
39+
rem Generate bindings for the component
40+
wit-bindgen c %%j --out-dir %~1\components\bindings
41+
42+
rem Build the wasm file with wasi-libc for wasmtime
43+
%dockercmd% run --rm -i -v !dockerinput!:/tmp/host1 -v !dockeroutput!:/tmp/host2 wasm-clang-builder /opt/wasi-sdk/bin/wasm32-wasip2-clang -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/host2/!COMPONENT_NAME!-p2.wasm /tmp/host1/components/!COMPONENT_NAME!.c /tmp/host1/components/bindings/!COMPONENT_NAME!.c /tmp/host1/components/bindings/!COMPONENT_NAME!_component_type.o
44+
45+
rem Build AOT for Wasmtime
46+
cargo run -p hyperlight-wasm-aot compile --component %2\!COMPONENT_NAME!-p2.wasm %2\!COMPONENT_NAME!.aot
47+
copy %2\!COMPONENT_NAME!.aot %2\!COMPONENT_NAME!.wasm
48+
)
49+
3450
goto :EOF
3551
:Error
3652
echo Usage - compile-wasm ^<source directory^> ^<output directory^>

0 commit comments

Comments
 (0)