From 89635b1d8cd0a643a41df314a2a2c2799993d1f3 Mon Sep 17 00:00:00 2001 From: Jeremie Fraeys Date: Wed, 4 Mar 2026 20:25:31 -0500 Subject: [PATCH] build(cli): update build configuration Update build system for new modules: - Makefile: add build targets for new components - build.zig: include new source files in build graph Supports new CLI architecture. --- cli/Makefile | 53 ++++++++++++++++++++++++++++++++++++++++++--------- cli/build.zig | 31 +++++++++++++++++------------- 2 files changed, 62 insertions(+), 22 deletions(-) diff --git a/cli/Makefile b/cli/Makefile index 080faa0..0a07bef 100644 --- a/cli/Makefile +++ b/cli/Makefile @@ -35,6 +35,39 @@ endif prod: $(PROD_DEPS) | $(BUILD_DIR) $(ZIG) build --release=fast +# Release builds for all platforms +# Note: build.zig now auto-names cross-compiled binaries with os_arch prefix +release-all: build-sqlite + @echo "Building for all platforms..." + @# Linux x86_64 (static musl) - outputs ml-linux-x86_64 + $(ZIG) build -Dtarget=x86_64-linux-musl --release=fast + @# Linux arm64 (static musl) - outputs ml-linux-arm64 + $(ZIG) build -Dtarget=aarch64-linux-musl --release=fast + @# macOS x86_64 - outputs ml-darwin-x86_64 + $(ZIG) build -Dtarget=x86_64-macos --release=fast + @# macOS arm64 - outputs ml-darwin-arm64 + $(ZIG) build -Dtarget=aarch64-macos --release=fast + @# Windows x86_64 - outputs ml-windows-x86_64.exe + $(ZIG) build -Dtarget=x86_64-windows --release=fast + @echo "All builds complete. Binaries in zig-out/bin/" + @ls -lh zig-out/bin/ml-* + +# Verify binaries have no external dependencies (Linux/macOS) +check-static: + @echo "Checking binary dependencies..." + @if command -v ldd >/dev/null 2>&1; then \ + for f in zig-out/bin/ml-linux*; do \ + echo "Checking $$f..."; \ + ldd $$f 2>&1 | grep -q "not a dynamic" && echo " ✓ Static binary" || echo " ✗ Has dependencies"; \ + done; \ + fi + @if command -v otool >/dev/null 2>&1; then \ + for f in zig-out/bin/ml-darwin*; do \ + echo "Checking $$f..."; \ + otool -L $$f 2>&1 | head -2; \ + done; \ + fi + # Tiny build: smallest binary with ReleaseSmall # Note: Requires SQLite amalgamation .PHONY: tiny @@ -75,13 +108,15 @@ clean: help: @echo "Targets:" - @echo " prod - build production binary with ReleaseFast + LTO (best performance)" - @echo " tiny - build minimal binary with ReleaseSmall (smallest size)" - @echo " dev - build development binary with ReleaseFast (quick builds)" - @echo " debug - build debug binary with no optimizations (fastest compile)" - @echo " all - build release-small binary (legacy, same as 'tiny')" - @echo " test - run Zig unit tests" - @echo " build-rsync - build pinned rsync from official source into src/assets" + @echo " prod - build production binary with ReleaseFast (best performance)" + @echo " release-all - build binaries for all platforms (Linux, macOS, Windows)" + @echo " check-static - verify binaries have no external dependencies" + @echo " tiny - build minimal binary with ReleaseSmall (smallest size)" + @echo " dev - build development binary with ReleaseFast (quick builds)" + @echo " debug - build debug binary with no optimizations (fastest compile)" + @echo " all - build release-small binary (legacy, same as 'tiny')" + @echo " test - run Zig unit tests" + @echo " build-rsync - build pinned rsync from official source into src/assets" @echo " build-sqlite - fetch SQLite amalgamation into src/assets" - @echo " install - copy binary into /usr/local/bin" - @echo " clean - remove build artifacts" \ No newline at end of file + @echo " install - copy binary into /usr/local/bin" + @echo " clean - remove build artifacts" \ No newline at end of file diff --git a/cli/build.zig b/cli/build.zig index ad62770..6673f1e 100644 --- a/cli/build.zig +++ b/cli/build.zig @@ -109,19 +109,13 @@ pub fn build(b: *std.Build) void { // LTO disabled: requires LLD linker which may not be available // exe.want_lto = true; - // Link native dataset_hash library (only when not cross-compiling) + // Native libraries: PURE ZIG IMPLEMENTATION (zero-dependency) + // C++ native libs removed - hash.zig implements same algorithms in Zig exe.linkLibC(); - if (!is_cross_compiling) { - exe.addLibraryPath(b.path("../native/build")); - exe.linkSystemLibrary("dataset_hash"); - exe.addIncludePath(b.path("../native/dataset_hash")); - } else { - // Cross-compiling: dev-only, native library not available - std.log.warn("Cross-compiling (dev-only): native libraries disabled", .{}); - } + // Note: dataset_hash C++ lib removed - use utils/hash.zig instead - // SQLite setup: embedded for ReleaseSmall only, system lib for dev - const use_embedded_sqlite = has_sqlite_release and (optimize == .ReleaseSmall); + // SQLite setup: ALWAYS embedded (zero-dependency requirement) + const use_embedded_sqlite = has_sqlite_release; // Remove optimize check - always embed if (use_embedded_sqlite) { // Release: compile SQLite from downloaded amalgamation const sqlite_c_path = b.fmt("{s}/sqlite3.c", .{sqlite_release_path}); @@ -148,8 +142,19 @@ pub fn build(b: *std.Build) void { exe.addCSourceFile(.{ .file = b.path("src/assets/sqlite/sqlite_constants.c"), .flags = &.{ "-Wall", "-Wextra" } }); } - // Install the executable to zig-out/bin - b.installArtifact(exe); + // Install the executable to zig-out/bin with platform-specific name for cross-compilation + const install_step = b.addInstallArtifact(exe, .{}); + + // For cross-compilation, rename binary to include os_arch prefix + if (is_cross_compiling) { + const target_name = b.fmt("ml-{s}-{s}", .{ os_str, arch_str }); + install_step.dest_sub_path = target_name; + if (os_tag == .windows) { + install_step.dest_sub_path = b.fmt("{s}.exe", .{target_name}); + } + } + + b.getInstallStep().dependOn(&install_step.step); // Default build: install optimized CLI (used by `zig build`) const prod_step = b.step("prod", "Build production CLI binary");