feat(runtime): embed platform modules as bytecode

ui.lua and hints.lua are compiled to LUA_32BITS bytecode (matching the
firmware's Lua build) and linked into the binary. A new package.searchers
entry checks them as the fallback after the SD card, so a local
/.lua/lib/ui.lua still shadows the packaged one for debugging.

Bytecode is ~40% smaller than source and loads without parsing. A fresh
SD card with no make sdcard now has the platform available.
This commit is contained in:
2026-08-03 21:08:35 -04:00
parent 60ec720cdb
commit 6a9b082f97
10 changed files with 430 additions and 263 deletions
+11 -2
View File
@@ -10,10 +10,14 @@ LUA_OBJECTS := $(patsubst native/src/vendor/lua/%.c,_build/lua/%.o,$(LUA_C))
LUA_LIBRARY := _build/liblua.a
LUA_SMOKE := _build/lua-smoke
RUNTIME_TEST := _build/runtime-test
LUAC32 := _build/luac32
RUNTIME_CPP := $(sort $(wildcard native/src/runtime/*.cpp native/src/bindings/core/*.cpp \
native/src/bindings/features/*.cpp))
native/src/bindings/features/*.cpp) native/src/embedded_modules.cpp)
.PHONY: api test
.PHONY: api test embed
embed: $(LUAC32)
@$(PYTHON) tools/embed.py $(LUAC32) lua/lib native/src/embedded_modules.cpp
api:
@$(PYTHON) tools/gen_api.py
@@ -21,6 +25,8 @@ api:
test: $(LUA_SMOKE) $(RUNTIME_TEST)
@$(PYTHON) tools/gen_api.py --check
@printf '%-32s ' generated-api; echo ok
@$(PYTHON) tools/embed.py $(LUAC32) lua/lib native/src/embedded_modules.cpp --check
@printf '%-32s ' embedded-modules; echo ok
@$(LUA) -e 'assert(_VERSION == "Lua 5.4", "tests require Lua 5.4")'
@for file in $(CONTRACTS); do $(LUA) -e "assert(loadfile('$$file'))" || exit 1; done
@printf '%-32s ' contracts; echo ok
@@ -39,6 +45,9 @@ $(RUNTIME_TEST): $(RUNTIME_CPP) native/test/runtime_test.cpp $(LUA_LIBRARY)
$(LUA_LIBRARY): $(LUA_OBJECTS)
@$(AR) rcs $@ $^
$(LUAC32): tools/dump.c $(LUA_LIBRARY)
@$(CC) -std=c99 -DLUA_32BITS -I native/src/vendor/lua $< $(LUA_LIBRARY) -lm -o $@
_build/lua/%.o: native/src/vendor/lua/%.c
@mkdir -p $(@D)
@$(CC) -std=c99 -DLUA_32BITS -I native/src/vendor/lua -c $< -o $@