build: D1 cross-compile via cargo-zigbuild (4 non-macOS targets)

Replace the single-target musl cc with cargo-zigbuild + zig in the flake
devShell — one universal cross cc/linker (incl. rusqlite's bundled SQLite
C) for all four non-macOS D1 targets, added to rust-toolchain.toml:
  x86_64/aarch64-unknown-linux-musl              (static, D2)
  x86_64-pc-windows-gnu, aarch64-pc-windows-gnullvm  (standalone .exe)

Windows links -lsynchronization (std WaitOnAddress), which rust-overlay's
toolchain and zig's mingw don't ship; the symbols are forwarded by
kernel32, so an empty stub libsynchronization.a (ci/winstub/, wired via
.cargo/config.toml for the windows targets only) satisfies the linker.
Verified: all four build; linux static; windows valid PE32+.
This commit is contained in:
claude@clouddev1
2026-06-13 12:14:49 +00:00
parent 18d08642d7
commit 04ebd83f08
5 changed files with 71 additions and 23 deletions
+11 -17
View File
@@ -27,13 +27,6 @@
# from the crate metadata (no hand-maintained duplicate here).
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
# musl-targeting C compiler for the static release build: rusqlite's
# `bundled` SQLite is compiled from C, so a `--target …-musl` cargo build
# needs a musl `cc` for that C, plus a musl linker. `targetPrefix` is
# "x86_64-unknown-linux-musl-", so the wrapped binary is
# `${muslCC}/bin/x86_64-unknown-linux-musl-cc`.
muslCC = pkgs.pkgsCross.musl64.stdenv.cc;
# System build inputs are deliberately tiny — this is a pure-Rust TUI:
# * libsqlite3-sys is built with the `bundled` feature, so SQLite is
# compiled from vendored C. That needs a C compiler, which the
@@ -75,20 +68,21 @@
# CLAUDE.md "Build hygiene"). cargo-sweep prunes them; run it
# periodically between milestones.
pkgs.cargo-sweep
# musl cc/linker for the static release build (see muslCC above).
muslCC
# Cross-compilation for the D1 release matrix. `cargo zigbuild` uses
# Zig's bundled clang + libc as one universal cross cc/linker for
# every non-macOS target (Linux musl x64/arm64, Windows gnu/gnullvm
# x64/arm64) — including the `cc`-crate compile of rusqlite's bundled
# SQLite C — with no per-target toolchain or SDK. It auto-discovers
# `zig` on PATH, so no extra env is needed.
pkgs.cargo-zigbuild
pkgs.zig
];
# Point cargo's musl target at the musl cc for both the bundled-C
# compile (CC_<target>, consumed by the `cc` crate) and the final link
# (CARGO_TARGET_<TARGET>_LINKER). Harmless for normal glibc builds —
# these only take effect when building `--target x86_64-…-musl`.
shellHook = ''
export CC_x86_64_unknown_linux_musl="${muslCC}/bin/${muslCC.targetPrefix}cc"
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER="${muslCC}/bin/${muslCC.targetPrefix}cc"
echo "RDBMS Playground dev shell ($(uname -s))"
echo " rust: $(rustc --version | cut -d' ' -f1-2)"
echo " cargo: $(cargo --version | cut -d' ' -f1-2)"
echo " rust: $(rustc --version | cut -d' ' -f1-2)"
echo " cargo: $(cargo --version | cut -d' ' -f1-2)"
echo " zig: $(zig version 2>/dev/null || echo '?') (cargo-zigbuild cross targets)"
'';
};
});