Skip to content

Commit 6f290e1

Browse files
committed
build: make each grammar object depend on the sources it includes
A grammar unity object, grammar_<lang>.c, #includes its own vendored parser.c and, where the grammar has one, scanner.c. Those files were prerequisites of nothing. Editing a vendored scanner therefore left the object untouched and the edit silently absent from the binary. This is not hypothetical: the properties scanner fix in the previous commit appeared not to work at all. An A/B said 3 stalls against 2 - no effect - and the reason was that prod_grammar_properties.o predated the edit by five minutes and `nm` still showed the old `_reached_eof` symbol sitting in it. The measured "no effect" was a stale object, not a bad fix. The build already treats its other two unity objects this way and says why: LSP_UNITY_DEPS and TS_RUNTIME_DEPS both list the sources and headers they pull in, because this Makefile deliberately does not use compiler auto-dependency (-MMD) generation. Grammars were the gap, and MANIFEST.md's "Local source patches" table means patching a vendored scanner is an expected thing to do - so the trap was reachable by design. Secondary expansion is what lets one pattern rule name each grammar's own directory ($$* is the stem, grammar_properties -> properties). Applied to all three grammar object rules: production, test and tsan. Non-grammar objects match no directory and gain no prerequisite. Verified by touching internal/cbm/vendored/grammars/properties/scanner.c and watching exactly one object rebuild. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 2f33999 commit 6f290e1

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

‎Makefile.cbm‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,24 @@ test-foundation: $(BUILD_DIR)/test-foundation
861861

862862
# ── Grammar/TS/LSP object files (compiled with relaxed warnings) ─
863863

864-
$(BUILD_DIR)/%.o: $(CBM_DIR)/%.c | $(BUILD_DIR)
864+
# Each grammar_<lang>.c is a unity object that #includes its own vendored
865+
# parser.c and, where the grammar has one, scanner.c. Those includes were
866+
# prerequisites of nothing, so editing a vendored scanner left the object
867+
# untouched and the edit silently absent from the binary: on 2026-09-19 a fix
868+
# to properties/scanner.c appeared not to work at all, and `nm` showed the old
869+
# symbol still sitting in prod_grammar_properties.o. MANIFEST.md's "Local
870+
# source patches" table means patching a vendored scanner is expected, so this
871+
# trap is reachable by design. Same reasoning as LSP_UNITY_DEPS and
872+
# TS_RUNTIME_DEPS above; secondary expansion is what lets one pattern rule name
873+
# each grammar's own directory ($$* is the stem, grammar_properties ->
874+
# properties). Non-grammar objects match no directory and gain no prerequisite.
875+
GRAMMAR_VENDOR_DIR = $(CBM_DIR)/vendored/grammars/$$(subst grammar_,,$$*)
876+
GRAMMAR_UNITY_DEPS = $$(wildcard $(GRAMMAR_VENDOR_DIR)/*.c) \
877+
$$(wildcard $(GRAMMAR_VENDOR_DIR)/*.h) \
878+
$$(wildcard $(GRAMMAR_VENDOR_DIR)/tree_sitter/*.h)
879+
.SECONDEXPANSION:
880+
881+
$(BUILD_DIR)/%.o: $(CBM_DIR)/%.c $(GRAMMAR_UNITY_DEPS) | $(BUILD_DIR)
865882
$(CC) $(GRAMMAR_CFLAGS_TEST) -c -o $@ $<
866883

867884
$(BUILD_DIR)/ts_runtime.o: $(TS_RUNTIME_DEPS) | $(BUILD_DIR)
@@ -873,7 +890,7 @@ $(BUILD_DIR)/lsp_all.o: $(LSP_UNITY_DEPS) | $(BUILD_DIR)
873890
$(BUILD_DIR)/preprocessor.o: $(CBM_DIR)/preprocessor.cpp | $(BUILD_DIR)
874891
$(CXX) $(CXXFLAGS_TEST) -w -I$(CBM_DIR)/vendored -c -o $@ $<
875892

876-
$(BUILD_DIR)/tsan_%.o: $(CBM_DIR)/%.c | $(BUILD_DIR)
893+
$(BUILD_DIR)/tsan_%.o: $(CBM_DIR)/%.c $(GRAMMAR_UNITY_DEPS) | $(BUILD_DIR)
877894
$(CC) $(GRAMMAR_CFLAGS_TSAN) -c -o $@ $<
878895

879896
$(BUILD_DIR)/tsan_ts_runtime.o: $(TS_RUNTIME_DEPS) | $(BUILD_DIR)
@@ -1103,7 +1120,7 @@ TS_RUNTIME_OBJ_PROD = $(BUILD_DIR)/prod_ts_runtime.o
11031120
LSP_OBJ_PROD = $(BUILD_DIR)/prod_lsp_all.o
11041121
PP_OBJ_PROD = $(BUILD_DIR)/prod_preprocessor.o
11051122

1106-
$(BUILD_DIR)/prod_%.o: $(CBM_DIR)/%.c | $(BUILD_DIR)
1123+
$(BUILD_DIR)/prod_%.o: $(CBM_DIR)/%.c $(GRAMMAR_UNITY_DEPS) | $(BUILD_DIR)
11071124
$(CC) $(GRAMMAR_CFLAGS) -c -o $@ $<
11081125

11091126
$(BUILD_DIR)/prod_ts_runtime.o: $(TS_RUNTIME_DEPS) | $(BUILD_DIR)

0 commit comments

Comments
 (0)