diff --git a/.github/workflows/dry-run.yml b/.github/workflows/dry-run.yml index 9e3e8883a..b91ac98a6 100644 --- a/.github/workflows/dry-run.yml +++ b/.github/workflows/dry-run.yml @@ -88,16 +88,17 @@ jobs: - uses: msys2/setup-msys2@v2 with: - msystem: UCRT64 + msystem: CLANG64 path-type: inherit install: >- - mingw-w64-ucrt-x86_64-gcc - mingw-w64-ucrt-x86_64-zlib + mingw-w64-clang-x86_64-clang + mingw-w64-clang-x86_64-compiler-rt + mingw-w64-clang-x86_64-zlib make - name: Test shell: msys2 {0} - run: scripts/test.sh + run: scripts/test.sh CC=clang CXX=clang++ WIN32_LIBS="-lws2_32 -lpsapi" # ── Step 3: Build binaries (standard + UI, all OS) ────────── build-unix: @@ -166,11 +167,11 @@ jobs: - uses: msys2/setup-msys2@v2 with: - msystem: UCRT64 + msystem: CLANG64 path-type: inherit install: >- - mingw-w64-ucrt-x86_64-gcc - mingw-w64-ucrt-x86_64-zlib + mingw-w64-clang-x86_64-clang + mingw-w64-clang-x86_64-zlib make - uses: actions/setup-node@v4 @@ -179,7 +180,7 @@ jobs: - name: Build standard binary shell: msys2 {0} - run: scripts/build.sh + run: scripts/build.sh CC=clang CXX=clang++ WIN32_LIBS="-lws2_32 -lpsapi" - name: Archive standard binary shell: pwsh @@ -189,7 +190,7 @@ jobs: - name: Build UI binary shell: msys2 {0} - run: scripts/build.sh --with-ui + run: scripts/build.sh --with-ui CC=clang CXX=clang++ WIN32_LIBS="-lws2_32 -lpsapi" - name: Archive UI binary shell: pwsh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 801a60864..01d1efd38 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -102,16 +102,17 @@ jobs: - uses: msys2/setup-msys2@v2 with: - msystem: UCRT64 + msystem: CLANG64 path-type: inherit install: >- - mingw-w64-ucrt-x86_64-gcc - mingw-w64-ucrt-x86_64-zlib + mingw-w64-clang-x86_64-clang + mingw-w64-clang-x86_64-compiler-rt + mingw-w64-clang-x86_64-zlib make - name: Test shell: msys2 {0} - run: scripts/test.sh + run: scripts/test.sh CC=clang CXX=clang++ WIN32_LIBS="-lws2_32 -lpsapi" # ── Step 3: Build binaries (standard + UI, all OS) ────────── build-unix: @@ -180,11 +181,11 @@ jobs: - uses: msys2/setup-msys2@v2 with: - msystem: UCRT64 + msystem: CLANG64 path-type: inherit install: >- - mingw-w64-ucrt-x86_64-gcc - mingw-w64-ucrt-x86_64-zlib + mingw-w64-clang-x86_64-clang + mingw-w64-clang-x86_64-zlib make - uses: actions/setup-node@v4 @@ -193,7 +194,7 @@ jobs: - name: Build standard binary shell: msys2 {0} - run: scripts/build.sh --version ${{ inputs.version }} + run: scripts/build.sh --version ${{ inputs.version }} CC=clang CXX=clang++ WIN32_LIBS="-lws2_32 -lpsapi" - name: Archive standard binary shell: pwsh @@ -203,7 +204,7 @@ jobs: - name: Build UI binary shell: msys2 {0} - run: scripts/build.sh --with-ui --version ${{ inputs.version }} + run: scripts/build.sh --with-ui --version ${{ inputs.version }} CC=clang CXX=clang++ WIN32_LIBS="-lws2_32 -lpsapi" - name: Archive UI binary shell: pwsh diff --git a/Makefile.cbm b/Makefile.cbm index fa7f25da4..39098f1d2 100644 --- a/Makefile.cbm +++ b/Makefile.cbm @@ -61,13 +61,10 @@ CXXFLAGS_COMMON = -std=c++14 -Wall -Wextra -Werror \ CFLAGS_PROD = $(CFLAGS_COMMON) -O2 $(CFLAGS_EXTRA) CXXFLAGS_PROD = $(CXXFLAGS_COMMON) -O2 -# Test flags: debug + sanitizers -CFLAGS_TEST = $(CFLAGS_COMMON) -g -O1 \ - -fsanitize=address,undefined \ - -fno-omit-frame-pointer -CXXFLAGS_TEST = $(CXXFLAGS_COMMON) -g -O1 \ - -fsanitize=address,undefined \ - -fno-omit-frame-pointer +# Test flags: debug + sanitizers (override SANITIZE= to disable on Windows) +SANITIZE = -fsanitize=address,undefined -fno-omit-frame-pointer +CFLAGS_TEST = $(CFLAGS_COMMON) -g -O1 $(SANITIZE) +CXXFLAGS_TEST = $(CXXFLAGS_COMMON) -g -O1 $(SANITIZE) # TSan (can't combine with ASan) CFLAGS_TSAN = $(CFLAGS_COMMON) -g -O1 \ @@ -80,7 +77,7 @@ CXXFLAGS_TSAN = $(CXXFLAGS_COMMON) -g -O1 \ WIN32_LIBS ?= LDFLAGS = -lm -lstdc++ -lpthread -lz $(LIBGIT2_LIBS) $(WIN32_LIBS) -LDFLAGS_TEST = -lm -lstdc++ -lpthread -lz -fsanitize=address,undefined $(LIBGIT2_LIBS) $(WIN32_LIBS) +LDFLAGS_TEST = -lm -lstdc++ -lpthread -lz $(SANITIZE) $(LIBGIT2_LIBS) $(WIN32_LIBS) LDFLAGS_TSAN = -lm -lstdc++ -lpthread -lz -fsanitize=thread $(LIBGIT2_LIBS) $(WIN32_LIBS) # ── Source files ───────────────────────────────────────────────── @@ -195,7 +192,7 @@ UI_SRCS = \ MONGOOSE_SRC = vendored/mongoose/mongoose.c MONGOOSE_CFLAGS = -std=c11 -D_DEFAULT_SOURCE -O2 -w -Ivendored -DMG_ENABLE_LOG=0 MONGOOSE_CFLAGS_TEST = -std=c11 -D_DEFAULT_SOURCE -g -O1 -w -Ivendored -DMG_ENABLE_LOG=0 \ - -fsanitize=address,undefined -fno-omit-frame-pointer + $(SANITIZE) # mimalloc (vendored, global allocator override) MIMALLOC_SRC = vendored/mimalloc/src/static.c @@ -291,7 +288,7 @@ BUILD_DIR = build/c # Grammar + tree-sitter runtime: compiled without -Werror (upstream code has warnings) GRAMMAR_CFLAGS = -std=c11 -D_DEFAULT_SOURCE -O2 -w -I$(CBM_DIR) -I$(TS_INCLUDE) -I$(TS_SRC) GRAMMAR_CFLAGS_TEST = -std=c11 -D_DEFAULT_SOURCE -g -O1 -w -I$(CBM_DIR) -I$(TS_INCLUDE) -I$(TS_SRC) \ - -fsanitize=address,undefined -fno-omit-frame-pointer + $(SANITIZE) GRAMMAR_CFLAGS_TSAN = -std=c11 -D_DEFAULT_SOURCE -g -O1 -w -I$(CBM_DIR) -I$(TS_INCLUDE) -I$(TS_SRC) \ -fsanitize=thread -fno-omit-frame-pointer @@ -325,7 +322,7 @@ $(BUILD_DIR)/ts_runtime.o: $(CBM_DIR)/ts_runtime.c | $(BUILD_DIR) $(CC) $(GRAMMAR_CFLAGS_TEST) -c -o $@ $< $(BUILD_DIR)/lsp_all.o: $(CBM_DIR)/lsp_all.c | $(BUILD_DIR) - $(CC) $(GRAMMAR_CFLAGS_TEST) -fsanitize=address,undefined -fno-omit-frame-pointer -c -o $@ $< + $(CC) $(GRAMMAR_CFLAGS_TEST) $(SANITIZE) -c -o $@ $< $(BUILD_DIR)/preprocessor.o: $(CBM_DIR)/preprocessor.cpp | $(BUILD_DIR) $(CXX) $(CXXFLAGS_TEST) -w -I$(CBM_DIR)/vendored -c -o $@ $< @@ -357,7 +354,7 @@ SQLITE3_OBJ_TEST = $(BUILD_DIR)/sqlite3.o SQLITE3_OBJ_PROD = $(BUILD_DIR)/prod_sqlite3.o $(BUILD_DIR)/sqlite3.o: $(SQLITE3_SRC) | $(BUILD_DIR) - $(CC) $(SQLITE3_CFLAGS_TEST) -fsanitize=address,undefined -fno-omit-frame-pointer -c -o $@ $< + $(CC) $(SQLITE3_CFLAGS_TEST) $(SANITIZE) -c -o $@ $< $(BUILD_DIR)/prod_sqlite3.o: $(SQLITE3_SRC) | $(BUILD_DIR) $(CC) $(SQLITE3_CFLAGS) -c -o $@ $< diff --git a/scripts/test.sh b/scripts/test.sh index b35f7ea81..aa45811ea 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -38,10 +38,12 @@ done # shellcheck source=env.sh source "$ROOT/scripts/env.sh" -# Forward CC/CXX from args +# Forward CC/CXX and collect make-passthrough args (WIN32_LIBS=) +MAKE_ARGS="" for arg in "$@"; do case "$arg" in CC=*|CXX=*) export "${arg}" ;; + WIN32_LIBS=*) MAKE_ARGS="$MAKE_ARGS $arg" ;; --arch|--arch=*) ;; # already handled arm64|x86_64) ;; # already handled esac @@ -56,6 +58,6 @@ verify_compiler "$CC" scripts/clean.sh # Step 2 + 3: Build and run tests (with arch prefix on macOS) -$ARCH_PREFIX make -j"$NPROC" -f Makefile.cbm test +$ARCH_PREFIX make -j"$NPROC" -f Makefile.cbm test $MAKE_ARGS echo "=== All tests passed ==="