diff --git a/scripts/nixos.just b/scripts/nixos.just index 1c40b73..8ea88bf 100644 --- a/scripts/nixos.just +++ b/scripts/nixos.just @@ -170,7 +170,7 @@ build module="__help" target="fail" mode="aot": if [ "{{ mode }}" = "aot" ]; then just build-wasm-module {{ module }} - just build-wasm-aot {{ module }} + just build-wasm-aot {{ module }} {{ target }} just build-wasm-aot-array {{ module }} just prepare-aot-host {{ module }} diff --git a/scripts/wasm.just b/scripts/wasm.just index 84daffe..038d0d5 100644 --- a/scripts/wasm.just +++ b/scripts/wasm.just @@ -49,13 +49,18 @@ LINUX_LDFLAGS_NOWASM := "\ -lm \ " WAMRC := "wamrc" -WAMRCFLAGS := "\ +CROSS_WAMRCFLAGS := "\ --target=i386 \ --cpu=generic \ --opt-level=0 \ --enable-indirect-mode \ --disable-llvm-intrinsics \ " +LINUX_WAMRCFLAGS := "\ +--target=i386 \ +--cpu=generic \ +--opt-level=0 \ +" XXD := "xxd" [doc("C -> WASM: Compile a C function to a WASM module using WASI-SDK")] @@ -63,10 +68,29 @@ XXD := "xxd" build-wasm-module module: {{ WASI_CC }} {{ WASI_CFLAGS }} targets/wasm-module/{{ module }}.cpp -o {{ BUILD_DIR }}-{{ module }}/wasm_module.wasm +[private] +build-wasm-aot-linux module: + {{ WAMRC }} {{ LINUX_WAMRCFLAGS }} -o {{ BUILD_DIR }}-{{ module }}/wasm_module.aot {{ BUILD_DIR }}-{{ module }}/wasm_module.wasm + +[private] +build-wasm-aot-cross module: + {{ WAMRC }} {{ CROSS_WAMRCFLAGS }} -o {{ BUILD_DIR }}-{{ module }}/wasm_module.aot {{ BUILD_DIR }}-{{ module }}/wasm_module.wasm + + [doc("WASM -> AOT: Compile a WASM module ahead-of-time using WAMR")] [group("1: build module")] -build-wasm-aot module: - {{ WAMRC }} {{ WAMRCFLAGS }} -o {{ BUILD_DIR }}-{{ module }}/wasm_module.aot {{ BUILD_DIR }}-{{ module }}/wasm_module.wasm +build-wasm-aot module target="fail": + #!/usr/bin/env sh + if [ "{{ target }}" = "fail" ]; then + just build-wasm-aot-cross "{{ module }}" + elif [ "{{ target }}" = "linux" ]; then + just build-wasm-aot-linux "{{ module }}" + elif [ "{{ target }}" = "linux-baremetal" ]; then + just build-wasm-aot-cross "{{ module }}" + else + echo "unknown target: {{ target }}" >&2 + exit 1 + fi [doc("AOT -> C-Array: Dump a WASM module compiled ahead-of-time to a binary array")] [group("1: build module")]