Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkgs/build-support/pkg-config-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

{ stdenvNoCC
, lib
, rust
, buildPackages
, pkg-config
, baseBinName ? "pkg-config"
Expand Down Expand Up @@ -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");

Expand Down
6 changes: 6 additions & 0 deletions pkgs/build-support/pkg-config-wrapper/setup-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 9 additions & 5 deletions pkgs/build-support/rust/hooks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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) {};
Expand Down
34 changes: 22 additions & 12 deletions pkgs/development/compilers/rust/cargo.nix
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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";
Expand All @@ -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 ]
Expand Down Expand Up @@ -50,6 +64,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 = ''
Expand All @@ -61,21 +81,11 @@ 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";
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;
};
}
7 changes: 0 additions & 7 deletions pkgs/development/compilers/rust/rustc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 12 additions & 6 deletions pkgs/development/tools/rust/cargo-c/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
, rustPlatform
, fetchCrate
, pkg-config
, zlib
, curl
, libssh2
, openssl
, stdenv
, CoreFoundation
Expand All @@ -12,23 +14,27 @@

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 [
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";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/tools/misc/file/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down