Skip to content

Commit c8bdf92

Browse files
committed
Fix production build errors, add build step to Docker test infra
- Fix GCC -O2 warnings: calloc for cf (maybe-uninitialized), suppress stringop-truncation/alloc-size-larger-than (false positives), guard louvain against negative node_count - Default compiler: cc on macOS, gcc on Linux/Windows (fixes gcc-14 not found on MSYS2) - Docker test infra now runs BOTH test (ASan) and build (-O2 -Werror)
1 parent 9b22c11 commit c8bdf92

8 files changed

Lines changed: 77 additions & 29 deletions

File tree

Makefile.cbm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ endif
4141
IS_GCC := $(shell echo | $(CC) -dM -E - 2>/dev/null | grep -q '__GNUC__' && ! echo | $(CC) -dM -E - 2>/dev/null | grep -q '__clang__' && echo yes || echo no)
4242
GCC_ONLY_FLAGS :=
4343
ifeq ($(IS_GCC),yes)
44-
GCC_ONLY_FLAGS := -Wno-format-truncation -Wno-unused-result
44+
GCC_ONLY_FLAGS := -Wno-format-truncation -Wno-unused-result \
45+
-Wno-stringop-truncation -Wno-alloc-size-larger-than
4546
endif
4647

4748
CFLAGS_COMMON = -std=c11 -D_DEFAULT_SOURCE -Wall -Wextra -Werror \

scripts/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ print_env "build.sh"
8282
echo " ui=$WITH_UI version=${VERSION:-dev}"
8383

8484
# Verify compiler supports target arch
85-
verify_compiler "${CC:-gcc-14}"
85+
verify_compiler "$CC"
8686

8787
# Step 1: Clean C build artifacts only (not node_modules — npm ci handles that)
8888
rm -rf "$ROOT/build/c"

scripts/env.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ verify_compiler() {
7474
fi
7575
}
7676

77+
# ── Default compiler selection ─────────────────────────────────
78+
# macOS: cc (Apple Clang). Linux/Windows: gcc (system default).
79+
# CI overrides via CC=gcc CXX=g++ args. Local macOS overrides via CC=cc.
80+
if [[ -z "${CC:-}" ]]; then
81+
if [[ "$OS" == "darwin" ]]; then
82+
export CC=cc CXX=c++
83+
else
84+
export CC=gcc CXX=g++
85+
fi
86+
fi
87+
7788
# ── Print environment summary ──────────────────────────────────
7889
print_env() {
7990
local context="$1"

scripts/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ done
5050
print_env "test.sh"
5151

5252
# Verify compiler supports target arch
53-
verify_compiler "${CC:-gcc-14}"
53+
verify_compiler "$CC"
5454

5555
# Step 1: Clean
5656
scripts/clean.sh

src/pipeline/pass_githistory.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,14 @@ int cbm_pipeline_githistory_compute(const char *repo_path, cbm_githistory_result
430430
result->commit_count = commit_count;
431431

432432
/* Convert to testable format */
433-
cbm_commit_files_t *cf = malloc((size_t)commit_count * sizeof(cbm_commit_files_t));
433+
cbm_commit_files_t *cf = calloc((size_t)commit_count, sizeof(cbm_commit_files_t));
434+
if (!cf) {
435+
for (int c = 0; c < commit_count; c++) {
436+
commit_free(&commits[c]);
437+
}
438+
free(commits);
439+
return 0;
440+
}
434441
for (int c = 0; c < commit_count; c++) {
435442
cf[c].files = commits[c].files;
436443
cf[c].count = commits[c].count;

src/store/store.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3431,7 +3431,7 @@ static int arch_file_tree(cbm_store_t *s, const char *project, cbm_architecture_
34313431

34323432
int cbm_louvain(const int64_t *nodes, int node_count, const cbm_louvain_edge_t *edges,
34333433
int edge_count, cbm_louvain_result_t **out, int *out_count) {
3434-
if (node_count == 0) {
3434+
if (node_count <= 0) {
34353435
*out = NULL;
34363436
*out_count = 0;
34373437
return CBM_STORE_OK;

test-infrastructure/docker-compose.yml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66
# macOS: not possible in Docker — test natively: scripts/test.sh CC=cc
77
# Windows: not possible in Docker on Mac — CI only
88
#
9-
# Usage:
10-
# ./test-infrastructure/run.sh # test arm64 (native, fast)
11-
# ./test-infrastructure/run.sh all # test arm64 + amd64 in parallel
12-
# ./test-infrastructure/run.sh amd64 # test amd64 only (QEMU, slower)
13-
# ./test-infrastructure/run.sh lint # lint only
9+
# Each platform runs BOTH test (ASan/LeakSan) AND production build (-O2 -Werror).
1410

1511
services:
12+
# ── Test builds (ASan + UBSan + LeakSanitizer) ──────────────
1613
test:
1714
build:
1815
context: ..
@@ -31,6 +28,28 @@ services:
3128
- ..:/src
3229
command: ["CC=gcc", "CXX=g++"]
3330

31+
# ── Production builds (-O2 -Werror, catches stricter GCC warnings) ──
32+
build:
33+
build:
34+
context: ..
35+
dockerfile: test-infrastructure/Dockerfile
36+
platform: linux/arm64
37+
volumes:
38+
- ..:/src
39+
entrypoint: ["scripts/build.sh"]
40+
command: ["CC=gcc", "CXX=g++"]
41+
42+
build-amd64:
43+
build:
44+
context: ..
45+
dockerfile: test-infrastructure/Dockerfile
46+
platform: linux/amd64
47+
volumes:
48+
- ..:/src
49+
entrypoint: ["scripts/build.sh"]
50+
command: ["CC=gcc", "CXX=g++"]
51+
52+
# ── Lint ────────────────────────────────────────────────────
3453
lint:
3554
build:
3655
context: ..

test-infrastructure/run.sh

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Local CI testing — GCC + ASan + LeakSanitizer in Docker.
2+
# Local CI testing — mirrors GitHub Actions for all Docker-capable platforms.
33
#
44
# Coverage:
55
# arm64: Native on Apple Silicon (fast, ~3 min)
@@ -8,34 +8,48 @@
88
# Windows: CI only (no Docker support on Mac)
99
#
1010
# Usage:
11-
# ./test-infrastructure/run.sh # arm64 test (default, fast)
12-
# ./test-infrastructure/run.sh all # arm64 + amd64 in parallel
13-
# ./test-infrastructure/run.sh amd64 # amd64 only
11+
# ./test-infrastructure/run.sh # test + build arm64 (default)
12+
# ./test-infrastructure/run.sh all # test + build, arm64 + amd64
13+
# ./test-infrastructure/run.sh test # test only (ASan + LeakSan)
14+
# ./test-infrastructure/run.sh build # production build only (-O2 -Werror)
15+
# ./test-infrastructure/run.sh amd64 # test + build amd64 only
1416
# ./test-infrastructure/run.sh lint # clang-format + cppcheck
1517
# ./test-infrastructure/run.sh shell # debug shell (arm64)
16-
# ./test-infrastructure/run.sh shell-amd64 # debug shell (amd64)
1718

1819
set -euo pipefail
1920

2021
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
2122
COMPOSE="docker compose -f $ROOT/test-infrastructure/docker-compose.yml"
2223

23-
case "${1:-test}" in
24-
test|arm64)
25-
echo "=== Linux arm64 (GCC + ASan + LeakSanitizer) ==="
24+
case "${1:-full}" in
25+
full)
26+
echo "=== Linux arm64: test (ASan+LeakSan) + production build (-O2) ==="
2627
$COMPOSE run --rm test
28+
$COMPOSE run --rm build
29+
;;
30+
test)
31+
echo "=== Linux arm64: test (ASan + LeakSanitizer) ==="
32+
$COMPOSE run --rm test
33+
;;
34+
build)
35+
echo "=== Linux arm64: production build (-O2 -Werror) ==="
36+
$COMPOSE run --rm build
2737
;;
2838
amd64)
29-
echo "=== Linux amd64 via QEMU (GCC + ASan + LeakSanitizer) ==="
39+
echo "=== Linux amd64 via QEMU: test + build ==="
3040
$COMPOSE run --rm test-amd64
41+
$COMPOSE run --rm build-amd64
3142
;;
3243
all)
33-
echo "=== Testing arm64 + amd64 in parallel ==="
34-
$COMPOSE run --rm -d test
44+
echo "=== All platforms: test + build ==="
45+
echo "--- arm64 test ---"
46+
$COMPOSE run --rm test
47+
echo "--- arm64 build ---"
48+
$COMPOSE run --rm build
49+
echo "--- amd64 test ---"
3550
$COMPOSE run --rm test-amd64
36-
echo "=== Waiting for arm64... ==="
37-
# docker compose run -d returns immediately; wait for the container
38-
$COMPOSE wait test 2>/dev/null || true
51+
echo "--- amd64 build ---"
52+
$COMPOSE run --rm build-amd64
3953
echo "=== All platforms passed ==="
4054
;;
4155
lint)
@@ -46,12 +60,8 @@ case "${1:-test}" in
4660
echo "=== Debug shell (Linux arm64) ==="
4761
$COMPOSE run --rm --entrypoint bash test
4862
;;
49-
shell-amd64)
50-
echo "=== Debug shell (Linux amd64 via QEMU) ==="
51-
$COMPOSE run --rm --entrypoint bash test-amd64
52-
;;
5363
*)
54-
echo "Usage: $0 {test|arm64|amd64|all|lint|shell|shell-amd64}"
64+
echo "Usage: $0 {full|test|build|amd64|all|lint|shell}"
5565
exit 1
5666
;;
5767
esac

0 commit comments

Comments
 (0)