Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc: add support for armv7l targets #72480

Closed
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
14 changes: 2 additions & 12 deletions pkgs/build-support/rust/build-rust-crate/build-crate.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, stdenv, echo_build_heading, noisily, makeDeps }:
{ lib, stdenv, echo_build_heading, noisily, makeDeps, rustPlatform }:
{ crateName,
dependencies,
crateFeatures, crateRenames, libName, release, libPath,
Expand All @@ -14,16 +14,6 @@
(["-C codegen-units=$NIX_BUILD_CORES"] ++ extraRustcOpts);
rustcMeta = "-C metadata=${metadata} -C extra-filename=-${metadata}";

# Some platforms have different names for rustc.
rustPlatform =
with stdenv.hostPlatform.parsed;
let cpu_ = if cpu.name == "armv7a" then "armv7"
else cpu.name;
vendor_ = vendor.name;
kernel_ = kernel.name;
abi_ = abi.name;
in
"${cpu_}-${vendor_}-${kernel_}-${abi_}";
in ''
runHook preBuild
norm=""
Expand Down Expand Up @@ -67,7 +57,7 @@
${crateFeatures} --out-dir target/bin --emit=dep-info,link -L dependency=target/deps \
$LINK ${deps}$EXTRA_LIB --cap-lints allow \
$BUILD_OUT_DIR $EXTRA_BUILD $EXTRA_FEATURES --color ${colors} \
${if stdenv.hostPlatform != stdenv.buildPlatform then "--target ${rustPlatform} -C linker=${stdenv.hostPlatform.config}-gcc" else ""}
${if stdenv.hostPlatform != stdenv.buildPlatform then "--target ${rustPlatform.toRustTarget stdenv.hostPlatform} -C linker=${stdenv.hostPlatform.config}-gcc" else ""}
if [ "$crate_name_" != "$crate_name" ]; then
mv target/bin/$crate_name_ target/bin/$crate_name
fi
Expand Down
4 changes: 2 additions & 2 deletions pkgs/build-support/rust/build-rust-crate/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This can be useful for deploying packages with NixOps, and to share
# binary dependencies between projects.

{ lib, stdenv, defaultCrateOverrides, fetchCrate, rustc }:
{ lib, stdenv, defaultCrateOverrides, fetchCrate, rustc, rustPlatform }:

let
# This doesn't appear to be officially documented anywhere yet.
Expand Down Expand Up @@ -59,7 +59,7 @@ let
'';

configureCrate = import ./configure-crate.nix { inherit lib stdenv echo_build_heading noisily makeDeps; };
buildCrate = import ./build-crate.nix { inherit lib stdenv echo_build_heading noisily makeDeps; };
buildCrate = import ./build-crate.nix { inherit lib stdenv echo_build_heading noisily makeDeps rustPlatform; };
installCrate = import ./install-crate.nix;

in
Expand Down
17 changes: 6 additions & 11 deletions pkgs/build-support/rust/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, cacert, git, cargo, rustc, fetchcargo, buildPackages, windows }:
{ stdenv, cacert, git, cargo, rust, rustc, fetchcargo, buildPackages, windows }:

{ name ? "${args.pname}-${args.version}"
, cargoSha256 ? "unset"
Expand Down Expand Up @@ -46,12 +46,7 @@ let
cargoDepsCopy="$sourceRoot/${cargoVendorDir}"
'';

hostConfig = stdenv.hostPlatform.config;

rustHostConfig = {
x86_64-pc-mingw32 = "x86_64-pc-windows-gnu";
}.${hostConfig} or hostConfig;
rustTarget = if target == null then rustHostConfig else target;
rustTarget = if target == null then (rust.toRustTarget stdenv.hostPlatform) else target;

ccForBuild="${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}cc";
cxxForBuild="${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}c++";
Expand Down Expand Up @@ -129,10 +124,10 @@ stdenv.mkDerivation (args // {
(
set -x
env \
"CC_${stdenv.buildPlatform.config}"="${ccForBuild}" \
"CXX_${stdenv.buildPlatform.config}"="${cxxForBuild}" \
"CC_${stdenv.hostPlatform.config}"="${ccForHost}" \
"CXX_${stdenv.hostPlatform.config}"="${cxxForHost}" \
"CC_${rust.toRustTarget stdenv.buildPlatform}"="${ccForBuild}" \
"CXX_${rust.toRustTarget stdenv.buildPlatform}"="${cxxForBuild}" \
"CC_${rust.toRustTarget stdenv.hostPlatform}"="${ccForHost}" \
"CXX_${rust.toRustTarget stdenv.hostPlatform}"="${cxxForHost}" \
cargo build \
${stdenv.lib.optionalString (buildType == "release") "--release"} \
--target ${rustTarget} \
Expand Down
16 changes: 13 additions & 3 deletions pkgs/development/compilers/rust/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@
, llvmPackages_5
, pkgsBuildTarget, pkgsBuildBuild
}: rec {
makeRustPlatform = { rustc, cargo, ... }: {
toRustTarget = platform: {
"x86_64-pc-mingw32" = "x86_64-pc-windows-gnu";
}.${platform.config} or (with platform.parsed; let
cpu_ = {
"armv7a" = "armv7";
"armv7l" = "armv7";
"armv6l" = "arm";
}.${cpu.name} or cpu.name;
in "${cpu_}-${vendor.name}-${kernel.name}-${abi.name}");

makeRustPlatform = { rustc, cargo, ... }: rec {
rust = {
inherit rustc cargo;
inherit rustc cargo toRustTarget;
};

buildRustPackage = callPackage ../../../build-support/rust {
inherit rustc cargo;
inherit rustc cargo rust;

fetchcargo = buildPackages.callPackage ../../../build-support/rust/fetchcargo.nix {
inherit cargo;
Expand Down
6 changes: 3 additions & 3 deletions pkgs/development/compilers/rust/rustc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ in stdenv.mkDerivation rec {
"--set=build.cargo=${rustPlatform.rust.cargo}/bin/cargo"
"--enable-rpath"
"--enable-vendor"
"--build=${stdenv.buildPlatform.config}"
"--host=${stdenv.hostPlatform.config}"
"--target=${stdenv.targetPlatform.config}"
"--build=${rustPlatform.rust.toRustTarget stdenv.buildPlatform}"
"--host=${rustPlatform.rust.toRustTarget stdenv.hostPlatform}"
"--target=${rustPlatform.rust.toRustTarget stdenv.targetPlatform}"

"${setBuild}.cc=${ccForBuild}"
"${setHost}.cc=${ccForHost}"
Expand Down