diff --git a/.github/workflows/_lint.yml b/.github/workflows/_lint.yml index bddcee7df2..c1c1a45faf 100644 --- a/.github/workflows/_lint.yml +++ b/.github/workflows/_lint.yml @@ -65,7 +65,24 @@ jobs: - name: Add cppcheck to PATH run: echo "/opt/cppcheck/bin" >> "$GITHUB_PATH" + # Incremental cppcheck build directory (PRs only: release and dry-run + # gates always run cppcheck from a fresh ephemeral temp dir). Keyed on + # .cppcheck + Makefile.cbm so any suppression, flag, or LINT_SRCS change + # starts clean while unchanged TUs reuse verified .a1/.ctu-info state and + # cppcheck still runs full whole-program CTU analysis. + - name: cppcheck analysis cache + if: ${{ github.event_name == 'pull_request' }} + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ github.workspace }}/.cppcheck-build + key: cppcheck-build-2.20.0-${{ hashFiles('.cppcheck', 'Makefile.cbm') }}-${{ github.ref }}-${{ github.sha }} + restore-keys: | + cppcheck-build-2.20.0-${{ hashFiles('.cppcheck', 'Makefile.cbm') }}-${{ github.ref }}- + cppcheck-build-2.20.0-${{ hashFiles('.cppcheck', 'Makefile.cbm') }}- + - name: Lint (cppcheck + clang-format, no clang-tidy — enforced locally) + env: + CPPCHECK_BUILD_DIR: ${{ github.event_name == 'pull_request' && format('{0}/.cppcheck-build', github.workspace) || '' }} run: scripts/lint.sh --ci CLANG_FORMAT=clang-format-20 # Memory-analyzer gate (user decision 2026-08-03: runner cost accepted). diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml index ed60aca83e..c99e649756 100644 --- a/.github/workflows/_test.yml +++ b/.github/workflows/_test.yml @@ -251,7 +251,7 @@ jobs: CBM_SKIP_PERF: ${{ inputs.skip_perf && '1' || '' }} CBM_TEST_SELECTION_DIR: ${{ inputs.test_selection != '' && runner.os == 'Linux' && runner.arch == 'X64' && format('{0}/test-selection', runner.temp) || inputs.test_selection != '' && inputs.test_selection_portable && format('{0}/test-selection/portable', runner.temp) || '' }} CCACHE_DIR: ${{ github.workspace }}/.ccache - CCACHE_MAXSIZE: 1500M + CCACHE_MAXSIZE: 2500M # Every shard of a leg builds the identical runner, so one shard's # cache carries the complete object set: shard 1 (or the unsharded @@ -388,6 +388,10 @@ jobs: echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-21 main" | sudo tee /etc/apt/sources.list.d/llvm-21.list APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y clang-21 + # ccache was installed before clang-21, so update-ccache-symlinks did + # not create masquerade links for clang-21/clang++-21. + sudo ln -sf /usr/bin/ccache /usr/lib/ccache/clang-21 + sudo ln -sf /usr/bin/ccache /usr/lib/ccache/clang++-21 - name: Compiler cache (content-verified, restore) uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 @@ -405,6 +409,8 @@ jobs: - name: Test (clang-21, ASan+UBSan + off-by-default ASan checks) env: ASAN_OPTIONS: "detect_stack_use_after_return=1:strict_string_checks=1:detect_stack_use_after_scope=1" + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_MAXSIZE: 2500M run: | scripts/test.sh CC=clang-21 CXX=clang++-21 \ SANITIZE="-fsanitize=address,undefined -fno-omit-frame-pointer -fno-optimize-sibling-calls" @@ -510,9 +516,12 @@ jobs: - name: Test (Homebrew clang, ASan + LeakSanitizer) env: ASAN_OPTIONS: "detect_leaks=1:halt_on_error=1" + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_MAXSIZE: 2500M run: | LLVM_PREFIX="$(brew --prefix llvm@22)" - scripts/test.sh CC="$LLVM_PREFIX/bin/clang" CXX="$LLVM_PREFIX/bin/clang++" + export PATH="$LLVM_PREFIX/bin:$PATH" + scripts/test.sh CC=clang CXX=clang++ # Same step as in test-unix: the complete logs of the suites that did # not end green, only when the job failed. @@ -581,7 +590,7 @@ jobs: scripts/test.sh --tsan CC=${{ matrix.cc }} CXX=${{ matrix.cxx }} env: CCACHE_DIR: ${{ github.workspace }}/.ccache - CCACHE_MAXSIZE: 1500M + CCACHE_MAXSIZE: 2500M - name: ccache stats if: always() @@ -681,7 +690,7 @@ jobs: # The portable view, as on test-unix's arm64 and macOS legs. CBM_TEST_SELECTION_DIR: ${{ inputs.test_selection != '' && inputs.test_selection_portable && format('{0}/test-selection/portable', runner.temp) || '' }} CCACHE_DIR: ${{ github.workspace }}/.ccache - CCACHE_MAXSIZE: 1500M + CCACHE_MAXSIZE: 2500M - name: ccache stats if: always() @@ -801,7 +810,7 @@ jobs: run: scripts/build.sh --with-ui CC=clang CXX=clang++ TEST_SEAMS=1 env: CCACHE_DIR: ${{ github.workspace }}/.ccache - CCACHE_MAXSIZE: 1500M + CCACHE_MAXSIZE: 2500M - name: Windows regression guards (#636/#357, #618, #548, #423/#20) shell: pwsh diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 1d8994ec55..5f3177568e 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -252,7 +252,8 @@ jobs: unzip # Verified compiler cache — content-keyed, stale hits impossible by - # construction (see scripts/env.sh). + # construction (see scripts/env.sh). Cross-ref fallback matches _test.yml + # so fresh PRs start warm from main's cache instead of building cold. - name: Compiler cache (content-verified) uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: @@ -260,6 +261,7 @@ jobs: key: ccache-smoke-${{ matrix.os }}-${{ github.ref }}-${{ github.sha }} restore-keys: | ccache-smoke-${{ matrix.os }}-${{ github.ref }}- + ccache-smoke-${{ matrix.os }}- - name: Build prod + smoke (Ubuntu) if: matrix.os == 'ubuntu-latest' @@ -268,7 +270,7 @@ jobs: scripts/smoke-local.sh "$(pwd)/build/c/codebase-memory-mcp" env: CCACHE_DIR: ${{ github.workspace }}/.ccache - CCACHE_MAXSIZE: 1000M + CCACHE_MAXSIZE: 1500M SMOKE_REQUIRE_WRAPPERS: "1" - name: Build prod + smoke (macOS) @@ -279,7 +281,7 @@ jobs: scripts/smoke-local.sh "$(pwd)/build/c/codebase-memory-mcp" env: CCACHE_DIR: ${{ github.workspace }}/.ccache - CCACHE_MAXSIZE: 1000M + CCACHE_MAXSIZE: 1500M SMOKE_REQUIRE_WRAPPERS: "1" - name: Build prod + smoke (Windows) @@ -290,7 +292,7 @@ jobs: SMOKE_ARCH=amd64 bash test-infrastructure/vm/vm-smoke.sh env: CCACHE_DIR: ${{ github.workspace }}/.ccache - CCACHE_MAXSIZE: 1000M + CCACHE_MAXSIZE: 1500M SMOKE_REQUIRE_WRAPPERS: "1" # ── Waste sanitizer, REPORT-ONLY: memory + CPU waste on this repository and @@ -334,11 +336,22 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: scripts/ci/test-impact-shadow.sh --fetch-release "$RUNNER_TEMP/cbm-bin" + - name: Compiler cache (content-verified) + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ github.workspace }}/.ccache + key: ccache-shadow-ubuntu-latest-gcc-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ccache-shadow-ubuntu-latest-gcc-${{ github.ref }}- + ccache-shadow-ubuntu-latest-gcc- - name: Build the binary from this checkout (download failed) if: ${{ steps.release.outcome == 'failure' }} timeout-minutes: 20 + env: + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_MAXSIZE: 1500M run: | - APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update && sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y zlib1g-dev + APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update && sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y zlib1g-dev ccache scripts/build.sh CC=gcc CXX=g++ mkdir -p "$RUNNER_TEMP/cbm-bin" cp build/c/codebase-memory-mcp "$RUNNER_TEMP/cbm-bin/" @@ -349,8 +362,11 @@ jobs: - name: Build this checkout's engine if: ${{ steps.release.outcome != 'failure' }} timeout-minutes: 20 + env: + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_MAXSIZE: 1500M run: | - APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update && sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y zlib1g-dev + APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update && sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y zlib1g-dev ccache scripts/build.sh CC=gcc CXX=g++ - name: Select with the team artifact (engine shadow) env: diff --git a/.github/workflows/test-impact-artifact.yml b/.github/workflows/test-impact-artifact.yml index a0a53061c5..6fb1c2a007 100644 --- a/.github/workflows/test-impact-artifact.yml +++ b/.github/workflows/test-impact-artifact.yml @@ -46,13 +46,25 @@ jobs: - name: Install build deps and LLVM 21 (coverage toolchain) timeout-minutes: 10 run: | - APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update && sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y zlib1g-dev + APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update && sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y zlib1g-dev ccache wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-21 main" | sudo tee /etc/apt/sources.list.d/llvm-21.list sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y clang-21 llvm-21 libclang-rt-21-dev + - name: Compiler cache (content-verified) + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ github.workspace }}/.ccache + key: ccache-impact-ubuntu-24.04-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ccache-impact-ubuntu-24.04-${{ github.ref }}- + ccache-impact-ubuntu-24.04- + - name: Build the production binary and the coverage runner + env: + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_MAXSIZE: 2500M run: | scripts/build.sh CC=gcc CXX=g++ make -f Makefile.cbm test-runner-cov COV_LLVM_BIN=/usr/lib/llvm-21/bin -j"$(nproc)" diff --git a/Makefile.cbm b/Makefile.cbm index 6fcc6aef7d..225e66cae8 100644 --- a/Makefile.cbm +++ b/Makefile.cbm @@ -432,21 +432,10 @@ EXTRACTION_SRCS = \ $(CBM_DIR)/resolve_stats.c \ $(CBM_DIR)/extract_scope.c -# LSP resolvers (compiled as one unit via lsp_all.c) +# LSP resolvers (compiled as one unity TU via lsp_all.c; its #included lsp/*.c, +# generated/*.c, and headers are tracked automatically via -MMD -MP depfiles). LSP_SRCS = $(CBM_DIR)/lsp_all.c -# Header/source dependencies of the lsp_all unity object. lsp_all.c #includes -# every lsp/*.c resolver, which in turn include cbm.h — and CBMCall is copied -# BY VALUE across the lsp -> pipeline boundary (cbm_calls_push). This object is -# compiled standalone and linked in, NOT recompiled with the rest on every link, -# so it must list the headers/sources it pulls in. Without this, a changed struct -# layout (e.g. a new CBMCall field) leaves a stale lsp_all.o with the old layout — -# an ODR mismatch that under-reads the by-value struct copy. Explicit because this -# Makefile does not use compiler auto-dependency (-MMD) generation. -LSP_UNITY_DEPS = $(CBM_DIR)/lsp_all.c \ - $(wildcard $(CBM_DIR)/lsp/*.c $(CBM_DIR)/lsp/*.h \ - $(CBM_DIR)/lsp/generated/*.c $(CBM_DIR)/*.h) - # Tree-sitter runtime TS_RUNTIME_SRC = $(CBM_DIR)/ts_runtime.c TS_RUNTIME_DEPS = \ @@ -766,8 +755,8 @@ EXISTING_C_SRCS = $(EXTRACTION_SRCS) $(LSP_SRCS) $(TS_RUNTIME_SRC) \ # nothing had recompiled. # # Vendored trees are deliberately excluded — they are pinned, they carry their -# own explicit dep lists (LSP_UNITY_DEPS, TS_RUNTIME_DEPS), and globbing tens of -# thousands of grammar headers would cost more than it protects. +# own explicit dep lists (TS_RUNTIME_DEPS, GRAMMAR_UNITY_DEPS), and globbing +# tens of thousands of grammar headers would cost more than it protects. PROJECT_HDRS = $(wildcard src/*.h src/*/*.h $(CBM_DIR)/*.h $(CBM_DIR)/lsp/*.h tests/*.h \ tests/repro/*.h) @@ -1058,15 +1047,58 @@ PP_OBJ_TSAN = $(BUILD_DIR)/tsan_preprocessor.o # ── Targets ────────────────────────────────────────────────────── -.PHONY: test-coverage-flush test test-par test-repro test-foundation test-tsan test-daemon-smoke test-runner-cov cbm-cov cbm cbm-with-ui frontend embed clean-c lint lint-tidy lint-tidy-diff lint-cppcheck lint-format security fuzz +.PHONY: test-coverage-flush test test-par test-repro test-foundation test-tsan test-daemon-smoke test-runner-cov cbm-cov cbm cbm-with-ui frontend embed clean-c lint lint-tidy lint-tidy-diff lint-cppcheck lint-format security fuzz build-config-check test-build-config-check tsan-build-config-check $(BUILD_DIR): mkdir -p $(BUILD_DIR) +# ── First-party & test per-object compilation ──────────────────── +# Compile each C translation unit independently with -c -MMD -MP instead of +# passing hundreds of .c files to one $(CC) -o binary invocation. That lets +# `make -j` compile across all cores, gives exact per-TU header tracking, and +# lets content-verified ccache cache every unchanged TU across runs (multi-file +# -o binary bypasses ccache). +# Distinct object prefixes isolate compilation flag sets: +# t/ CFLAGS_TEST + -Itests -Itests/repro (test-runner, test-repro-runner, +# cbm-fuzz, test-foundation) +# i/ CFLAGS_IMAGE_PROBE + -Itests (test-runner-image-probe; no coverage) +# s/ CFLAGS_TSAN + -Itests -Itests/repro (test-runner-tsan + tsan probe) +# p/ CFLAGS_PROD (codebase-memory-mcp, cbm-with-ui) +CORE_C_SRCS = $(PROD_SRCS) $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC) +CORE_C_SRCS_WITH_ASSETS = $(PROD_SRCS_WITH_ASSETS) $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC) + +TEST_CORE_OBJS = $(patsubst %.c,$(BUILD_DIR)/t/%.o,$(CORE_C_SRCS)) +TEST_SUITE_OBJS = $(patsubst %.c,$(BUILD_DIR)/t/%.o,$(ALL_TEST_SRCS)) +TEST_RUNNER_OBJS = $(TEST_SUITE_OBJS) $(TEST_CORE_OBJS) +TEST_FOUNDATION_OBJS = $(patsubst %.c,$(BUILD_DIR)/t/%.o,$(TEST_FOUNDATION_SRCS) $(FOUNDATION_SRCS)) +TEST_REPRO_OBJS = $(patsubst %.c,$(BUILD_DIR)/t/%.o,$(TEST_REPRO_SRCS)) $(TEST_CORE_OBJS) +FUZZ_OBJ = $(patsubst %.c,$(BUILD_DIR)/t/%.o,$(FUZZ_SRC)) + +IMAGE_PROBE_TEST_OBJS = $(patsubst %.c,$(BUILD_DIR)/i/%.o,$(IMAGE_PROBE_SRCS)) +IMAGE_PROBE_TSAN_OBJS = $(patsubst %.c,$(BUILD_DIR)/s/%.o,$(IMAGE_PROBE_SRCS)) +TSAN_RUNNER_OBJS = $(patsubst %.c,$(BUILD_DIR)/s/%.o,$(ALL_TEST_SRCS) $(CORE_C_SRCS)) + +PROD_BIN_OBJS = $(patsubst %.c,$(BUILD_DIR)/p/%.o,$(MAIN_SRC) $(CORE_C_SRCS)) +PROD_UI_BIN_OBJS = $(patsubst %.c,$(BUILD_DIR)/p/%.o,$(MAIN_SRC) $(CORE_C_SRCS_WITH_ASSETS)) + +TEST_BUILD_CONFIG_SIG := CC=$(CC)|CXX=$(CXX)|SANITIZE=$(SANITIZE)|TEST_COVERAGE=$(TEST_COVERAGE)|CXX_STDLIB_FLAGS=$(CXX_STDLIB_FLAGS)|ZSTD_EXTRA_CFLAGS=$(ZSTD_EXTRA_CFLAGS) +test-build-config-check: +$(BUILD_DIR)/.test-build-config: test-build-config-check | $(BUILD_DIR) + @printf '%s\n' '$(TEST_BUILD_CONFIG_SIG)' > $@.tmp + @if cmp -s $@.tmp $@; then rm -f $@.tmp; \ + else mv -f $@.tmp $@; rm -f $(BUILD_DIR)/test-runner $(BUILD_DIR)/test-runner-image-probe $(BUILD_DIR)/test-repro-runner $(BUILD_DIR)/test-foundation $(BUILD_DIR)/cbm-fuzz; fi + +TSAN_BUILD_CONFIG_SIG := CC=$(CC)|CXX=$(CXX)|TSAN_SANITIZE=$(TSAN_SANITIZE)|CXX_STDLIB_FLAGS=$(CXX_STDLIB_FLAGS) +tsan-build-config-check: +$(BUILD_DIR)/.tsan-build-config: tsan-build-config-check | $(BUILD_DIR) + @printf '%s\n' '$(TSAN_BUILD_CONFIG_SIG)' > $@.tmp + @if cmp -s $@.tmp $@; then rm -f $@.tmp; \ + else mv -f $@.tmp $@; rm -f $(BUILD_DIR)/test-runner-tsan $(BUILD_DIR)/test-runner-tsan-image-probe; fi + # ── Foundation-only test (fast, no extraction) ─────────────────── -$(BUILD_DIR)/test-foundation: $(TEST_FOUNDATION_SRCS) $(FOUNDATION_SRCS) $(PROJECT_HDRS) | $(BUILD_DIR) - $(CC) $(CFLAGS_TEST) -o $@ $(TEST_FOUNDATION_SRCS) $(FOUNDATION_SRCS) $(LDFLAGS_TEST) +$(BUILD_DIR)/test-foundation: $(TEST_FOUNDATION_OBJS) $(PROJECT_HDRS) | $(BUILD_DIR) + $(CC) $(TEST_COVERAGE_FLAGS) -o $@ $(TEST_FOUNDATION_OBJS) $(LDFLAGS_TEST) test-foundation: $(BUILD_DIR)/test-foundation cd "$(CURDIR)" && $(BUILD_DIR)/test-foundation @@ -1080,8 +1112,8 @@ test-foundation: $(BUILD_DIR)/test-foundation # to properties/scanner.c appeared not to work at all, and `nm` showed the old # symbol still sitting in prod_grammar_properties.o. MANIFEST.md's "Local # source patches" table means patching a vendored scanner is expected, so this -# trap is reachable by design. Same reasoning as LSP_UNITY_DEPS and -# TS_RUNTIME_DEPS above; secondary expansion is what lets one pattern rule name +# trap is reachable by design. Same reasoning as TS_RUNTIME_DEPS above; +# secondary expansion is what lets one pattern rule name # each grammar's own directory ($$* is the stem, grammar_properties -> # properties). Non-grammar objects match no directory and gain no prerequisite. GRAMMAR_VENDOR_DIR = $(CBM_DIR)/vendored/grammars/$$(subst grammar_,,$$*) @@ -1090,28 +1122,28 @@ GRAMMAR_UNITY_DEPS = $$(wildcard $(GRAMMAR_VENDOR_DIR)/*.c) \ $$(wildcard $(GRAMMAR_VENDOR_DIR)/tree_sitter/*.h) .SECONDEXPANSION: -$(BUILD_DIR)/%.o: $(CBM_DIR)/%.c $(GRAMMAR_UNITY_DEPS) | $(BUILD_DIR) +$(BUILD_DIR)/%.o: $(CBM_DIR)/%.c $(GRAMMAR_UNITY_DEPS) $(BUILD_DIR)/.test-build-config | $(BUILD_DIR) $(CC) $(GRAMMAR_CFLAGS_TEST) -c -o $@ $< -$(BUILD_DIR)/ts_runtime.o: $(TS_RUNTIME_DEPS) | $(BUILD_DIR) +$(BUILD_DIR)/ts_runtime.o: $(TS_RUNTIME_DEPS) $(BUILD_DIR)/.test-build-config | $(BUILD_DIR) $(CC) $(GRAMMAR_CFLAGS_TEST) -c -o $@ $< -$(BUILD_DIR)/lsp_all.o: $(LSP_UNITY_DEPS) | $(BUILD_DIR) - $(CC) $(GRAMMAR_CFLAGS_TEST) $(SANITIZE) $(TEST_COVERAGE_FLAGS) -c -o $@ $< +$(BUILD_DIR)/lsp_all.o: $(CBM_DIR)/lsp_all.c $(BUILD_DIR)/.test-build-config | $(BUILD_DIR) + $(CC) $(GRAMMAR_CFLAGS_TEST) $(SANITIZE) $(TEST_COVERAGE_FLAGS) -MMD -MP -MF $(@:.o=.d) -c -o $@ $< -$(BUILD_DIR)/preprocessor.o: $(CBM_DIR)/preprocessor.cpp | $(BUILD_DIR) +$(BUILD_DIR)/preprocessor.o: $(CBM_DIR)/preprocessor.cpp $(BUILD_DIR)/.test-build-config | $(BUILD_DIR) $(CXX) $(CXXFLAGS_TEST) -w -I$(CBM_DIR)/vendored -c -o $@ $< -$(BUILD_DIR)/tsan_%.o: $(CBM_DIR)/%.c $(GRAMMAR_UNITY_DEPS) | $(BUILD_DIR) +$(BUILD_DIR)/tsan_%.o: $(CBM_DIR)/%.c $(GRAMMAR_UNITY_DEPS) $(BUILD_DIR)/.tsan-build-config | $(BUILD_DIR) $(CC) $(GRAMMAR_CFLAGS_TSAN) -c -o $@ $< -$(BUILD_DIR)/tsan_ts_runtime.o: $(TS_RUNTIME_DEPS) | $(BUILD_DIR) +$(BUILD_DIR)/tsan_ts_runtime.o: $(TS_RUNTIME_DEPS) $(BUILD_DIR)/.tsan-build-config | $(BUILD_DIR) $(CC) $(GRAMMAR_CFLAGS_TSAN) -c -o $@ $< -$(BUILD_DIR)/tsan_lsp_all.o: $(LSP_UNITY_DEPS) | $(BUILD_DIR) - $(CC) $(GRAMMAR_CFLAGS_TSAN) -c -o $@ $< +$(BUILD_DIR)/tsan_lsp_all.o: $(CBM_DIR)/lsp_all.c $(BUILD_DIR)/.tsan-build-config | $(BUILD_DIR) + $(CC) $(GRAMMAR_CFLAGS_TSAN) -MMD -MP -MF $(@:.o=.d) -c -o $@ $< -$(BUILD_DIR)/tsan_preprocessor.o: $(CBM_DIR)/preprocessor.cpp | $(BUILD_DIR) +$(BUILD_DIR)/tsan_preprocessor.o: $(CBM_DIR)/preprocessor.cpp $(BUILD_DIR)/.tsan-build-config | $(BUILD_DIR) $(CXX) $(CXXFLAGS_TSAN) -w -I$(CBM_DIR)/vendored -c -o $@ $< # ── Full test binary ───────────────────────────────────────────── @@ -1122,11 +1154,11 @@ MIMALLOC_OBJ_TSAN = $(BUILD_DIR)/tsan_mimalloc.o MIMALLOC_OBJ_PROD = $(BUILD_DIR)/prod_mimalloc.o $(BUILD_DIR)/mimalloc.o: $(MIMALLOC_SRC) $(wildcard vendored/mimalloc/src/*.c) \ - $(wildcard vendored/mimalloc/include/*.h) Makefile.cbm | $(BUILD_DIR) + $(wildcard vendored/mimalloc/include/*.h) Makefile.cbm $(BUILD_DIR)/.test-build-config | $(BUILD_DIR) $(CC) $(MIMALLOC_CFLAGS_TEST) -c -o $@ $< $(BUILD_DIR)/tsan_mimalloc.o: $(MIMALLOC_SRC) $(wildcard vendored/mimalloc/src/*.c) \ - $(wildcard vendored/mimalloc/include/*.h) Makefile.cbm | $(BUILD_DIR) + $(wildcard vendored/mimalloc/include/*.h) Makefile.cbm $(BUILD_DIR)/.tsan-build-config | $(BUILD_DIR) $(CC) $(MIMALLOC_CFLAGS_TEST) $(TSAN_SANITIZE) -c -o $@ $< # static.c is an AMALGAMATION: it #includes options.c and friends, none of which @@ -1134,9 +1166,10 @@ $(BUILD_DIR)/tsan_mimalloc.o: $(MIMALLOC_SRC) $(wildcard vendored/mimalloc/src/* # in this Makefile. Both gaps bit for real — the __DATE__ removal in options.c and # SQLITE_OMIT_LOAD_EXTENSION below each silently did nothing on an incremental # build because the object was considered up to date. Depend on the included -# sources AND on this Makefile so a flag change rebuilds too. +# sources, this Makefile, and .build-config (tracks CC/CXX) so flag or compiler +# changes rebuild too. $(BUILD_DIR)/prod_mimalloc.o: $(MIMALLOC_SRC) $(wildcard vendored/mimalloc/src/*.c) \ - $(wildcard vendored/mimalloc/include/*.h) Makefile.cbm | $(BUILD_DIR) + $(wildcard vendored/mimalloc/include/*.h) Makefile.cbm $(BUILD_DIR)/.build-config | $(BUILD_DIR) $(CC) $(MIMALLOC_CFLAGS) -c -o $@ $< # sqlite3 object files (vendored amalgamation) @@ -1144,10 +1177,10 @@ SQLITE3_OBJ_TEST = $(BUILD_DIR)/sqlite3.o SQLITE3_OBJ_TSAN = $(BUILD_DIR)/tsan_sqlite3.o SQLITE3_OBJ_PROD = $(BUILD_DIR)/prod_sqlite3.o -$(BUILD_DIR)/sqlite3.o: $(SQLITE3_SRC) | $(BUILD_DIR) +$(BUILD_DIR)/sqlite3.o: $(SQLITE3_SRC) $(BUILD_DIR)/.test-build-config | $(BUILD_DIR) $(CC) $(SQLITE3_CFLAGS_TEST) $(SANITIZE) -c -o $@ $< -$(BUILD_DIR)/tsan_sqlite3.o: $(SQLITE3_SRC) | $(BUILD_DIR) +$(BUILD_DIR)/tsan_sqlite3.o: $(SQLITE3_SRC) $(BUILD_DIR)/.tsan-build-config | $(BUILD_DIR) $(CC) $(SQLITE3_CFLAGS_TEST) $(TSAN_SANITIZE) -c -o $@ $< # .build-config: SQLITE3_CFLAGS carries MEMWASTE_VENDOR_CFLAGS (see the stamp @@ -1176,10 +1209,10 @@ TRE_OBJ_PROD = $(BUILD_DIR)/prod_tre.o # TRE is third-party code we vendor and do not modify, so the alignment # behaviour is upstream's to change; suppressing the check for this one # object is the honest scope. Everything else keeps alignment armed. -$(BUILD_DIR)/tre.o: $(TRE_SRC) | $(BUILD_DIR) +$(BUILD_DIR)/tre.o: $(TRE_SRC) $(BUILD_DIR)/.test-build-config | $(BUILD_DIR) $(CC) $(TRE_CFLAGS) $(SANITIZE) -fno-sanitize=alignment -c -o $@ $< -$(BUILD_DIR)/tsan_tre.o: $(TRE_SRC) | $(BUILD_DIR) +$(BUILD_DIR)/tsan_tre.o: $(TRE_SRC) $(BUILD_DIR)/.tsan-build-config | $(BUILD_DIR) $(CC) $(TRE_CFLAGS) $(TSAN_SANITIZE) -c -o $@ $< $(BUILD_DIR)/prod_tre.o: $(TRE_SRC) $(BUILD_DIR)/.build-config | $(BUILD_DIR) @@ -1189,13 +1222,13 @@ endif # Vendored LZ4 (test build) LZ4_OBJ_TEST = $(BUILD_DIR)/test_lz4.o $(BUILD_DIR)/test_lz4hc.o LZ4_OBJ_TSAN = $(BUILD_DIR)/tsan_lz4.o $(BUILD_DIR)/tsan_lz4hc.o -$(BUILD_DIR)/test_lz4.o: $(CBM_DIR)/vendored/lz4/lz4.c | $(BUILD_DIR) +$(BUILD_DIR)/test_lz4.o: $(CBM_DIR)/vendored/lz4/lz4.c $(BUILD_DIR)/.test-build-config | $(BUILD_DIR) $(CC) -std=c11 -D_DEFAULT_SOURCE -g -O1 $(SANITIZE) -w -I$(CBM_DIR) -c -o $@ $< -$(BUILD_DIR)/test_lz4hc.o: $(CBM_DIR)/vendored/lz4/lz4hc.c | $(BUILD_DIR) +$(BUILD_DIR)/test_lz4hc.o: $(CBM_DIR)/vendored/lz4/lz4hc.c $(BUILD_DIR)/.test-build-config | $(BUILD_DIR) $(CC) -std=c11 -D_DEFAULT_SOURCE -g -O1 $(SANITIZE) -w -I$(CBM_DIR)/vendored/lz4 -c -o $@ $< -$(BUILD_DIR)/tsan_lz4.o: $(CBM_DIR)/vendored/lz4/lz4.c | $(BUILD_DIR) +$(BUILD_DIR)/tsan_lz4.o: $(CBM_DIR)/vendored/lz4/lz4.c $(BUILD_DIR)/.tsan-build-config | $(BUILD_DIR) $(CC) -std=c11 -D_DEFAULT_SOURCE -g -O1 $(TSAN_SANITIZE) -w -I$(CBM_DIR) -c -o $@ $< -$(BUILD_DIR)/tsan_lz4hc.o: $(CBM_DIR)/vendored/lz4/lz4hc.c | $(BUILD_DIR) +$(BUILD_DIR)/tsan_lz4hc.o: $(CBM_DIR)/vendored/lz4/lz4hc.c $(BUILD_DIR)/.tsan-build-config | $(BUILD_DIR) $(CC) -std=c11 -D_DEFAULT_SOURCE -g -O1 $(TSAN_SANITIZE) -w -I$(CBM_DIR)/vendored/lz4 -c -o $@ $< # Vendored zstd (test build) @@ -1209,9 +1242,9 @@ $(BUILD_DIR)/tsan_lz4hc.o: $(CBM_DIR)/vendored/lz4/lz4hc.c | $(BUILD_DIR) # MREMAP_MAYMOVE/nanosleep out of their view of libc. ZSTD_OBJ_TEST = $(BUILD_DIR)/test_zstd.o ZSTD_OBJ_TSAN = $(BUILD_DIR)/tsan_zstd.o -$(BUILD_DIR)/test_zstd.o: $(CBM_DIR)/vendored/zstd/zstd.c | $(BUILD_DIR) +$(BUILD_DIR)/test_zstd.o: $(CBM_DIR)/vendored/zstd/zstd.c $(BUILD_DIR)/.test-build-config | $(BUILD_DIR) $(CC) -std=c11 -D_DEFAULT_SOURCE -g -O1 $(SANITIZE) $(ZSTD_EXTRA_CFLAGS) -w -I$(CBM_DIR)/vendored/zstd -c -o $@ $< -$(BUILD_DIR)/tsan_zstd.o: $(CBM_DIR)/vendored/zstd/zstd.c | $(BUILD_DIR) +$(BUILD_DIR)/tsan_zstd.o: $(CBM_DIR)/vendored/zstd/zstd.c $(BUILD_DIR)/.tsan-build-config | $(BUILD_DIR) $(CC) -std=c11 -D_DEFAULT_SOURCE -g -O1 $(TSAN_SANITIZE) -w -I$(CBM_DIR)/vendored/zstd -c -o $@ $< # nomic-embed-code pretrained vector blob @@ -1241,18 +1274,17 @@ IMAGE_PROBE_SRCS = tests/image_probe_main.c tests/image_probe_roles.c \ CFLAGS_IMAGE_PROBE = $(filter-out $(TEST_COVERAGE_FLAGS) $(TEST_COVERAGE_DEFINE),$(CFLAGS_TEST)) # TRE_OBJ_* is empty except on Windows, where compat_regex.c is backed by TRE. -$(BUILD_DIR)/test-runner-image-probe: $(IMAGE_PROBE_SRCS) $(MIMALLOC_OBJ_TEST) $(TRE_OBJ_TEST) $(PROJECT_HDRS) | $(BUILD_DIR) - $(CC) $(CFLAGS_IMAGE_PROBE) -Itests -o $@ $(IMAGE_PROBE_SRCS) $(MIMALLOC_OBJ_TEST) \ +$(BUILD_DIR)/test-runner-image-probe: $(IMAGE_PROBE_TEST_OBJS) $(MIMALLOC_OBJ_TEST) $(TRE_OBJ_TEST) $(PROJECT_HDRS) | $(BUILD_DIR) + $(CC) -o $@ $(IMAGE_PROBE_TEST_OBJS) $(MIMALLOC_OBJ_TEST) \ $(TRE_OBJ_TEST) $(LDFLAGS_TEST) -$(BUILD_DIR)/test-runner-tsan-image-probe: $(IMAGE_PROBE_SRCS) $(MIMALLOC_OBJ_TSAN) $(TRE_OBJ_TSAN) $(PROJECT_HDRS) | $(BUILD_DIR) - $(CC) $(CFLAGS_TSAN) -Itests -o $@ $(IMAGE_PROBE_SRCS) $(MIMALLOC_OBJ_TSAN) $(TRE_OBJ_TSAN) \ +$(BUILD_DIR)/test-runner-tsan-image-probe: $(IMAGE_PROBE_TSAN_OBJS) $(MIMALLOC_OBJ_TSAN) $(TRE_OBJ_TSAN) $(PROJECT_HDRS) | $(BUILD_DIR) + $(CC) -o $@ $(IMAGE_PROBE_TSAN_OBJS) $(MIMALLOC_OBJ_TSAN) $(TRE_OBJ_TSAN) \ $(LDFLAGS_TSAN) -$(BUILD_DIR)/test-runner: $(ALL_TEST_SRCS) $(PROD_SRCS) $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC) $(OBJS_VENDORED_TEST) $(PROJECT_HDRS) | $(BUILD_DIR) $(BUILD_DIR)/test-runner-image-probe - $(CC) $(CFLAGS_TEST) -Itests -Itests/repro -o $@ \ - $(ALL_TEST_SRCS) $(PROD_SRCS) \ - $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC) \ +$(BUILD_DIR)/test-runner: $(TEST_RUNNER_OBJS) $(OBJS_VENDORED_TEST) $(PROJECT_HDRS) | $(BUILD_DIR) $(BUILD_DIR)/test-runner-image-probe + $(CC) $(TEST_COVERAGE_FLAGS) -o $@ \ + $(TEST_RUNNER_OBJS) \ $(OBJS_VENDORED_TEST) \ $(LDFLAGS_TEST) @@ -1277,10 +1309,9 @@ test-focused: $(BUILD_DIR)/test-runner # Mirrors test-runner's link line but uses repro_main.c (own main + counters) # and TEST_REPRO_SRCS instead of ALL_TEST_SRCS. Exits non-zero while any bug is # still reproduced (the expected state); bug-repro.yml surfaces it as a board. -$(BUILD_DIR)/test-repro-runner: $(TEST_REPRO_SRCS) $(PROD_SRCS) $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC) $(OBJS_VENDORED_TEST) $(PROJECT_HDRS) | $(BUILD_DIR) - $(CC) $(CFLAGS_TEST) -Itests -o $@ \ - $(TEST_REPRO_SRCS) $(PROD_SRCS) \ - $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC) \ +$(BUILD_DIR)/test-repro-runner: $(TEST_REPRO_OBJS) $(OBJS_VENDORED_TEST) $(PROJECT_HDRS) | $(BUILD_DIR) + $(CC) $(TEST_COVERAGE_FLAGS) -o $@ \ + $(TEST_REPRO_OBJS) \ $(OBJS_VENDORED_TEST) \ $(LDFLAGS_TEST) @@ -1337,10 +1368,9 @@ TSAN_OPTIONS ?= halt_on_error=1:report_thread_leaks=0 # Normal ASan/native/soak paths remain uncapped. High-worker TSan diagnostics # invoke test-runner-tsan directly so release gates cannot drift accidentally. -$(BUILD_DIR)/test-runner-tsan: $(ALL_TEST_SRCS) $(PROD_SRCS) $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC) $(OBJS_VENDORED_TSAN) $(PROJECT_HDRS) | $(BUILD_DIR) $(BUILD_DIR)/test-runner-tsan-image-probe - $(CC) $(CFLAGS_TSAN) -Itests -Itests/repro -o $@ \ - $(ALL_TEST_SRCS) $(PROD_SRCS) \ - $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC) \ +$(BUILD_DIR)/test-runner-tsan: $(TSAN_RUNNER_OBJS) $(OBJS_VENDORED_TSAN) $(PROJECT_HDRS) | $(BUILD_DIR) $(BUILD_DIR)/test-runner-tsan-image-probe + $(CC) -o $@ \ + $(TSAN_RUNNER_OBJS) \ $(OBJS_VENDORED_TSAN) \ $(LDFLAGS_TSAN) @@ -1363,21 +1393,20 @@ TS_RUNTIME_OBJ_PROD = $(BUILD_DIR)/prod_ts_runtime.o LSP_OBJ_PROD = $(BUILD_DIR)/prod_lsp_all.o PP_OBJ_PROD = $(BUILD_DIR)/prod_preprocessor.o -# Every prod object whose flags carry a BUILD_CONFIG_SIG variable -# (TEST_SEAM_DEFINE via GRAMMAR_CFLAGS, MEMWASTE_VENDOR_CFLAGS) depends on the -# $(BUILD_DIR)/.build-config stamp. These objects are compiled once and linked -# into every later binary, so without the stamp a TEST_SEAMS or MEMWASTE flip -# relinks the PREVIOUS flavour: a release binary keeps seam code compiled into -# lsp_all, or a seams binary misses it. prod_mimalloc.o and the unixcoder blob -# take no config variable and stay off the stamp. +# Every prod object whose flags or compiler carry a BUILD_CONFIG_SIG variable +# (CC/CXX, TEST_SEAM_DEFINE via GRAMMAR_CFLAGS, MEMWASTE_VENDOR_CFLAGS) depends +# on the $(BUILD_DIR)/.build-config stamp. These objects are compiled once and +# linked into every later binary, so without the stamp a compiler, TEST_SEAMS, +# or MEMWASTE flip relinks the PREVIOUS flavour. Only the raw-data unixcoder +# assembly blob stays off the stamp. $(BUILD_DIR)/prod_%.o: $(CBM_DIR)/%.c $(GRAMMAR_UNITY_DEPS) $(BUILD_DIR)/.build-config | $(BUILD_DIR) $(CC) $(GRAMMAR_CFLAGS) -c -o $@ $< $(BUILD_DIR)/prod_ts_runtime.o: $(TS_RUNTIME_DEPS) $(BUILD_DIR)/.build-config | $(BUILD_DIR) $(CC) $(GRAMMAR_CFLAGS) -c -o $@ $< -$(BUILD_DIR)/prod_lsp_all.o: $(LSP_UNITY_DEPS) $(BUILD_DIR)/.build-config | $(BUILD_DIR) - $(CC) $(GRAMMAR_CFLAGS) $(TEST_COVERAGE_FLAGS) -c -o $@ $< +$(BUILD_DIR)/prod_lsp_all.o: $(CBM_DIR)/lsp_all.c $(BUILD_DIR)/.build-config | $(BUILD_DIR) + $(CC) $(GRAMMAR_CFLAGS) $(TEST_COVERAGE_FLAGS) -MMD -MP -MF $(@:.o=.d) -c -o $@ $< $(BUILD_DIR)/prod_preprocessor.o: $(CBM_DIR)/preprocessor.cpp $(BUILD_DIR)/.build-config | $(BUILD_DIR) $(CXX) $(CXXFLAGS_PROD) -w -I$(CBM_DIR)/vendored -c -o $@ $< @@ -1425,7 +1454,7 @@ MAIN_SRC = src/main.c # for trap debugging -- silently re-run the previously instrumented binary, # which during this bisect produced a "crashes without sanitizers too" result # that was pure artifact and sent the investigation down the wrong path. -BUILD_CONFIG_SIG := TEST_SEAMS=$(TEST_SEAMS)|CFLAGS_EXTRA=$(CFLAGS_EXTRA)|SANITIZE=$(SANITIZE)|MEMWASTE=$(MEMWASTE)|MEMWASTE_ACCESS=$(MEMWASTE_ACCESS)|MEMWASTE_PROFILE=$(MEMWASTE_PROFILE)|TEST_COVERAGE=$(TEST_COVERAGE) +BUILD_CONFIG_SIG := CC=$(CC)|CXX=$(CXX)|STATIC=$(STATIC)|TEST_SEAMS=$(TEST_SEAMS)|CFLAGS_EXTRA=$(CFLAGS_EXTRA)|SANITIZE=$(SANITIZE)|MEMWASTE=$(MEMWASTE)|MEMWASTE_ACCESS=$(MEMWASTE_ACCESS)|MEMWASTE_PROFILE=$(MEMWASTE_PROFILE)|TEST_COVERAGE=$(TEST_COVERAGE) .PHONY: build-config-check build-config-check: $(BUILD_DIR)/.build-config: build-config-check | $(BUILD_DIR) @@ -1434,10 +1463,9 @@ $(BUILD_DIR)/.build-config: build-config-check | $(BUILD_DIR) else mv -f $@.tmp $@; rm -f $(BUILD_DIR)/codebase-memory-mcp; \ echo "=== build config changed -> full rebuild: $(BUILD_CONFIG_SIG) ==="; fi -$(BUILD_DIR)/codebase-memory-mcp: $(MAIN_SRC) $(PROD_SRCS) $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC) $(OBJS_VENDORED_PROD) $(BUILD_DIR)/.build-config $(PROJECT_HDRS) | $(BUILD_DIR) - $(CC) $(CFLAGS_PROD) -o $@ \ - $(MAIN_SRC) $(PROD_SRCS) \ - $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC) \ +$(BUILD_DIR)/codebase-memory-mcp: $(PROD_BIN_OBJS) $(OBJS_VENDORED_PROD) $(BUILD_DIR)/.build-config $(PROJECT_HDRS) | $(BUILD_DIR) + $(CC) -O2 $(TEST_COVERAGE_FLAGS) -o $@ \ + $(PROD_BIN_OBJS) \ $(OBJS_VENDORED_PROD) \ $(LDFLAGS) @@ -1462,10 +1490,10 @@ frontend: embed: frontend scripts/embed-frontend.sh graph-ui/dist $(BUILD_DIR)/embedded -cbm-with-ui: embed $(OBJS_VENDORED_PROD) - $(CC) $(CFLAGS_PROD) -o $(BUILD_DIR)/codebase-memory-mcp \ - $(MAIN_SRC) $(PROD_SRCS_WITH_ASSETS) \ - $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC) \ +cbm-with-ui: embed $(OBJS_VENDORED_PROD) $(filter-out $(BUILD_DIR)/p/src/ui/embedded_assets.o,$(PROD_UI_BIN_OBJS)) | $(BUILD_DIR)/p/src/ui + $(CC) $(CFLAGS_PROD) -MMD -MP -MF $(BUILD_DIR)/p/src/ui/embedded_assets.d -c -o $(BUILD_DIR)/p/src/ui/embedded_assets.o src/ui/embedded_assets.c + $(CC) -O2 $(TEST_COVERAGE_FLAGS) -o $(BUILD_DIR)/codebase-memory-mcp \ + $(PROD_UI_BIN_OBJS) \ $(OBJS_VENDORED_PROD) \ $(wildcard $(BUILD_DIR)/embedded/embed_*.o) \ $(LDFLAGS) @@ -1484,6 +1512,7 @@ CLANG_TIDY ?= $(shell [ -x "$(LLVM_BIN)/clang-tidy" ] && echo "$(LLVM_BIN)/clang CLANG_FORMAT ?= $(shell [ -x "$(LLVM_BIN)/clang-format" ] && echo "$(LLVM_BIN)/clang-format" || echo clang-format) CPPCHECK ?= cppcheck CPPCHECK_JOBS ?= 2 +CPPCHECK_BUILD_DIR ?= # macOS SDK sysroot (needed for Homebrew LLVM to find system headers) SYSROOT = $(shell xcrun --show-sdk-path 2>/dev/null) @@ -1509,13 +1538,21 @@ lint-tidy-diff: @scripts/lint-tidy-diff.sh "$(CLANG_TIDY)" $(LINT_SRCS) -- $(CFLAGS_COMMON) $(SYSROOT_FLAG) # cppcheck: complementary analysis (config in .cppcheck). A build directory -# retains whole-program analysis with parallel workers; each run owns its state. +# retains whole-program analysis with parallel workers. When CPPCHECK_BUILD_DIR +# is unset each run uses a fresh temp dir; PR CI passes a persistent cached dir +# keyed on .cppcheck + Makefile.cbm so cppcheck re-analyzes only changed TUs +# (verified by cppcheck's own source + header hashes) plus full CTU analysis. lint-cppcheck: @echo "=== cppcheck ===" @set -e; \ - cppcheck_dir=$$(mktemp -d "$${TMPDIR:-/tmp}/cbm-cppcheck.XXXXXX"); \ - trap 'status=$$?; rm -rf "$$cppcheck_dir" || :; exit "$$status"' EXIT; \ - trap 'exit 129' HUP; trap 'exit 130' INT; trap 'exit 143' TERM; \ + if [ -n "$(CPPCHECK_BUILD_DIR)" ]; then \ + cppcheck_dir="$(CPPCHECK_BUILD_DIR)"; \ + mkdir -p "$$cppcheck_dir"; \ + else \ + cppcheck_dir=$$(mktemp -d "$${TMPDIR:-/tmp}/cbm-cppcheck.XXXXXX"); \ + trap 'status=$$?; rm -rf "$$cppcheck_dir" || :; exit "$$status"' EXIT; \ + trap 'exit 129' HUP; trap 'exit 130' INT; trap 'exit 143' TERM; \ + fi; \ $(CPPCHECK) -j$(CPPCHECK_JOBS) --cppcheck-build-dir="$$cppcheck_dir" \ --enable=warning,style,performance,portability \ --std=c11 --language=c \ @@ -1737,10 +1774,9 @@ fuzz: # Linux leaves out UBSan's C++ runtime, but the C++ objects (preprocessor, # simplecpp) carry -fsanitize=vptr checks that need it # (__ubsan_vptr_type_cache, __ubsan_handle_dynamic_type_cache_miss). -$(BUILD_DIR)/cbm-fuzz: $(FUZZ_SRC) $(PROD_SRCS) $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC) $(OBJS_VENDORED_TEST) $(PROJECT_HDRS) | $(BUILD_DIR) - $(CC) $(CFLAGS_TEST) -fsanitize=fuzzer -fsanitize-link-c++-runtime -o $@ \ - $(FUZZ_SRC) $(PROD_SRCS) \ - $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC) \ +$(BUILD_DIR)/cbm-fuzz: $(FUZZ_OBJ) $(TEST_CORE_OBJS) $(OBJS_VENDORED_TEST) $(PROJECT_HDRS) | $(BUILD_DIR) + $(CC) $(TEST_COVERAGE_FLAGS) -fsanitize=fuzzer -fsanitize-link-c++-runtime -o $@ \ + $(FUZZ_OBJ) $(TEST_CORE_OBJS) \ $(OBJS_VENDORED_TEST) \ $(LDFLAGS_TEST) @@ -1785,3 +1821,28 @@ security: cbm scripts/security-fuzz.sh $(BUILD_DIR)/codebase-memory-mcp scripts/security-vendored.sh @echo "=== All security checks passed ===" + +# Placed after .SECONDEXPANSION and every *_SRCS definition so $$(@D), +# all object paths, and depfiles expand accurately. +ALL_FIRST_PARTY_OBJS = $(sort $(TEST_RUNNER_OBJS) $(TEST_FOUNDATION_OBJS) \ + $(TEST_REPRO_OBJS) $(FUZZ_OBJ) \ + $(IMAGE_PROBE_TEST_OBJS) $(IMAGE_PROBE_TSAN_OBJS) \ + $(TSAN_RUNNER_OBJS) $(PROD_BIN_OBJS) $(PROD_UI_BIN_OBJS)) +OBJ_SUBDIRS = $(patsubst %/,%,$(sort $(dir $(ALL_FIRST_PARTY_OBJS)))) + +$(OBJ_SUBDIRS): + @mkdir -p $@ + +$(BUILD_DIR)/t/%.o: %.c $(BUILD_DIR)/.test-build-config | $$(@D) + $(CC) $(CFLAGS_TEST) -Itests -Itests/repro -MMD -MP -MF $(@:.o=.d) -c -o $@ $< + +$(BUILD_DIR)/i/%.o: %.c $(BUILD_DIR)/.test-build-config | $$(@D) + $(CC) $(CFLAGS_IMAGE_PROBE) -Itests -MMD -MP -MF $(@:.o=.d) -c -o $@ $< + +$(BUILD_DIR)/s/%.o: %.c $(BUILD_DIR)/.tsan-build-config | $$(@D) + $(CC) $(CFLAGS_TSAN) -Itests -Itests/repro -MMD -MP -MF $(@:.o=.d) -c -o $@ $< + +$(BUILD_DIR)/p/%.o: %.c $(BUILD_DIR)/.build-config | $$(@D) + $(CC) $(CFLAGS_PROD) -MMD -MP -MF $(@:.o=.d) -c -o $@ $< + +-include $(ALL_FIRST_PARTY_OBJS:.o=.d) $(LSP_OBJ_TEST:.o=.d) $(LSP_OBJ_TSAN:.o=.d) $(LSP_OBJ_PROD:.o=.d) diff --git a/scripts/lint.sh b/scripts/lint.sh index b2220af673..28ca37ea13 100755 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -61,6 +61,20 @@ print_env "lint.sh" echo "=== no-skips policy (tests pass or fail) ===" bash "$ROOT/scripts/check-no-test-skips.sh" +# Default cppcheck parallelism to all detected CPU cores unless overridden. +HAS_CPPCHECK_JOBS=false +if [[ -n "${CPPCHECK_JOBS:-}" ]]; then + HAS_CPPCHECK_JOBS=true +fi +for arg in "${MAKE_ARGS[@]+"${MAKE_ARGS[@]}"}"; do + case "$arg" in + CPPCHECK_JOBS=*) HAS_CPPCHECK_JOBS=true ;; + esac +done +if ! $HAS_CPPCHECK_JOBS; then + MAKE_ARGS+=("CPPCHECK_JOBS=$NPROC") +fi + if $CI_ONLY; then echo "=== CI mode: cppcheck + clang-format ===" make -j2 -f Makefile.cbm lint-ci "${MAKE_ARGS[@]+"${MAKE_ARGS[@]}"}" diff --git a/tests/test_language_count_contract.sh b/tests/test_language_count_contract.sh index 93d171d6fc..946719fb12 100644 --- a/tests/test_language_count_contract.sh +++ b/tests/test_language_count_contract.sh @@ -120,7 +120,12 @@ while IFS= read -r path; do "SURFACES so it stays in step with the registry, or to EXEMPT with a" \ "note saying what its number actually counts." >&2 failures=$((failures + 1)) -done < <(git grep -IlE '[0-9]{2,3} languages|languages-[0-9]{2,3}' || true) +# Generated tree-sitter parser.c tables (~1.5 GB across 164 grammars) never +# carry product-count prose; skipping them cuts this scan ~20x on Windows while +# still checking MANIFEST.md, docs, manifests, scripts, and all source files. +done < <(git grep -IlE '[0-9]{2,3} languages|languages-[0-9]{2,3}' -- \ + ':(glob,exclude)internal/cbm/vendored/grammars/**/parser.c' \ + ':(glob,exclude)tools/**/parser.c' || true) if ((failures > 0)); then echo "FAIL: $failures language-count contract violation(s)" >&2