From d3956f058bbd0bdcd92e6a78f0639b9d17e96f98 Mon Sep 17 00:00:00 2001 From: oxalica Date: Tue, 6 Apr 2021 02:27:36 +0800 Subject: [PATCH] Fix cross compiling --- examples/cross-aarch64/.cargo/config | 3 +++ examples/cross-aarch64/.gitignore | 1 + examples/cross-aarch64/shell.nix | 2 +- rust-overlay.nix | 27 ++++++++++++++------------- 4 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 examples/cross-aarch64/.gitignore diff --git a/examples/cross-aarch64/.cargo/config b/examples/cross-aarch64/.cargo/config index 62b7477c0b5..7d2979c152a 100644 --- a/examples/cross-aarch64/.cargo/config +++ b/examples/cross-aarch64/.cargo/config @@ -1,3 +1,6 @@ +[build] +target-dir = "target" + [target.aarch64-unknown-linux-gnu] linker = "aarch64-unknown-linux-gnu-gcc" runner = "qemu-aarch64" diff --git a/examples/cross-aarch64/.gitignore b/examples/cross-aarch64/.gitignore new file mode 100644 index 00000000000..ea8c4bf7f35 --- /dev/null +++ b/examples/cross-aarch64/.gitignore @@ -0,0 +1 @@ +/target diff --git a/examples/cross-aarch64/shell.nix b/examples/cross-aarch64/shell.nix index bf24aa13350..b34fd8d9c9d 100644 --- a/examples/cross-aarch64/shell.nix +++ b/examples/cross-aarch64/shell.nix @@ -6,7 +6,7 @@ mkShell { nativeBuildInputs = [ # Manual `buildPackages` is required here. See: https://github.com/NixOS/nixpkgs/issues/49526 # build = host = x86_64, target = aarch64 - buildPackages.rust-bin.stable.latest.rust + buildPackages.rust-bin.stable.latest.minimal buildPackages.pkg-config # build = host = target = x86_64, just to avoid re-build. pkgsBuildBuild.qemu diff --git a/rust-overlay.nix b/rust-overlay.nix index 98a179121f9..64649244dca 100644 --- a/rust-overlay.nix +++ b/rust-overlay.nix @@ -162,7 +162,7 @@ let map (tuple: { name = tuple.name; src = (getFetchUrl pkgs tuple.name tuple.target stdenv fetchurl); }) pkgsTuplesToInstall; mkComponent = { pname, version, src }: - self.stdenv.mkDerivation { + self.stdenv.mkDerivation ({ inherit pname version src; # No point copying src to a build server, then copying back the @@ -246,7 +246,7 @@ let ''; dontStrip = true; - }; + }); aggregateComponents = { pname, version, components }: self.pkgs.symlinkJoin { @@ -275,21 +275,19 @@ let --replace "@out@" "$out" fi - # `symlinkJoin` (`runCommand`) doesn't handle propagatedBuildInputs. + # `symlinkJoin` (`runCommand`) doesn't handle propagated dependencies. # Need to do it manually. mkdir -p "$out/nix-support" echo "$propagatedBuildInputs" > "$out/nix-support/propagated-build-inputs" + if [[ -n "$depsTargetTargetPropagated" ]]; then + echo "$depsTargetTargetPropagated" > "$out/nix-support/propagated-target-target-deps" + fi ''; - # Add the compiler as part of the propagated build inputs in order - # to run: - # - # $ nix-shell -p rustChannels.stable.rust - # - # And get a fully working Rust compiler, with the stdenv linker. - propagatedBuildInputs = - [ self.stdenv.cc ] ++ - self.lib.optional (self.stdenv.hostPlatform.isDarwin) self.libiconv; + # FIXME: If these propagated dependencies go components, darwin build will fail with "`-liconv` not found". + propagatedBuildInputs = [ self.stdenv.cc ]; + depsTargetTargetPropagated = + self.lib.optional (self.stdenv.targetPlatform.isDarwin) self.targetPackages.libiconv; meta.platforms = self.lib.platforms.all; }; @@ -434,7 +432,10 @@ let inherit componentSet; inherit (manifest) targetComponentsList; extensions = componentNames ++ extensions; - targets = [ (toRustTarget self.stdenv.targetPlatform) ] ++ targets; + targets = [ + (toRustTarget self.stdenv.hostPlatform) # Build script requires host std. + (toRustTarget self.stdenv.targetPlatform) + ] ++ targets; inherit targetExtensions; }; }