From 7713fba8f89a15fd0413ea61b98880e90a978eec Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Tue, 14 Jul 2020 14:39:13 +0200 Subject: [PATCH 1/2] Revert "buildRustPackage: fix cargoBuildFlags" This reverts commit deb78151a9438fb202842d9dbe348365cfd767e0. Mixing up two distinct phases of a derivation's build is not a good idea. See also https://github.com/NixOS/nixpkgs/pull/91689#issuecomment-657813954. --- pkgs/build-support/rust/default.nix | 2 +- pkgs/development/tools/rust/rustup/default.nix | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index 9e9f2cb4e3b..8d3a7ba6929 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -199,7 +199,7 @@ stdenv.mkDerivation (args // { -executable ! \( -regex ".*\.\(so.[0-9.]+\|so\|a\|dylib\)" \)) ''; - installCheckPhase = args.checkPhase or (let + checkPhase = args.checkPhase or (let argstr = "${stdenv.lib.optionalString (checkType == "release") "--release"} --target ${rustTarget} --frozen"; in '' ${stdenv.lib.optionalString (buildAndTestSubdir != null) "pushd ${buildAndTestSubdir}"} diff --git a/pkgs/development/tools/rust/rustup/default.nix b/pkgs/development/tools/rust/rustup/default.nix index fd772ff40b2..bdd916ccdda 100644 --- a/pkgs/development/tools/rust/rustup/default.nix +++ b/pkgs/development/tools/rust/rustup/default.nix @@ -39,9 +39,7 @@ rustPlatform.buildRustPackage rec { ) ]; - # Disable tests until they can be run with --features no-self-update - doCheck = false; - #doCheck = !stdenv.isAarch64 && !stdenv.isDarwin; + doCheck = !stdenv.isAarch64 && !stdenv.isDarwin; postInstall = '' pushd $out/bin From d2694d936ef88d0d6028203105552efddf6db23d Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Tue, 14 Jul 2020 17:32:06 +0200 Subject: [PATCH 2/2] rustPlatform: don't install artifacts modified by `checkPhase` While the artifacts from `buildPhase` should be used for testing as well, it should be avoided that those are modified during `checkPhase`. This can happen if a package is built e.g. with special `cargoBuildFlags` that don't apply to the `checkPhase`. In that case, a binary would be installed into `$out` without those flags since `checkPhase` overrides the binary in the `target`-directory. This patch copies the state of `target/release` into a temporary location at the end of the `buildPhase` and installs the results from that temporary directory into `$out` while `checkPhase` can continue using the configured build-dir. cc #91689 Closes #93119 Closes #91191 --- pkgs/build-support/rust/default.nix | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index 8d3a7ba6929..c292b8ea4d4 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -74,6 +74,7 @@ let ccForHost="${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"; cxxForHost="${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++"; releaseDir = "target/${rustTarget}/${buildType}"; + tmpDir = "${releaseDir}-tmp"; # Specify the stdenv's `diff` by abspath to ensure that the user's build # inputs do not cause us to find the wrong `diff`. @@ -193,7 +194,9 @@ stdenv.mkDerivation (args // { # This needs to be done after postBuild: packages like `cargo` do a pushd/popd in # the pre/postBuild-hooks that need to be taken into account before gathering # all binaries to install. - bins=$(find $releaseDir \ + mkdir -p $tmpDir + cp -r $releaseDir/* $tmpDir/ + bins=$(find $tmpDir \ -maxdepth 1 \ -type f \ -executable ! \( -regex ".*\.\(so.[0-9.]+\|so\|a\|dylib\)" \)) @@ -214,13 +217,13 @@ stdenv.mkDerivation (args // { strictDeps = true; - inherit releaseDir; + inherit releaseDir tmpDir; installPhase = args.installPhase or '' runHook preInstall # rename the output dir to a architecture independent one - mapfile -t targets < <(find "$NIX_BUILD_TOP" -type d | grep '${releaseDir}$') + mapfile -t targets < <(find "$NIX_BUILD_TOP" -type d | grep '${tmpDir}$') for target in "''${targets[@]}"; do rm -rf "$target/../../${buildType}" ln -srf "$target" "$target/../../" @@ -228,7 +231,7 @@ stdenv.mkDerivation (args // { mkdir -p $out/bin $out/lib xargs -r cp -t $out/bin <<< $bins - find $releaseDir \ + find $tmpDir \ -maxdepth 1 \ -regex ".*\.\(so.[0-9.]+\|so\|a\|dylib\)" \ -print0 | xargs -r -0 cp -t $out/lib