NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.07k stars 14.12k forks source link

buildRustPackage cannot cross-compile anymore #149593

Open sbourdeauducq opened 2 years ago

sbourdeauducq commented 2 years ago

For reasons that I do not understand, buildRustPackage attempts to build openssh when cross-compiling. This now fails as of current master and release-21.11. It used to work on nixpkgs 0f4b4b85d959200f52c16bbb74036994e7db5f74. I'm not sure if openssh should be fixed, or if buildRustPackage should not attempt to cross-compile openssh in the first place.

Issue can be reproduced with:

NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build -A pkgsCross.mingwW64.rink

(Note that it builds correctly and runs with 0f4b4b85d959200f52c16bbb74036994e7db5f74 despite marked as "unsupported")

sbourdeauducq commented 2 years ago

Workaround:

--- a/pkgs/build-support/rust/build-rust-package/default.nix
+++ b/pkgs/build-support/rust/build-rust-package/default.nix
@@ -119,7 +119,6 @@ stdenv.mkDerivation ((removeAttrs args [ "depsExtraArgs" "cargoLock" ]) // lib.o

   nativeBuildInputs = nativeBuildInputs ++ [
     cacert
-    git
     cargoBuildHook
     cargoCheckHook
     cargoInstallHook
sbourdeauducq commented 2 years ago

It fails during the check phase and it seems 85c63a515d21c8fa27a561a9b8a1db5b18118e39 is what broke it. @risicle

risicle commented 2 years ago

It depends what you mean by cross-compiling. If you mean building using the binfmt_misc qemu method then yes, I ran into this yesterday. LD_PRELOAD doesn't appear to work with it. But if that's a problem, we should review all uses of libredirect because they will have the same issue.

If by cross-compiling you mean having a different stdenv.hostPlatform and stdenv.targetPlatform, I'm surprised this doesn't already automatically disable the checkPhase and if not, it would surely be fairly easy to detect at eval-time and disable the tests.

Conditionally disabling the tests for the binfmt_misc case would be tricky and would introduce an impurity.

sbourdeauducq commented 2 years ago

It depends what you mean by cross-compiling.

With the repro nix-build -A pkgsCross.mingwW64.rink it means having a different stdenv.hostPlatform and stdenv.targetPlatform I believe.

risicle commented 2 years ago

Oh just looking at the docs now looks like I've misunderstood what hostPlatform is all along. I think what I meant was buildPlatform.

Anyway, looks like it doesn't disable it by default: https://nixos.org/manual/nixpkgs/stable/#cross-testsuite-runs-host-code

Which surprises me because I would have expected most packages' checkPhases would need to run host-native code. But it should be a simple fix..

risicle commented 2 years ago

Turns out it actually does? https://github.com/NixOS/nixpkgs/blob/e03cb37982e485aa7fe89490dfdea471288bd31c/pkgs/stdenv/generic/make-derivation.nix#L103

But it gets more confusing because when I try building nix-build -A pkgsCross.mingwW64.rink even with doCheck = stdenv.hostPlatform == stdenv.buildPlatform; explicitly set for openssh, it still tries to run the tests. So in this case, it does appear stdenv.hostPlatform == stdenv.buildPlatform.