From e46bcfda3fd6f7f99408034f01b29d800c9482c9 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sun, 10 Dec 2023 15:55:29 +0100 Subject: [PATCH] Windows pure shell build works --- default.nix | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/default.nix b/default.nix index fb81a59e..54865ba7 100644 --- a/default.nix +++ b/default.nix @@ -12,9 +12,10 @@ let newBuildTarget = { nixPkgsSystem, rustTarget ? nixPkgsSystem, - depsBuildBuild ? pkgsCross: [], + nativeBuildInputs ? pkgsCross: [], + rustFlags ? pkgsCross: [], }: { - inherit nixPkgsSystem rustTarget depsBuildBuild; + inherit nixPkgsSystem rustTarget nativeBuildInputs rustFlags; }; # centralize per-target configuration in a single place. @@ -40,10 +41,10 @@ let "x86_64-windows" = newBuildTarget { nixPkgsSystem = "x86_64-w64-mingw32"; rustTarget = "x86_64-pc-windows-gnu"; - #depsBuildBuild = pkgsCross: [ - # pkgsCross.stdenv.cc - # pkgsCross.windows.pthreads - #]; + nativeBuildInputs = pkgsCross: [ pkgsCross.windows.pthreads ]; + rustFlags = pkgsCross: [ + "-C" "link-arg=-L${pkgsCross.windows.pthreads}/lib" + ]; }; }; @@ -143,11 +144,13 @@ let ''; buildEnv = rec { - nativeBuildInputs = (buildTarget.depsBuildBuild pkgsCross) ++ [ + nativeBuildInputs = (buildTarget.nativeBuildInputs pkgsCross) ++ [ toolchain pkgs.protobuf - #pkgsCross.stdenv.cc - #pkgsCross.windows.pthreads + + # Required for shell because of rust dependency build scripts which must + # run on the build system. + pkgs.stdenv.cc ]; SODIUM_LIB_DIR = "${libsodium}/lib"; @@ -159,11 +162,11 @@ let CARGO_BUILD_TARGET = rustTarget; CARGO_BUILD_RUSTFLAGS = [ "-C" "target-feature=+crt-static" - "-C" "link-args=-static" + "-C" "link-arg=-static" # https://github.com/rust-lang/cargo/issues/4133 "-C" "linker=${TARGET_CC}" - ]; + ] ++ (buildTarget.rustFlags pkgsCross); }; in { @@ -182,7 +185,7 @@ in { ]; } // buildEnv); - shell = pkgs.mkShell buildEnv; + shell = pkgsCross.mkShell buildEnv; # TODO #clippy = {