Files
esp32-lua-api/Makefile
T
evan 6a9b082f97 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.
2026-08-03 21:08:35 -04:00

54 lines
2.0 KiB
Makefile

LUA ?= lua
PYTHON ?= python3
CC ?= cc
CXX ?= c++
AR ?= ar
CONTRACTS := $(sort $(wildcard lua/api/core/*.lua lua/api/features/*.lua))
LUA_C := $(sort $(wildcard native/src/vendor/lua/*.c))
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/embedded_modules.cpp)
.PHONY: api test embed
embed: $(LUAC32)
@$(PYTHON) tools/embed.py $(LUAC32) lua/lib native/src/embedded_modules.cpp
api:
@$(PYTHON) tools/gen_api.py
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
@printf '%-32s ' lua/test/ui.lua; $(LUA) lua/test/ui.lua
@printf '%-32s ' lua/test/hints.lua; $(LUA) lua/test/hints.lua
@printf '%-32s ' native/test/lua_smoke.c; $(LUA_SMOKE) && echo ok
@printf '%-32s ' native/test/runtime_test.cpp; $(RUNTIME_TEST) && echo ok
$(LUA_SMOKE): native/test/lua_smoke.c $(LUA_LIBRARY)
@$(CC) -std=c99 -DLUA_32BITS -I native/src/vendor/lua $< $(LUA_LIBRARY) -lm -ldl -o $@
$(RUNTIME_TEST): $(RUNTIME_CPP) native/test/runtime_test.cpp $(LUA_LIBRARY)
@$(CXX) -std=c++11 -Wall -Wextra -DLUA_32BITS -I native/include -I native/src/vendor/lua \
$(RUNTIME_CPP) native/test/runtime_test.cpp $(LUA_LIBRARY) -lm -ldl -o $@
$(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 $@