Skip to content

Commit ec59f82

Browse files
committed
fix(nix): cross build static linux binaries
Use the musl cross package sets for the Linux static package instead of pkgsStatic. The CI build scripts need host executables while Cargo still targets the musl triples for the final binary, and pkgsStatic caused build-script links to mix static flags with dynamic glibc objects. Keep the rust-overlay toolchain target-specific so nix flake evaluation exposes the same ccusage-static package names while avoiding the failed static build-script link path seen in CI.
1 parent d602f90 commit ec59f82

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎flake.nix‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,20 @@
8181
});
8282
staticCcusage = pkgs.lib.optionalAttrs pkgs.stdenv.isLinux (
8383
let
84-
staticPkgs = pkgs.pkgsStatic;
84+
linuxStaticTarget =
85+
if system == "x86_64-linux"
86+
then "x86_64-unknown-linux-musl"
87+
else "aarch64-unknown-linux-musl";
88+
staticPkgs =
89+
if system == "x86_64-linux"
90+
then pkgs.pkgsCross.musl64
91+
else pkgs.pkgsCross.aarch64-multiplatform-musl;
8592
staticCraneLib = (crane.mkLib staticPkgs).overrideToolchain
86-
(p: p.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml);
93+
(p: (p.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override {
94+
targets = [ linuxStaticTarget ];
95+
});
8796
staticCommonArgs = commonArgs // {
97+
cargoExtraArgs = "-p ccusage --bin ccusage --target ${linuxStaticTarget}";
8898
nativeBuildInputs = with staticPkgs; [
8999
pkg-config
90100
];

0 commit comments

Comments
 (0)