@@ -12,7 +12,7 @@ OUTPUT_DIR=$(realpath $OUTPUT_DIR)
12
12
13
13
if [ -f " /.dockerenv" ] || grep -q docker /proc/1/cgroup; then
14
14
# 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/* ' )
16
16
do
17
17
echo Building ${FILENAME}
18
18
# Build the wasm file with wasi-libc for wasmtime
@@ -23,6 +23,29 @@ if [ -f "/.dockerenv" ] || grep -q docker /proc/1/cgroup; then
23
23
cargo run -p hyperlight-wasm-aot compile ${OUTPUT_DIR} /${FILENAME% .* } -wasi-libc.wasm ${OUTPUT_DIR} /${FILENAME% .* } .aot
24
24
cp ${OUTPUT_DIR} /${FILENAME% .* } .aot ${OUTPUT_DIR} /${FILENAME% .* } .wasm
25
25
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
+
26
49
else
27
50
# not running in a container so use the docker image to build the wasm files
28
51
echo Building docker image that has Wasm sdk. Should be quick if preivoulsy built and no changes to dockerfile.
33
56
34
57
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
35
58
36
- for FILENAME in $( find . -name ' *.c' )
59
+ for FILENAME in $( find . -name ' *.c' -not -path ' ./components/* ' )
37
60
do
38
61
echo Building ${FILENAME}
39
62
# 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}
41
64
42
65
# Build AOT for Wasmtime; note that Wasmtime does not support
43
66
# interpreting, so its wasm binary is secretly an AOT binary.
44
67
cargo run -p hyperlight-wasm-aot compile ${OUTPUT_DIR} /${FILENAME% .* } -wasi-libc.wasm ${OUTPUT_DIR} /${FILENAME% .* } .aot
45
68
cp ${OUTPUT_DIR} /${FILENAME% .* } .aot ${OUTPUT_DIR} /${FILENAME% .* } .wasm
46
69
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
47
94
fi
48
95
49
96
popd
0 commit comments