@@ -832,8 +832,14 @@ BUILD_DIR = build/c
832832# ── Object file compilation (grammars need relaxed warnings) ─────
833833
834834# Grammar + tree-sitter runtime: compiled without -Werror (upstream code has warnings)
835+ # $(TEST_SEAM_DEFINE): these prod objects (grammars, ts_runtime, lsp_all) are
836+ # linked into the same binary as the CFLAGS_PROD sources, so both halves must
837+ # agree on the seam switch. lsp_all holds seam code of its own (ts_lsp.c's
838+ # budget probes, any seam counter a resolver defines): without the define a
839+ # TEST_SEAMS=1 binary silently lacks those seams, and a seam symbol that cbm.c
840+ # references fails to link. GRAMMAR_CFLAGS_TEST always carries the define.
835841GRAMMAR_CFLAGS = -std=c11 -D_DEFAULT_SOURCE -O2 -w -I$(CBM_DIR) -I$(TS_INCLUDE) -I$(TS_SRC) \
836- $(MEMWASTE_VENDOR_CFLAGS)
842+ $(TEST_SEAM_DEFINE) $( MEMWASTE_VENDOR_CFLAGS)
837843GRAMMAR_CFLAGS_TEST = -std=c11 -D_DEFAULT_SOURCE -g -O1 -w -I$(CBM_DIR) -I$(TS_INCLUDE) -I$(TS_SRC) \
838844 -DCBM_ENABLE_TEST_SEAMS=1 $(SANITIZED_DEFINE) $(SANITIZE)
839845GRAMMAR_CFLAGS_TSAN = -std=c11 -D_DEFAULT_SOURCE -g -O1 -w -I$(CBM_DIR) -I$(TS_INCLUDE) -I$(TS_SRC) \
@@ -941,7 +947,9 @@ $(BUILD_DIR)/sqlite3.o: $(SQLITE3_SRC) | $(BUILD_DIR)
941947$(BUILD_DIR)/tsan_sqlite3.o: $(SQLITE3_SRC) | $(BUILD_DIR)
942948 $(CC) $(SQLITE3_CFLAGS_TEST) $(TSAN_SANITIZE) -c -o $@ $<
943949
944- $(BUILD_DIR)/prod_sqlite3.o: $(SQLITE3_SRC) Makefile.cbm | $(BUILD_DIR)
950+ # .build-config: SQLITE3_CFLAGS carries MEMWASTE_VENDOR_CFLAGS (see the stamp
951+ # under "Production binary").
952+ $(BUILD_DIR)/prod_sqlite3.o: $(SQLITE3_SRC) Makefile.cbm $(BUILD_DIR)/.build-config | $(BUILD_DIR)
945953 $(CC) $(SQLITE3_CFLAGS) -c -o $@ $<
946954
947955# TRE regex (only compiled on Windows — POSIX uses system <regex.h>)
@@ -971,7 +979,7 @@ $(BUILD_DIR)/tre.o: $(TRE_SRC) | $(BUILD_DIR)
971979$(BUILD_DIR)/tsan_tre.o: $(TRE_SRC) | $(BUILD_DIR)
972980 $(CC) $(TRE_CFLAGS) $(TSAN_SANITIZE) -c -o $@ $<
973981
974- $(BUILD_DIR)/prod_tre.o: $(TRE_SRC) | $(BUILD_DIR)
982+ $(BUILD_DIR)/prod_tre.o: $(TRE_SRC) $(BUILD_DIR)/.build-config | $(BUILD_DIR)
975983 $(CC) $(TRE_CFLAGS) -O2 $(MEMWASTE_VENDOR_CFLAGS) -c -o $@ $<
976984endif
977985
@@ -1125,28 +1133,35 @@ TS_RUNTIME_OBJ_PROD = $(BUILD_DIR)/prod_ts_runtime.o
11251133LSP_OBJ_PROD = $(BUILD_DIR)/prod_lsp_all.o
11261134PP_OBJ_PROD = $(BUILD_DIR)/prod_preprocessor.o
11271135
1128- $(BUILD_DIR)/prod_%.o: $(CBM_DIR)/%.c $(GRAMMAR_UNITY_DEPS) | $(BUILD_DIR)
1136+ # Every prod object whose flags carry a BUILD_CONFIG_SIG variable
1137+ # (TEST_SEAM_DEFINE via GRAMMAR_CFLAGS, MEMWASTE_VENDOR_CFLAGS) depends on the
1138+ # $(BUILD_DIR)/.build-config stamp. These objects are compiled once and linked
1139+ # into every later binary, so without the stamp a TEST_SEAMS or MEMWASTE flip
1140+ # relinks the PREVIOUS flavour: a release binary keeps seam code compiled into
1141+ # lsp_all, or a seams binary misses it. prod_mimalloc.o and the unixcoder blob
1142+ # take no config variable and stay off the stamp.
1143+ $(BUILD_DIR)/prod_%.o: $(CBM_DIR)/%.c $(GRAMMAR_UNITY_DEPS) $(BUILD_DIR)/.build-config | $(BUILD_DIR)
11291144 $(CC) $(GRAMMAR_CFLAGS) -c -o $@ $<
11301145
1131- $(BUILD_DIR)/prod_ts_runtime.o: $(TS_RUNTIME_DEPS) | $(BUILD_DIR)
1146+ $(BUILD_DIR)/prod_ts_runtime.o: $(TS_RUNTIME_DEPS) $(BUILD_DIR)/.build-config | $(BUILD_DIR)
11321147 $(CC) $(GRAMMAR_CFLAGS) -c -o $@ $<
11331148
1134- $(BUILD_DIR)/prod_lsp_all.o: $(LSP_UNITY_DEPS) | $(BUILD_DIR)
1149+ $(BUILD_DIR)/prod_lsp_all.o: $(LSP_UNITY_DEPS) $(BUILD_DIR)/.build-config | $(BUILD_DIR)
11351150 $(CC) $(GRAMMAR_CFLAGS) -c -o $@ $<
11361151
1137- $(BUILD_DIR)/prod_preprocessor.o: $(CBM_DIR)/preprocessor.cpp | $(BUILD_DIR)
1152+ $(BUILD_DIR)/prod_preprocessor.o: $(CBM_DIR)/preprocessor.cpp $(BUILD_DIR)/.build-config | $(BUILD_DIR)
11381153 $(CXX) $(CXXFLAGS_PROD) -w -I$(CBM_DIR)/vendored -c -o $@ $<
11391154
11401155# Vendored LZ4 (compiled separately, not unity-built via lz4_store.c)
11411156LZ4_OBJ_PROD = $(BUILD_DIR)/prod_lz4.o $(BUILD_DIR)/prod_lz4hc.o
1142- $(BUILD_DIR)/prod_lz4.o: $(CBM_DIR)/vendored/lz4/lz4.c | $(BUILD_DIR)
1157+ $(BUILD_DIR)/prod_lz4.o: $(CBM_DIR)/vendored/lz4/lz4.c $(BUILD_DIR)/.build-config | $(BUILD_DIR)
11431158 $(CC) -std=c11 -D_DEFAULT_SOURCE -O2 -w $(MEMWASTE_VENDOR_CFLAGS) -I$(CBM_DIR) -c -o $@ $<
1144- $(BUILD_DIR)/prod_lz4hc.o: $(CBM_DIR)/vendored/lz4/lz4hc.c | $(BUILD_DIR)
1159+ $(BUILD_DIR)/prod_lz4hc.o: $(CBM_DIR)/vendored/lz4/lz4hc.c $(BUILD_DIR)/.build-config | $(BUILD_DIR)
11451160 $(CC) -std=c11 -D_DEFAULT_SOURCE -O2 -w $(MEMWASTE_VENDOR_CFLAGS) -I$(CBM_DIR)/vendored/lz4 -c -o $@ $<
11461161
11471162# Vendored zstd (compiled separately, not unity-built via zstd_store.c)
11481163ZSTD_OBJ_PROD = $(BUILD_DIR)/prod_zstd.o
1149- $(BUILD_DIR)/prod_zstd.o: $(CBM_DIR)/vendored/zstd/zstd.c | $(BUILD_DIR)
1164+ $(BUILD_DIR)/prod_zstd.o: $(CBM_DIR)/vendored/zstd/zstd.c $(BUILD_DIR)/.build-config | $(BUILD_DIR)
11501165 $(CC) -std=c11 -D_DEFAULT_SOURCE -O2 -w $(MEMWASTE_VENDOR_CFLAGS) -I$(CBM_DIR)/vendored/zstd -c -o $@ $<
11511166
11521167OBJS_VENDORED_PROD = $(MIMALLOC_OBJ_PROD) $(SQLITE3_OBJ_PROD) $(TRE_OBJ_PROD) $(GRAMMAR_OBJS_PROD) $(TS_RUNTIME_OBJ_PROD) $(LSP_OBJ_PROD) $(PP_OBJ_PROD) $(LZ4_OBJ_PROD) $(ZSTD_OBJ_PROD) $(UNIXCODER_OBJ)
@@ -1162,7 +1177,8 @@ MAIN_SRC = src/main.c
11621177# configuration and it is rewritten only when that content changes, so ordinary
11631178# incremental builds are unaffected. (Single-quoted: the signature may contain
11641179# the escaped quotes of -DCBM_VERSION, which are literal inside '', but must not
1165- # contain a literal single quote.)
1180+ # contain a literal single quote.) The config-flavoured prod objects above
1181+ # depend on the stamp for the same reason as the binary.
11661182# SANITIZE belongs here: it changes the instrumentation compiled into every
11671183# object, so a build that only changes it MUST rebuild. Its absence made
11681184# `scripts/test.sh SANITIZE= ...` -- the documented way to get a plain build
0 commit comments