aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2026-10-17 10:52:27 +0200
committerNicholas Rodrigues Lordello <[email protected]>2026-10-17 10:52:27 +0200
commitd3c95fce3f5c8b910d3dc04ed5d8c1673944baf0 (patch)
tree61b36f4cf2c0c77a3ee3bc05a83384b695e58fb5 /Makefile
parentf97bb735065392d639462e90d9abd1bb5f738c61 (diff)
Use `wasm2c` instead of WAMR
Instead of interpreting Wasm, compile it ahead of time to C and run that instead: - it is much faster (no interpreter overhead) - it is easier to implement host functions, they are just C calls This works well for us since we only ever load a single Wasm blob (the PICO-8 runtime that `picow` is built with). There was some fun figuring out how big-endian stuff works (WRT memory layout), but otherwise it was pretty straight forward. Note that traps are still not working, I need to figure that out still...
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile67
1 files changed, 24 insertions, 43 deletions
diff --git a/Makefile b/Makefile
index 93d1b04..426fc9d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,70 +1,51 @@
-include config.mk
-CC ?= cc
-AR ?= ar
-HOSTCC ?= cc
-PICO8 ?= pico8
+CC ?= cc
+AR ?= ar
+HOSTCC ?= cc
+PICO8 ?= pico8
+WASM2C ?= wasm2c
+
WAT2WASM ?= wat2wasm
-ARCH ?= $(shell uname -m)
-CFLAGS += -std=c99 -Wall -Wextra -O2 -MMD
-SDL3_CFLAGS ?= $(shell pkg-config sdl3 --cflags)
-SDL3_LIBS ?= $(shell pkg-config sdl3 --libs)
+ARCH ?= $(shell uname -m)
+CFLAGS ?= -std=c99 -Wall -Wextra -O2 -MMD -Isrc -Ilib -I$(SYSTEM) \
+ $(shell pkg-config sdl3 --cflags)
+LDFLAGS ?= $(shell pkg-config sdl3 --libs) -lm
+W2CFLAGS ?= --disable-tail-call
TARGET := build/$(ARCH)
OUT := $(TARGET)/out
TOOLS := build/tools
SYSTEM := build/system
-PICOW_CFLAGS := $(CFLAGS) $(SDL3_CFLAGS) -Ilib/
-PICOW_LDFLAGS := $(LDFLAGS) $(SDL3_LIBS) -L$(TARGET) -lwamr -lm
-PICOW_SRC := $(wildcard src/*.c) $(SYSTEM)/sysroot.c
-PICOW_OBJ := $(patsubst %.c,$(OUT)/%.o,$(PICOW_SRC:build/%=%))
-
-WAMR_CFLAGS := $(CFLAGS) -Wno-unused-parameter \
- -DBH_FREE=wasm_runtime_free \
- -DBH_MALLOC=wasm_runtime_malloc \
- -DWASM_ENABLE_FAST_INTERP=1 \
- -DWASM_ENABLE_INTERP=1 \
- -Ilib/wamr/core/iwasm/common \
- -Ilib/wamr/core/iwasm/include \
- -Ilib/wamr/core/iwasm/interpreter \
- -Ilib/wamr/core/shared/mem-alloc \
- -Ilib/wamr/core/shared/platform/include \
- -Ilib/wamr/core/shared/utils \
- -Ilib/wamr/custom
-WAMR_SRC := $(shell find lib/wamr -name '*.c')
-WAMR_OBJ := $(patsubst %.c,$(OUT)/%.o,$(WAMR_SRC))
+SRC := $(wildcard src/*.c) $(SYSTEM)/pico8.c $(SYSTEM)/sysroot.c
+OBJ := $(patsubst %.c,$(OUT)/%.o,$(SRC:build/%=%))
.PHONY: all
all: $(TARGET)/picow ;
-$(TARGET)/picow: $(PICOW_OBJ) $(TARGET)/libwamr.a
+$(TARGET)/picow: $(OBJ)
@ echo "CC\t$@"
- @ $(CC) $(PICOW_OBJ) -o $@ $(PICOW_LDFLAGS)
+ @ $(CC) $(OBJ) -o $@ $(LDFLAGS)
-$(OUT)/src/%.o: src/%.c $(SYSTEM)/sysroot.h
+$(OUT)/src/%.o: src/%.c $(SYSTEM)/pico8.h $(SYSTEM)/sysroot.h
@ echo "CC\t$@"
@ mkdir -p $(dir $@)
- @ $(CC) $(PICOW_CFLAGS) -I$(SYSTEM) -c $< -o $@
+ @ $(CC) $(CFLAGS) -c $< -o $@
$(OUT)/system/%.o: $(SYSTEM)/%.c
@ echo "CC\t$@"
@ mkdir -p $(dir $@)
- @ $(CC) $(PICOW_CFLAGS) -Isrc/ -c $< -o $@
-
-$(TARGET)/libwamr.a: $(WAMR_OBJ)
- @ echo "AR\t$@"
- @ $(AR) rcs $@ $^
+ @ $(CC) $(CFLAGS) -Wno-unused -Wno-unused-parameter -c $< -o $@
-$(OUT)/lib/wamr/%.o: lib/wamr/%.c
- @ echo "CC\t$@"
- @ mkdir -p $(dir $@)
- @ $(CC) $(WAMR_CFLAGS) -c $< -o $@
+$(SYSTEM)/pico8.h $(SYSTEM)/pico8.c: $(SYSTEM)/stub/pico8.wasm \
+ $(SYSTEM)/pico8.wasm
+ @ echo "WASM2C\t$(SYSTEM)/pico8.h $(SYSTEM)/pico8.c"
+ @ $(WASM2C) $(W2CFLAGS) $< -o $(SYSTEM)/pico8.c
+ @ echo '#include "wasmrt.h"' > $(SYSTEM)/wasm-rt.h
$(SYSTEM)/sysroot.h $(SYSTEM)/sysroot.c: $(TOOLS)/generate-sysroot \
$(SYSTEM)/pico8.data.pod \
- $(SYSTEM)/pico8.wasm \
- $(SYSTEM)/stub/pico8.wasm \
$(SYSTEM)/unknown.p8.png \
$(SYSTEM)/font.png
@ echo "TOOL\t$(SYSTEM)/sysroot.h $(SYSTEM)/sysroot.c"
@@ -113,4 +94,4 @@ build/compile_commands.json: $(TOOLS)/ccj
clean:
rm -rf build/
--include $(PICOW_OBJ:.o=.d) $(WAMR_OBJ:.o=.d)
+-include $(OBJ:.o=.d)