add a c-only target (no WASM)

This commit is contained in:
2026-03-13 00:22:03 +01:00
parent 0f847d7d2d
commit 129ba0e0b6
5 changed files with 206 additions and 51 deletions

152
wasm.just
View File

@ -16,6 +16,35 @@ WASI_CFLAGS := "\
-Wl,--export=__heap_base \
-Wl,--export=__data_end \
"
CROSS_CFLAGS_NOWASM := "\
-m32 \
-ffunction-sections \
-fdata-sections \
-ffreestanding \
-fomit-frame-pointer \
-ggdb \
"
CROSS_LDFLAGS_NOWASM := f"\
-Wl,--build-id=none \
-static \
-nostdlib \
-m32 \
-lc \
-lgcc \
-lm \
"
LINUX_CFLAGS_NOWASM := "\
-O0 \
-m32 \
-ffunction-sections \
-fdata-sections \
-ggdb \
"
LINUX_LDFLAGS_NOWASM := f"\
-Wl,--build-id=none \
-m32 \
-lm \
"
WAMRC := "wamrc"
WAMRCFLAGS := "\
--target=i386 \
@ -44,32 +73,38 @@ build-wasm-aot-array module:
build-wasm-interp-array module:
{{ XXD }} -i {{ BUILD_DIR }}-{{ module }}/wasm_module.wasm > {{ BUILD_DIR }}-{{ module }}/wasm_interp_array.c
[private]
build-c-module-fail module:
{{ CROSS_CC }} {{ CROSS_CFLAGS_NOWASM }} \
-c targets/wasm-module/{{ module }}.c \
-o {{ BUILD_DIR }}-{{ module }}/c_module.o
[private]
build-c-module-linux module:
{{ LINUX_CC }} {{ LINUX_CFLAGS_NOWASM }} \
-c targets/wasm-module/{{ module }}.c \
-o {{ BUILD_DIR }}-{{ module }}/c_module.o
[doc("C -> Object: Compile a C function (no WASM)")]
[group("1: build module")]
build-c-module module target="fail":
#!/usr/bin/env sh
if [ "{{ target }}" = "fail" ]; then
just build-c-module-fail "{{ module }}"
elif [ "{{ target }}" = "linux" ]; then
just build-c-module-linux "{{ module }}"
else
echo "unknown target: {{ target }}" >&2
exit 1
fi
# =================================================================================================================== #
# Host program recipes
# =================================================================================================================== #
# FAIL*
CROSS_CFLAGS := "\
-I./targets/wasm-host \
-O2 \
-m32 \
-ffunction-sections \
-fdata-sections \
-ffreestanding \
-fomit-frame-pointer \
-ggdb \
"
CROSS_LDFLAGS := f"\
-Wl,--build-id=none \
-static \
-nostdlib \
-m32 \
-L{{LIBIWASM_RELEASE}} \
-liwasm \
-lc \
-lgcc \
-lm \
"
CROSS_CFLAGS := f"-I./targets/wasm-host {{CROSS_CFLAGS_NOWASM}} -O2"
CROSS_LDFLAGS := f"{{CROSS_LDFLAGS_NOWASM}} -L{{LIBIWASM_RELEASE}} -liwasm"
CROSS_INCLUDES := f"\
-I{{WAMR_ROOT}}/core/iwasm/include \
-I{{WAMR_ROOT}}/core/shared/utils \
@ -78,22 +113,8 @@ CROSS_INCLUDES := f"\
# LINUX-POSIX
LINUX_CFLAGS := "\
-I./targets/wasm-host \
-O0 \
-m32 \
-ffunction-sections \
-fdata-sections \
-ggdb \
"
LINUX_LDFLAGS := f"\
-Wl,--build-id=none \
-m32 \
-Wl,-rpath,{{LIBIWASM_LINUX_DEBUG}} \
-L{{LIBIWASM_LINUX_DEBUG}} \
-liwasm \
-lm \
"
LINUX_CFLAGS := f"-I./targets/wasm-host {{ LINUX_CFLAGS_NOWASM }}"
LINUX_LDFLAGS := f"{{LINUX_LDFLAGS_NOWASM}} -Wl,-rpath,{{LIBIWASM_LINUX_DEBUG}} -L{{LIBIWASM_LINUX_DEBUG}} -liwasm"
LINUX_INCLUDES := f"\
-I{{WAMR_ROOT}}/core/iwasm/include \
-I{{WAMR_ROOT}}/core/shared/utils \
@ -182,6 +203,32 @@ build-wasm-host module target="fail":
exit 1
fi
[private]
build-c-host-fail module:
{{ CROSS_CC }} {{ CROSS_CFLAGS_NOWASM }} \
-c targets/c-host/fail.c \
-o {{ BUILD_DIR }}-{{ module }}/c_host.o
[private]
build-c-host-linux module:
{{ LINUX_CC }} {{ LINUX_CFLAGS_NOWASM }} \
-c targets/c-host/linux.c \
-o {{ BUILD_DIR }}-{{ module }}/c_host.o
[doc("Insert the C function into the host program (no WASM)")]
[group("2: build host")]
build-c-host module target="fail":
#!/usr/bin/env sh
if [ "{{ target }}" = "fail" ]; then
just build-c-host-fail "{{ module }}"
elif [ "{{ target }}" = "linux" ]; then
just build-c-host-linux "{{ module }}"
else
echo "unknown target: {{ target }}" >&2
exit 1
fi
[private]
build-system-startup-fail module:
{{ CROSS_CC }} targets/startup.s {{ CROSS_CFLAGS }} -c -o {{ BUILD_DIR }}-{{ module }}/startup.o
@ -256,6 +303,37 @@ link-system module target="fail":
exit 1
fi
[private]
link-c-system-fail module:
{{ CROSS_CC }} \
-Wl,-T targets/linker.ld \
{{ BUILD_DIR }}-{{ module }}/c_host.o \
{{ BUILD_DIR }}-{{ module }}/startup.o \
{{ BUILD_DIR }}-{{ module }}/c_module.o \
{{ CROSS_LDFLAGS_NOWASM }} \
-o {{ BUILD_DIR }}-{{ module }}/system.elf
[private]
link-c-system-linux module:
{{ LINUX_CC }} \
{{ BUILD_DIR }}-{{ module }}/c_host.o \
{{ BUILD_DIR }}-{{ module }}/c_module.o \
{{ LINUX_LDFLAGS_NOWASM }} \
-o {{ BUILD_DIR }}-{{ module }}/system.elf
[doc("Link C-Host, C-function and bootloader")]
[group("2: build host")]
link-c-system module target="fail":
#!/usr/bin/env sh
if [ "{{ target }}" = "fail" ]; then
just link-c-system-fail "{{ module }}"
elif [ "{{ target }}" = "linux" ]; then
just link-c-system-linux "{{ module }}"
else
echo "unknown target: {{ target }}" >&2
exit 1
fi
[doc("Create bootdisk")]
[group("2: build host")]
build-iso module: