From 39cc140d1b7ad96ba03a6db1997b96040bd67dd6 Mon Sep 17 00:00:00 2001 From: Yureka Date: Fri, 28 Oct 2022 19:03:09 +0200 Subject: [PATCH 1/8] cargo-c: 0.9.2 -> 0.9.13 --- pkgs/development/tools/rust/cargo-c/default.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/development/tools/rust/cargo-c/default.nix b/pkgs/development/tools/rust/cargo-c/default.nix index 0b82c1b5a3665..e478f909a2437 100644 --- a/pkgs/development/tools/rust/cargo-c/default.nix +++ b/pkgs/development/tools/rust/cargo-c/default.nix @@ -12,16 +12,16 @@ rustPlatform.buildRustPackage rec { pname = "cargo-c"; - version = "0.9.2"; + version = "0.9.13"; src = fetchCrate { inherit pname; # this version may need to be updated along with package version - version = "${version}+cargo-0.55"; - sha256 = "sha256-yh5vAtKlBvoSlJBsW2RSduSK6T8aOssM84WQMNjLZqA="; + version = "${version}+cargo-0.65"; + sha256 = "sha256-f/p+ZIvDe9JQ8GM82SEud7sRTlimNs/ADPevfdkhsfg="; }; - cargoSha256 = "sha256-YikTjAeroaHyNe3ygUWRHSXJwdm2BSBV7RgIDN4suZ4="; + cargoSha256 = "sha256-JrlEWgKbTqQG/JYFqBR53eB58fa29c/+vIdSNGoS5Y0="; nativeBuildInputs = [ pkg-config (lib.getDev curl) ]; buildInputs = [ openssl curl ] ++ lib.optionals stdenv.isDarwin [ From e802126765398157fbe0215d83e140ecadb57279 Mon Sep 17 00:00:00 2001 From: Yureka Date: Fri, 28 Oct 2022 19:05:15 +0200 Subject: [PATCH 2/8] cargoSetupHook: set crt-static flag for host and build platforms separately --- pkgs/build-support/rust/hooks/default.nix | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkgs/build-support/rust/hooks/default.nix b/pkgs/build-support/rust/hooks/default.nix index 652b074c30206..2f905d4a8534c 100644 --- a/pkgs/build-support/rust/hooks/default.nix +++ b/pkgs/build-support/rust/hooks/default.nix @@ -70,13 +70,17 @@ in { # Target platform rustTarget = '' - [target."${rust.toRustTarget stdenv.buildPlatform}"] + [host."${rust.toRustTarget stdenv.buildPlatform}"] "linker" = "${ccForBuild}" - ${lib.optionalString (stdenv.buildPlatform.config != stdenv.hostPlatform.config) '' - [target."${shortTarget}"] - "linker" = "${ccForHost}" - ''} + "rustflags" = [ "-C", "target-feature=${if stdenv.buildPlatform.isStatic then "+" else "-"}crt-static" ] + + [target."${rust.toRustTarget stdenv.hostPlatform}"] + "linker" = "${ccForHost}" "rustflags" = [ "-C", "target-feature=${if stdenv.hostPlatform.isStatic then "+" else "-"}crt-static" ] + + [unstable] + host-config = true + target-applies-to-host = true ''; }; } ./cargo-setup-hook.sh) {}; From deab9411126cc1493c7265230e7e491820ac9d01 Mon Sep 17 00:00:00 2001 From: Yureka Date: Fri, 28 Oct 2022 19:05:26 +0200 Subject: [PATCH 3/8] cargo: no longer broken on musl --- pkgs/development/compilers/rust/cargo.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkgs/development/compilers/rust/cargo.nix b/pkgs/development/compilers/rust/cargo.nix index 6a4d01de5ef42..2c9a3b1af472a 100644 --- a/pkgs/development/compilers/rust/cargo.nix +++ b/pkgs/development/compilers/rust/cargo.nix @@ -75,7 +75,5 @@ rustPlatform.buildRustPackage { maintainers = with maintainers; [ retrry ]; license = [ licenses.mit licenses.asl20 ]; platforms = platforms.unix; - # weird segfault in a build script - broken = stdenv.targetPlatform.isMusl && !stdenv.targetPlatform.isStatic; }; } From 4efa7c2d854d70f285f0d8c3f457481e76deeac6 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 16 Oct 2022 21:17:12 +0000 Subject: [PATCH 4/8] pkg-config: set pkg-config-rs-compatible env vars By moving this from the rustc derivation, the necessary environment variables will also be set for other Rust packages that need them, like cargo. --- pkgs/build-support/pkg-config-wrapper/default.nix | 2 ++ pkgs/build-support/pkg-config-wrapper/setup-hook.sh | 6 ++++++ pkgs/development/compilers/rust/rustc.nix | 7 ------- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pkgs/build-support/pkg-config-wrapper/default.nix b/pkgs/build-support/pkg-config-wrapper/default.nix index 312d2fe02610a..e255ee0ffce1a 100644 --- a/pkgs/build-support/pkg-config-wrapper/default.nix +++ b/pkgs/build-support/pkg-config-wrapper/default.nix @@ -3,6 +3,7 @@ { stdenvNoCC , lib +, rust , buildPackages , pkg-config , baseBinName ? "pkg-config" @@ -39,6 +40,7 @@ stdenv.mkDerivation { shell = getBin stdenvNoCC.shell + stdenvNoCC.shell.shellPath or ""; inherit targetPrefix suffixSalt baseBinName; + rustTarget = replaceStrings ["-"] ["_"] (rust.toRustTarget targetPlatform); outputs = [ "out" ] ++ optionals propagateDoc ([ "man" ] ++ optional (pkg-config ? doc) "doc"); diff --git a/pkgs/build-support/pkg-config-wrapper/setup-hook.sh b/pkgs/build-support/pkg-config-wrapper/setup-hook.sh index 34f1a999a82ee..4eaafd9000439 100644 --- a/pkgs/build-support/pkg-config-wrapper/setup-hook.sh +++ b/pkgs/build-support/pkg-config-wrapper/setup-hook.sh @@ -25,5 +25,11 @@ addEnvHooks "$targetOffset" pkgConfigWrapper_addPkgConfigPath export PKG_CONFIG${role_post}=@targetPrefix@@baseBinName@ +# The Rust pkg-config crate does not support prefixed pkg-config executables[1], +# but it does support checking these idiosyncratic PKG_CONFIG_${TRIPLE} +# environment variables. +# [1]: https://github.com/rust-lang/pkg-config-rs/issues/53 +export PKG_CONFIG_@rustTarget@=@targetPrefix@@baseBinName@ + # No local scope in sourced file unset -v role_post diff --git a/pkgs/development/compilers/rust/rustc.nix b/pkgs/development/compilers/rust/rustc.nix index eb0304aca187b..472c1019d06ab 100644 --- a/pkgs/development/compilers/rust/rustc.nix +++ b/pkgs/development/compilers/rust/rustc.nix @@ -41,13 +41,6 @@ in stdenv.mkDerivation rec { # See: https://github.com/NixOS/nixpkgs/pull/56540#issuecomment-471624656 stripDebugList = [ "bin" ]; - # The Rust pkg-config crate does not support prefixed pkg-config executables[1], - # but it does support checking these idiosyncratic PKG_CONFIG_${TRIPLE} - # environment variables. - # [1]: https://github.com/rust-lang/pkg-config-rs/issues/53 - "PKG_CONFIG_${builtins.replaceStrings ["-"] ["_"] (rust.toRustTarget stdenv.buildPlatform)}" = - "${pkgsBuildHost.stdenv.cc.targetPrefix}pkg-config"; - NIX_LDFLAGS = toString ( # when linking stage1 libstd: cc: undefined reference to `__cxa_begin_catch' optional (stdenv.isLinux && !withBundledLLVM) "--push-state --as-needed -lstdc++ --pop-state" From 60e1814946aadf64fb05c82847185db683cf9c65 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 16 Oct 2022 17:16:27 +0000 Subject: [PATCH 5/8] cargo: run libcurl link test when cross-compiling It's not possible to run installCheckPhase when cross-compiling, so we have to tack this on to postInstall instead. --- pkgs/development/compilers/rust/cargo.nix | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pkgs/development/compilers/rust/cargo.nix b/pkgs/development/compilers/rust/cargo.nix index 2c9a3b1af472a..3e6dee8350d7e 100644 --- a/pkgs/development/compilers/rust/cargo.nix +++ b/pkgs/development/compilers/rust/cargo.nix @@ -50,6 +50,12 @@ rustPlatform.buildRustPackage { src/tools/cargo/src/etc/cargo.bashcomp.sh installShellCompletion --zsh src/tools/cargo/src/etc/_cargo + '' + lib.optionalString (!stdenv.hostPlatform.isStatic && + stdenv.hostPlatform.parsed.kernel.execFormat == lib.systems.parse.execFormats.elf) '' + # Check that it didn't build its own static libcurl. This isn't an + # installCheck because it should be run even when cross compiling. + echo Checking libcurl is dynamically linked... + $READELF -a $out/bin/.cargo-wrapped | grep -F 'Shared library: [libcurl.so' ''; checkPhase = '' @@ -61,14 +67,6 @@ rustPlatform.buildRustPackage { # Disable check phase as there are failures (4 tests fail) doCheck = false; - doInstallCheck = !stdenv.hostPlatform.isStatic && - stdenv.hostPlatform.parsed.kernel.execFormat == lib.systems.parse.execFormats.elf; - installCheckPhase = '' - runHook preInstallCheck - readelf -a $out/bin/.cargo-wrapped | grep -F 'Shared library: [libcurl.so' - runHook postInstallCheck - ''; - meta = with lib; { homepage = "https://crates.io"; description = "Downloads your Rust project's dependencies and builds your project"; From ab29bae3fc4eaa293b1bce236dc06ffccd4bf510 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 16 Oct 2022 17:17:08 +0000 Subject: [PATCH 6/8] cargo: add missing zlib build dependency This fixes cross-compilation. --- pkgs/development/compilers/rust/cargo.nix | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pkgs/development/compilers/rust/cargo.nix b/pkgs/development/compilers/rust/cargo.nix index 3e6dee8350d7e..14b9ac3cf3542 100644 --- a/pkgs/development/compilers/rust/cargo.nix +++ b/pkgs/development/compilers/rust/cargo.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, pkgsHostHost +{ lib, stdenv, fetchpatch, pkgsHostHost , file, curl, pkg-config, python3, openssl, cmake, zlib , installShellFiles, makeWrapper, cacert, rustPlatform, rustc , libiconv, CoreFoundation, Security @@ -8,6 +8,18 @@ rustPlatform.buildRustPackage { pname = "cargo"; inherit (rustc) version src; + patches = [ + # Update the pkg-config crate so it supports the cross-compilation + # environment variables exported by the pkg-config setup hook. + # Fortunately, the new version of the crate is already present in + # the vendor directory, as it was already updated for the + # "bootstrap" crate that implements the build system for rustc. + (fetchpatch { + url = "https://github.com/rust-lang/rust/commit/b3b6fbc8341a008347cad370af1210aa4efa3080.patch"; + sha256 = "09xcfladpdrd7lmncai5160f47yibg5x1n9p6xsfpvh2cnaci3c5"; + }) + ]; + # the rust source tarball already has all the dependencies vendored, no need to fetch them again cargoVendorDir = "vendor"; buildAndTestSubdir = "src/tools/cargo"; @@ -20,8 +32,10 @@ rustPlatform.buildRustPackage { # changes hash of vendor directory otherwise dontUpdateAutotoolsGnuConfigScripts = true; + depsBuildBuild = [ pkg-config ]; + nativeBuildInputs = [ - pkg-config cmake installShellFiles makeWrapper + pkg-config cmake installShellFiles makeWrapper zlib (lib.getDev pkgsHostHost.curl) ]; buildInputs = [ cacert file curl python3 openssl zlib ] From 3439644bb1f1c805febf425ead225b1902845eaa Mon Sep 17 00:00:00 2001 From: Yureka Date: Sat, 29 Oct 2022 08:46:11 +0200 Subject: [PATCH 7/8] file: fix doCheck conditional for pkgsMusl.pkgsCross.gnu64 --- pkgs/tools/misc/file/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/tools/misc/file/default.nix b/pkgs/tools/misc/file/default.nix index 980502a269a4a..03be0c8b3be38 100644 --- a/pkgs/tools/misc/file/default.nix +++ b/pkgs/tools/misc/file/default.nix @@ -25,7 +25,7 @@ stdenv.mkDerivation rec { ++ lib.optional stdenv.hostPlatform.isWindows libgnurx; # https://bugs.astron.com/view.php?id=382 - doCheck = !stdenv.hostPlatform.isMusl; + doCheck = !stdenv.buildPlatform.isMusl; makeFlags = lib.optional stdenv.hostPlatform.isWindows "FILE_COMPILE=file"; From 5c450c54299f3f3d1197664c1c122cadefbf3616 Mon Sep 17 00:00:00 2001 From: Yureka Date: Sat, 29 Oct 2022 08:46:51 +0200 Subject: [PATCH 8/8] cargo-c: fix cross and static --- pkgs/development/tools/rust/cargo-c/default.nix | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkgs/development/tools/rust/cargo-c/default.nix b/pkgs/development/tools/rust/cargo-c/default.nix index e478f909a2437..c9a75b28dcc13 100644 --- a/pkgs/development/tools/rust/cargo-c/default.nix +++ b/pkgs/development/tools/rust/cargo-c/default.nix @@ -2,7 +2,9 @@ , rustPlatform , fetchCrate , pkg-config +, zlib , curl +, libssh2 , openssl , stdenv , CoreFoundation @@ -23,12 +25,16 @@ rustPlatform.buildRustPackage rec { cargoSha256 = "sha256-JrlEWgKbTqQG/JYFqBR53eB58fa29c/+vIdSNGoS5Y0="; - nativeBuildInputs = [ pkg-config (lib.getDev curl) ]; - buildInputs = [ openssl curl ] ++ lib.optionals stdenv.isDarwin [ + depsBuildBuild = [ pkg-config ]; + + nativeBuildInputs = [ pkg-config (lib.getDev curl) (lib.getDev libssh2) zlib ]; + buildInputs = [ openssl curl libssh2 stdenv.cc.cc.lib ] ++ lib.optionals stdenv.isDarwin [ CoreFoundation libiconv Security ]; + NIX_LDFLAGS = "-lc -lm -lgcc "; + LIBSSH2_SYS_USE_PKG_CONFIG = "1"; # Ensure that we are avoiding build of the curl vendored in curl-sys doInstallCheck = stdenv.hostPlatform.libc == "glibc";