Commit ecf042b6
ecf042b62131Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
fix: use static library for bigint (link only when needed)
Replace unconditional sp_bigint.o linking with libspbi.a static library. The linker only includes bigint code when the program actually uses it. Reduces hello-world binary from 51KB to 16KB.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- ecf042b62131
- Parent
- 1d90f0cc6ea8
MakefilemodifiedView file
@@ -83,14 +83,19 @@
8383
@mkdir -p build8484
$(CC) -c -O2 -Wno-all -Ilib lib/sp_bigint.c -o build/sp_bigint.o8585
86-
test: spinel_parse build/sp_bigint.o $(RE_LIB)86+
BI_LIB = lib/libspbi.a87+
88+
$(BI_LIB): build/sp_bigint.o89+
ar rcs $@ $^90+
91+
test: spinel_parse $(BI_LIB) $(RE_LIB)8792
@if [ ! -f spinel_codegen ]; then echo "Run 'make bootstrap' first"; exit 1; fi8893
@pass=0; fail=0; err=0; \8994
for f in test/*.rb; do \9095
bn=$$(basename "$$f" .rb); \9196
./spinel_parse "$$f" /tmp/_sp_t.ast 2>/dev/null && \9297
./spinel_codegen /tmp/_sp_t.ast /tmp/_sp_t.c 2>/dev/null && \93-
$(CC) $(CFLAGS) /tmp/_sp_t.c build/sp_bigint.o $(RE_LIB) -lm -o /tmp/_sp_t_bin 2>/dev/null; \98+
$(CC) $(CFLAGS) /tmp/_sp_t.c $(BI_LIB) $(RE_LIB) -lm -o /tmp/_sp_t_bin 2>/dev/null; \9499
if [ $$? -eq 0 ]; then \95100
expected=$$(timeout 10 ruby "$$f" 2>/dev/null); \96101
actual=$$(timeout 10 /tmp/_sp_t_bin 2>/dev/null); \@@ -106,14 +111,14 @@
106111
rm -f /tmp/_sp_t.ast /tmp/_sp_t.c /tmp/_sp_t_bin; \107112
echo "Tests: $$pass pass, $$fail fail, $$err error"108113
109-
bench: spinel_parse build/sp_bigint.o $(RE_LIB)114+
bench: spinel_parse $(BI_LIB) $(RE_LIB)110115
@if [ ! -f spinel_codegen ]; then echo "Run 'make bootstrap' first"; exit 1; fi111116
@pass=0; fail=0; skip=0; \112117
for f in benchmark/*.rb; do \113118
bn=$$(basename "$$f" .rb); \114119
timeout 10 ./spinel_parse "$$f" /tmp/_sp_b.ast 2>/dev/null && \115120
timeout 10 ./spinel_codegen /tmp/_sp_b.ast /tmp/_sp_b.c 2>/dev/null && \116-
$(CC) $(CFLAGS) /tmp/_sp_b.c build/sp_bigint.o $(RE_LIB) -lm -o /tmp/_sp_b_bin 2>/dev/null; \121+
$(CC) $(CFLAGS) /tmp/_sp_b.c $(BI_LIB) $(RE_LIB) -lm -o /tmp/_sp_b_bin 2>/dev/null; \117122
if [ $$? -eq 0 ]; then \118123
expected=$$(timeout 60 ruby "$$f" 2>/dev/null); \119124
ruby_rc=$$?; \