Skip to content

Commit

Permalink
Fix cross compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
oxalica committed Apr 6, 2021
1 parent 5f9d317 commit d3956f0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
3 changes: 3 additions & 0 deletions examples/cross-aarch64/.cargo/config
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[build]
target-dir = "target"

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-unknown-linux-gnu-gcc"
runner = "qemu-aarch64"
1 change: 1 addition & 0 deletions examples/cross-aarch64/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
2 changes: 1 addition & 1 deletion examples/cross-aarch64/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 14 additions & 13 deletions rust-overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -246,7 +246,7 @@ let
'';

dontStrip = true;
};
});

aggregateComponents = { pname, version, components }:
self.pkgs.symlinkJoin {
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
};
}
Expand Down

0 comments on commit d3956f0

Please sign in to comment.