From b84a60ba693c3a8c7dd203399235c55001093e1e Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Tue, 5 Dec 2023 15:05:10 +0100 Subject: [PATCH] Fixed libsodium issue for windows build --- default.nix | 51 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/default.nix b/default.nix index 40a01ee4..64d85795 100644 --- a/default.nix +++ b/default.nix @@ -128,29 +128,32 @@ let ) ); -in { + # For some reason the pkgsCross.pkgsStatic build of libsodium doesn't contain + # a `.a` file when compiled to a windows target, but rather contains + # a `.dll.a` file which libsodium-sys doesn't pick up on. Copying the one to + # the be the other seems to work. + libsodium = pkgs.runCommand "libsodium-wrapped" { + libsodium = pkgsCross.pkgsStatic.libsodium; + } '' + cp -rL "$libsodium" "$out" + chmod -R +w "$out" + if [ ! -e "$out"/lib/libsodium.a ] && [ -f "$out"/lib/libsodium.dll.a ]; then + cp "$out"/lib/libsodium.dll.a "$out"/lib/libsodium.a + fi + ''; - inherit pkgs; - - release = naersk.buildPackage rec { - inherit release; - - src = ./.; - strictDeps = true; - doCheck = false; - - depsBuildBuild = (buildTarget.depsBuildBuild pkgsCross) ++ [ + buildEnv = rec { + nativeBuildInputs = (buildTarget.depsBuildBuild pkgsCross) ++ [ + toolchain pkgs.protobuf ]; - cargoBuildOptions = prev: prev++[ - "--features=${builtins.concatStringsSep "," builtFeatures}" - ]; - OPENSSL_STATIC = "1"; OPENSSL_LIB_DIR = "${pkgsCross.pkgsStatic.openssl.out}/lib"; OPENSSL_INCLUDE_DIR = "${pkgsCross.pkgsStatic.openssl.dev}/include"; + SODIUM_LIB_DIR = "${libsodium}/lib"; + # Required because ring crate is special. This also seems to have # fixed some issues with the x86_64-windows cross-compile :shrug: TARGET_CC = "${pkgsCross.stdenv.cc}/bin/${pkgsCross.stdenv.cc.targetPrefix}cc"; @@ -168,6 +171,24 @@ in { ]; }; +in { + + inherit pkgs pkgsCross; + + release = naersk.buildPackage (rec { + inherit release; + + src = ./.; + strictDeps = true; + doCheck = false; + + cargoBuildOptions = prev: prev++[ + "--features=${builtins.concatStringsSep "," builtFeatures}" + ]; + } // buildEnv); + + shell = pkgsCross.mkShell buildEnv; + # TODO #clippy = { # amd64 = (compile {