buildRustCrate: fix target config environment variables on 32-bit ARM

wip/yesman
Ben Wolsieffer 4 years ago
parent b3f8642587
commit f0fdecfbb4
  1. 11
      pkgs/build-support/rust/build-rust-crate/configure-crate.nix
  2. 10
      pkgs/build-support/rust/build-rust-crate/default.nix
  3. 15
      pkgs/development/compilers/rust/default.nix

@ -1,4 +1,4 @@
{ lib, stdenv, echo_colored, noisily, mkRustcDepArgs, mkRustcFeatureArgs }: { lib, stdenv, rust, echo_colored, noisily, mkRustcDepArgs, mkRustcFeatureArgs }:
{ {
build build
, buildDependencies , buildDependencies
@ -17,7 +17,6 @@
, libName , libName
, libPath , libPath
, release , release
, target_os
, verbose , verbose
, workspace_member }: , workspace_member }:
let version_ = lib.splitString "-" crateVersion; let version_ = lib.splitString "-" crateVersion;
@ -124,8 +123,8 @@ in ''
export CARGO_PKG_AUTHORS="${authors}" export CARGO_PKG_AUTHORS="${authors}"
export CARGO_PKG_DESCRIPTION="${crateDescription}" export CARGO_PKG_DESCRIPTION="${crateDescription}"
export CARGO_CFG_TARGET_ARCH=${stdenv.hostPlatform.parsed.cpu.name} export CARGO_CFG_TARGET_ARCH=${rust.toTargetArch stdenv.hostPlatform}
export CARGO_CFG_TARGET_OS=${target_os} export CARGO_CFG_TARGET_OS=${rust.toTargetOs stdenv.hostPlatform}
export CARGO_CFG_TARGET_FAMILY="unix" export CARGO_CFG_TARGET_FAMILY="unix"
export CARGO_CFG_UNIX=1 export CARGO_CFG_UNIX=1
export CARGO_CFG_TARGET_ENV="gnu" export CARGO_CFG_TARGET_ENV="gnu"
@ -136,8 +135,8 @@ in ''
export CARGO_MANIFEST_DIR=$(pwd) export CARGO_MANIFEST_DIR=$(pwd)
export DEBUG="${toString (!release)}" export DEBUG="${toString (!release)}"
export OPT_LEVEL="${toString optLevel}" export OPT_LEVEL="${toString optLevel}"
export TARGET="${stdenv.hostPlatform.config}" export TARGET="${rust.toRustTarget stdenv.hostPlatform}"
export HOST="${stdenv.hostPlatform.config}" export HOST="${rust.toRustTarget stdenv.buildPlatform}"
export PROFILE=${if release then "release" else "debug"} export PROFILE=${if release then "release" else "debug"}
export OUT_DIR=$(pwd)/target/build/${crateName}.out export OUT_DIR=$(pwd)/target/build/${crateName}.out
export CARGO_PKG_VERSION_MAJOR=${lib.elemAt version 0} export CARGO_PKG_VERSION_MAJOR=${lib.elemAt version 0}

@ -8,12 +8,6 @@
, cargo, jq }: , cargo, jq }:
let let
# This doesn't appear to be officially documented anywhere yet.
# See https://github.com/rust-lang-nursery/rust-forge/issues/101.
target_os = if stdenv.hostPlatform.isDarwin
then "macos"
else stdenv.hostPlatform.parsed.kernel.name;
# Create rustc arguments to link against the given list of dependencies # Create rustc arguments to link against the given list of dependencies
# and renames. # and renames.
# #
@ -52,7 +46,7 @@ let
inherit (import ./log.nix { inherit lib; }) noisily echo_colored; inherit (import ./log.nix { inherit lib; }) noisily echo_colored;
configureCrate = import ./configure-crate.nix { configureCrate = import ./configure-crate.nix {
inherit lib stdenv echo_colored noisily mkRustcDepArgs mkRustcFeatureArgs; inherit lib stdenv rust echo_colored noisily mkRustcDepArgs mkRustcFeatureArgs;
}; };
buildCrate = import ./build-crate.nix { buildCrate = import ./build-crate.nix {
@ -284,7 +278,7 @@ stdenv.mkDerivation (rec {
inherit crateName buildDependencies completeDeps completeBuildDeps crateDescription inherit crateName buildDependencies completeDeps completeBuildDeps crateDescription
crateFeatures crateRenames libName build workspace_member release libPath crateVersion crateFeatures crateRenames libName build workspace_member release libPath crateVersion
extraLinkFlags extraRustcOpts extraLinkFlags extraRustcOpts
crateAuthors crateHomepage verbose colors target_os; crateAuthors crateHomepage verbose colors;
}; };
buildPhase = buildCrate { buildPhase = buildCrate {
inherit crateName dependencies inherit crateName dependencies

@ -13,12 +13,23 @@
, llvmPackages_5 , llvmPackages_5
, pkgsBuildTarget, pkgsBuildBuild , pkgsBuildTarget, pkgsBuildBuild
}: rec { }: rec {
# https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch
toTargetArch = platform:
if platform.isAarch32 then "arm"
else platform.parsed.cpu.name;
# https://doc.rust-lang.org/reference/conditional-compilation.html#target_os
toTargetOs = platform:
if platform.isDarwin then "macos"
else platform.parsed.kernel.name;
# Target triple. Rust has slightly different naming conventions than we use.
toRustTarget = platform: with platform.parsed; let toRustTarget = platform: with platform.parsed; let
cpu_ = { cpu_ = platform.rustc.arch or {
"armv7a" = "armv7"; "armv7a" = "armv7";
"armv7l" = "armv7"; "armv7l" = "armv7";
"armv6l" = "arm"; "armv6l" = "arm";
}.${cpu.name} or platform.rustc.arch or cpu.name; }.${cpu.name} or cpu.name;
in platform.rustc.config in platform.rustc.config
or "${cpu_}-${vendor.name}-${kernel.name}${lib.optionalString (abi.name != "unknown") "-${abi.name}"}"; or "${cpu_}-${vendor.name}-${kernel.name}${lib.optionalString (abi.name != "unknown") "-${abi.name}"}";

Loading…
Cancel
Save