Fix windows build, add release target

This commit is contained in:
Brian Picciano 2024-01-09 11:17:52 +01:00
parent c65a201222
commit 7e5aeb5f28

View File

@ -38,7 +38,13 @@
"x86_64-windows" = newBuildTarget { "x86_64-windows" = newBuildTarget {
nixPkgsSystem = "x86_64-w64-mingw32"; nixPkgsSystem = "x86_64-w64-mingw32";
rustTarget = "x86_64-pc-windows-gnu"; rustTarget = "x86_64-pc-windows-gnu";
nativeBuildInputs = pkgsCross: [ pkgsCross.windows.pthreads ]; nativeBuildInputs = pkgsCross: [
pkgsCross.stdenv.cc
pkgsCross.windows.pthreads
];
rustFlags = pkgsCross: [
"-C" "link-arg=-L${pkgsCross.windows.pthreads}/lib"
];
}; };
}; };
@ -62,12 +68,29 @@
# "$system.cross-$system" for every system. # "$system.cross-$system" for every system.
# #
eachCrossSystem = supportedSystems: callback: eachCrossSystem = supportedSystems: callback:
eachSystem supportedSystems (buildSystem: builtins.foldl' eachSystem supportedSystems (buildSystem: let
pkgs = mkPkgs buildSystem null;
crosses = builtins.foldl'
(inner: targetSystem: inner // { (inner: targetSystem: inner // {
"cross-${targetSystem}" = callback buildSystem targetSystem; "cross-${targetSystem}" = callback buildSystem targetSystem;
}) })
{ default = callback buildSystem buildSystem; } { default = callback buildSystem buildSystem; }
supportedSystems supportedSystems;
in
crosses // (rec {
default = callback buildSystem buildSystem;
release = let
bins = pkgs.symlinkJoin {
name = "${default.name}-all-bins";
paths = builtins.attrValues crosses;
};
in
pkgs.runCommand "${default.name}-release" {} ''
cp -rL "${bins}" "$out"
chmod +w "$out"/bin
(cd "$out"/bin && sha256sum * > sha256.txt)
'';
})
); );
mkPkgs = buildSystem: targetSystem: import nixpkgs ({ mkPkgs = buildSystem: targetSystem: import nixpkgs ({
@ -82,20 +105,9 @@
})); }));
mkToolchain = buildSystem: targetSystem: let mkToolchain = buildSystem: targetSystem: let
debug = v: builtins.trace v v;
buildTarget = buildTargets.${targetSystem}; buildTarget = buildTargets.${targetSystem};
rustTarget = buildTarget.rustTarget; rustTarget = buildTarget.rustTarget;
#fenixPkgs = fenix.packages.${buildSystem}; fenixPkgs = fenix.packages.${buildSystem};
# TODO prefer to use the nix flake fenix
fenixPkgs = import ((mkPkgs buildSystem null).fetchFromGitHub {
owner = "nix-community";
repo = "fenix";
rev = "81ab0b4f7ae9ebb57daa0edf119c4891806e4d3a";
hash = "sha256-bZmI7ytPAYLpyFNgj5xirDkKuAniOkj1xHdv5aIJ5GM=";
}) {
system = buildSystem;
};
# TODO I'd prefer to use the toolchain file # TODO I'd prefer to use the toolchain file
# https://github.com/nix-community/fenix/issues/123 # https://github.com/nix-community/fenix/issues/123
@ -145,7 +157,7 @@
# https://github.com/rust-lang/cargo/issues/4133 # https://github.com/rust-lang/cargo/issues/4133
"-C" "linker=${TARGET_CC}" "-C" "linker=${TARGET_CC}"
]; ] ++ (buildTarget.rustFlags pkgsCross);
}; };
in { in {
@ -165,6 +177,17 @@
strictDeps = true; strictDeps = true;
doCheck = false; doCheck = false;
release = true; release = true;
postInstall = ''
cd "$out"/bin
for f in "$(ls)"; do
if ext="$(echo "$f" | grep -oP '\.[a-z]+$')"; then
base="$(echo "$f" | cut -d. -f1)"
mv "$f" "$base-${targetSystem}$ext"
else
mv "$f" "$f-${targetSystem}"
fi
done
'';
} // (buildEnv buildSystem targetSystem)) } // (buildEnv buildSystem targetSystem))
); );