refactor(makefile): reorganize native library targets for C++ and Rust separation

Separate C++ and Rust native library targets in the Makefile:

- Rename native/rust/ references to native_rust/ for new workspace location

- Split 'Native Libraries' help section into C++ and Rust categories

- Rename prod-with-native -> prod-with-rust, detect-regressions-native -> detect-regressions-rust

- Add rust-debug target, remove native-release (redundant)

- Add compare-benchmarks target for Rust/Go/C++ performance comparison

- Update all rust-* targets with proper cargo availability checks

- Add cargo existence checks to prevent errors when Rust not installed
This commit is contained in:
Jeremie Fraeys 2026-03-23 15:17:43 -04:00
parent e67d18900e
commit 1d7be5c829
No known key found for this signature in database

143
Makefile
View file

@ -97,62 +97,68 @@ dev:
@cp cli/zig-out/bin/ml-* bin/cli/ml-$$(uname -s | tr '[:upper:]' '[:lower:]')-$$(uname -m | sed 's/x86_64/amd64/')
@echo "$(OK) Development binaries built"
# Native Libraries (C++)
native-build:
@cd native/rust && cargo build --release
@echo "$(OK) Rust native libraries built"
native-release:
@cd native/rust && cargo build --release
@mkdir -p bin/native
@cp native/rust/target/release/libqueue_index.so native/rust/target/release/libdataset_hash.so bin/native/ 2>/dev/null || true
@cp native/rust/target/release/libqueue_index.dylib native/rust/target/release/libdataset_hash.dylib bin/native/ 2>/dev/null || true
@echo "$(OK) Rust native libraries built (release)"
native-debug:
@cd native/rust && cargo build
@echo "$(OK) Rust native libraries built (debug)"
@command -v cmake >/dev/null 2>&1 || { echo "Error: cmake not found. Install: brew install cmake"; exit 1; }
@mkdir -p native/build && cd native/build && cmake .. -DCMAKE_BUILD_TYPE=Release && make -j$(shell nproc 2>/dev/null || echo 4)
@echo "$(OK) C++ native libraries built"
native-test:
@cd native/rust && cargo test
@echo "$(OK) Rust native tests passed"
native-smoke:
@bash ./scripts/dev/smoke-test.sh --native
@echo "$(OK) Native smoke test passed"
@command -v cmake >/dev/null 2>&1 || { echo "Error: cmake not found. Install: brew install cmake"; exit 1; }
@mkdir -p native/build && cd native/build && cmake .. -DCMAKE_BUILD_TYPE=Release && make -j$(shell nproc 2>/dev/null || echo 4)
@cd native/build && ctest --output-on-failure
@echo "$(OK) C++ native tests passed"
native-clean:
@cd native/rust && cargo clean
@rm -rf native/build
@echo "$(OK) Native build cleaned"
@rm -rf native/build/
@echo "$(OK) C++ native build cleaned"
# Rust-specific targets
# Rust Libraries
rust-build:
@cd native/rust && cargo build --release
@echo "$(OK) Rust libraries built"
@command -v cargo >/dev/null 2>&1 || { echo "Error: cargo not found. Install Rust: brew install rust"; exit 1; }
@cd native_rust && cargo build --release
@mkdir -p bin/native
@cp native_rust/target/release/libqueue_index.so native_rust/target/release/libdataset_hash.so bin/native/ 2>/dev/null || true
@cp native_rust/target/release/libqueue_index.dylib native_rust/target/release/libdataset_hash.dylib bin/native/ 2>/dev/null || true
@echo "$(OK) Rust native libraries built (release)"
rust-debug:
@command -v cargo >/dev/null 2>&1 || { echo "Error: cargo not found. Install Rust: brew install rust"; exit 1; }
@cd native_rust && cargo build
@echo "$(OK) Rust native libraries built (debug)"
rust-test:
@cd native/rust && cargo test
@echo "$(OK) Rust tests passed"
@command -v cargo >/dev/null 2>&1 || { echo "Error: cargo not found. Install Rust: brew install rust"; exit 1; }
@cd native_rust && cargo test
@echo "$(OK) Rust native tests passed"
rust-smoke:
@bash ./scripts/dev/smoke-test.sh --native
@echo "$(OK) Rust smoke test passed"
rust-clean:
@cd native/rust && cargo clean
@command -v cargo >/dev/null 2>&1 || { exit 0; }
@cd native_rust && cargo clean
@rm -rf native/build
@echo "$(OK) Rust build cleaned"
rust-check:
@cd native/rust && cargo clippy -- -D warnings
@command -v cargo >/dev/null 2>&1 || { echo "Error: cargo not found. Install Rust: brew install rust"; exit 1; }
@cd native_rust && cargo clippy -- -D warnings
@echo "$(OK) Rust clippy passed"
rust-fmt:
@cd native/rust && cargo fmt --check
@command -v cargo >/dev/null 2>&1 || { echo "Error: cargo not found. Install Rust: brew install rust"; exit 1; }
@cd native_rust && cargo fmt --check
@echo "$(OK) Rust fmt check passed"
prod-with-native: native-release
prod-with-rust: rust-build
@mkdir -p bin/server bin/native
@cp native/rust/target/release/lib*.so bin/native/ 2>/dev/null || true
@cp native/rust/target/release/lib*.dylib bin/native/ 2>/dev/null || true
@cp native_rust/target/release/lib*.so bin/native/ 2>/dev/null || true
@cp native_rust/target/release/lib*.dylib bin/native/ 2>/dev/null || true
go build -ldflags="$(LDFLAGS_PROD)" -o bin/server/api-server ./cmd/api-server/main.go
go build -ldflags="$(LDFLAGS_PROD)" -o bin/server/worker ./cmd/worker/worker_server.go
@echo "$(OK) Production binaries built (with native libs)"
@echo "$(OK) Production binaries built (with Rust libs)"
cross-platform:
@rm -rf dist && mkdir -p dist
@ -232,7 +238,7 @@ test-coverage:
@echo "$(OK) Coverage report: coverage/coverage.html"
@go tool cover -func=coverage/coverage.out | tail -1
consistency-test: build native-build
consistency-test: build rust-build
@echo "Running cross-implementation consistency tests..."
@go test -v ./tests/integration/consistency/... 2>&1 | tee /tmp/consistency-test.txt || true
@echo "\n=== Consistency Test Summary ==="
@ -303,7 +309,7 @@ clean:
clean-release: clean
rm -rf native/build/
cd native/rust && cargo clean
cd native_rust && cargo clean
go clean -cache -testcache
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -name "*.pyc" -delete 2>/dev/null || true
@ -574,20 +580,41 @@ detect-regressions: profile-tools
-current tests/bin/current.bench.txt \
-threshold 10.0
detect-regressions-native: native-build profile-tools
detect-regressions-rust: rust-build profile-tools
@mkdir -p tests/bin
@if [ ! -f tests/bin/baseline-native.bench.txt ]; then \
echo "Creating native baseline..."; \
go test -bench=. -benchmem -tags native_libs ./tests/benchmarks/... \
| tee tests/bin/baseline-native.bench.txt; \
@if [ ! -f tests/bin/baseline-rust.bench.txt ]; then \
echo "Creating Rust baseline..."; \
cd native_rust && cargo bench 2>&1 | tee ../tests/bin/baseline-rust.bench.txt; \
fi
go test -bench=. -benchmem -tags native_libs ./tests/benchmarks/... \
| tee tests/bin/current-native.bench.txt
cd native_rust && cargo bench 2>&1 | tee ../tests/bin/current-rust.bench.txt
./bin/tools/performance-regression-detector \
-baseline tests/bin/baseline-native.bench.txt \
-current tests/bin/current-native.bench.txt \
-baseline tests/bin/baseline-rust.bench.txt \
-current tests/bin/current-rust.bench.txt \
-threshold 10.0
# Compare Rust vs Go vs C++ benchmarks
compare-benchmarks: rust-build
@echo "=========================================="
@echo " Native Library Performance Comparison"
@echo "=========================================="
@echo ""
@echo "--- Rust (BLAKE3/queue_index) ---"
@cd native_rust && cargo bench 2>&1 | grep -E '(test result|bench:|time:)' | head -20 || true
@echo ""
@echo "--- Go (reference implementation) ---"
@go test -bench=. -benchmem ./tests/benchmarks/... 2>&1 | grep -E '(Benchmark|ns/op|allocs/op)' | head -15 || true
@echo ""
@echo "--- C++ (native libs) ---"
@if [ -f native/build/test/queue_index_bench ]; then \
./native/build/test/queue_index_bench 2>&1 | head -10 || true; \
else \
echo "C++ benchmarks not built (run: make native-build)"; \
fi
@echo ""
@echo "=========================================="
@echo "Benchmark comparison complete"
@echo "=========================================="
clean-benchmarks:
@./scripts/maintenance/cleanup-benchmarks.sh benchmarks
@ -747,7 +774,7 @@ help:
@printf "Build\n"
@printf " build Build all components (default)\n"
@printf " prod Production-optimized binaries\n"
@printf " prod-with-native Production binaries + native Rust libs\n"
@printf " prod-with-rust Production binaries + Rust libs\n"
@printf " dev Fast development build\n"
@printf " cross-platform Linux x86_64 static binaries in dist/\n"
@printf " build-cli Build Zig CLI only\n"
@ -756,19 +783,23 @@ help:
@printf " prepare-release clean-release + release verification\n"
@printf " verify-build Check build reproducibility\n"
@printf "\n"
@printf "Native Libraries\n"
@printf " native-build Build Rust libs (release)\n"
@printf " native-release Build Rust libs + copy to bin/native\n"
@printf " native-debug Build Rust libs (debug)\n"
@printf " native-test Run Rust unit tests\n"
@printf " native-smoke Run smoke tests\n"
@printf " native-clean Clean Rust build artifacts\n"
@printf " rust-build Alias for native-build\n"
@printf " rust-test Run Rust tests only\n"
@printf " rust-clean Clean Rust build\n"
@printf "Native Libraries (C++)\n"
@printf " native-build Build C++ native libs (cmake)\n"
@printf " native-test Run C++ native tests (ctest)\n"
@printf " native-clean Clean C++ build artifacts\n"
@printf "\n"
@printf "Rust Libraries\n"
@printf " rust-build Build Rust libs (cargo release)\n"
@printf " rust-debug Build Rust libs (cargo debug)\n"
@printf " rust-test Run Rust tests\n"
@printf " rust-smoke Run Rust smoke tests\n"
@printf " rust-clean Clean Rust build artifacts\n"
@printf " rust-check Run clippy lints\n"
@printf " rust-fmt Check Rust formatting\n"
@printf "\n"
@printf "Production\n"
@printf " prod-with-rust Production binaries + Rust libs\n"
@printf "\n"
@printf "Tests\n"
@printf " test All tests with infrastructure (CI default)\n"
@printf " test-unit Fast unit tests, no infrastructure\n"