build-support/rust: Organize
- `toRustTarget` and friends pulled out from rust tools into rust library. Since they don't depend on any packages they can be more widely useable. - `build-rust-package` gets its own directory - `fetch-cargo-tarball` gets its own directory (cherry picked from commit 18ed048c7b27e288a6c9ba894790a7e67ed5080d)
This commit is contained in:
parent
96cf5a2b2d
commit
67aa63e5e2
|
@ -9,8 +9,8 @@ let cargo-vendor-normalise = stdenv.mkDerivation {
|
||||||
postFixup = "wrapPythonPrograms";
|
postFixup = "wrapPythonPrograms";
|
||||||
doInstallCheck = true;
|
doInstallCheck = true;
|
||||||
installCheckPhase = ''
|
installCheckPhase = ''
|
||||||
# check that ./fetchcargo-default-config.toml is a fix point
|
# check that ../fetchcargo-default-config.toml is a fix point
|
||||||
reference=${./fetchcargo-default-config.toml}
|
reference=${../fetchcargo-default-config.toml}
|
||||||
< $reference $out/bin/cargo-vendor-normalise > test;
|
< $reference $out/bin/cargo-vendor-normalise > test;
|
||||||
cmp test $reference
|
cmp test $reference
|
||||||
'';
|
'';
|
|
@ -0,0 +1,37 @@
|
||||||
|
{ lib }:
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
# Returns the name of the rust target, even if it is custom. Adjustments are
|
||||||
|
# because rust has slightly different naming conventions than we do.
|
||||||
|
toRustTarget = platform: let
|
||||||
|
inherit (platform.parsed) cpu vendor kernel abi;
|
||||||
|
cpu_ = platform.rustc.platform.arch or {
|
||||||
|
"armv7a" = "armv7";
|
||||||
|
"armv7l" = "armv7";
|
||||||
|
"armv6l" = "arm";
|
||||||
|
"armv5tel" = "armv5te";
|
||||||
|
"riscv64" = "riscv64gc";
|
||||||
|
}.${cpu.name} or cpu.name;
|
||||||
|
vendor_ = platform.rustc.platform.vendor or {
|
||||||
|
"w64" = "pc";
|
||||||
|
}.${vendor.name} or vendor.name;
|
||||||
|
in platform.rustc.config
|
||||||
|
or "${cpu_}-${vendor_}-${kernel.name}${lib.optionalString (abi.name != "unknown") "-${abi.name}"}";
|
||||||
|
|
||||||
|
# Returns the name of the rust target if it is standard, or the json file
|
||||||
|
# containing the custom target spec.
|
||||||
|
toRustTargetSpec = platform:
|
||||||
|
if (platform.rustc or {}) ? platform
|
||||||
|
then builtins.toFile (toRustTarget platform + ".json") (builtins.toJSON platform.rustc.platform)
|
||||||
|
else toRustTarget platform;
|
||||||
|
}
|
|
@ -17,38 +17,17 @@
|
||||||
, CoreFoundation, Security
|
, CoreFoundation, Security
|
||||||
, pkgsBuildTarget, pkgsBuildBuild
|
, pkgsBuildTarget, pkgsBuildBuild
|
||||||
, makeRustPlatform
|
, makeRustPlatform
|
||||||
}: 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
|
let
|
||||||
toTargetOs = platform:
|
# Use `import` to make sure no packages sneak in here.
|
||||||
if platform.isDarwin then "macos"
|
lib' = import ../../../build-support/rust/lib { inherit lib; };
|
||||||
else platform.parsed.kernel.name;
|
in
|
||||||
|
{
|
||||||
|
lib = lib';
|
||||||
|
|
||||||
# Returns the name of the rust target, even if it is custom. Adjustments are
|
# Backwards compat before `lib` was factored out.
|
||||||
# because rust has slightly different naming conventions than we do.
|
inherit (lib') toTargetArch toTargetOs toRustTarget toRustTargetSpec;
|
||||||
toRustTarget = platform: with platform.parsed; let
|
|
||||||
cpu_ = platform.rustc.platform.arch or {
|
|
||||||
"armv7a" = "armv7";
|
|
||||||
"armv7l" = "armv7";
|
|
||||||
"armv6l" = "arm";
|
|
||||||
"armv5tel" = "armv5te";
|
|
||||||
}.${cpu.name} or cpu.name;
|
|
||||||
vendor_ = platform.rustc.platform.vendor or {
|
|
||||||
"w64" = "pc";
|
|
||||||
}.${vendor.name} or vendor.name;
|
|
||||||
in platform.rustc.config
|
|
||||||
or "${cpu_}-${vendor_}-${kernel.name}${lib.optionalString (abi.name != "unknown") "-${abi.name}"}";
|
|
||||||
|
|
||||||
# Returns the name of the rust target if it is standard, or the json file
|
|
||||||
# containing the custom target spec.
|
|
||||||
toRustTargetSpec = platform:
|
|
||||||
if (platform.rustc or {}) ? platform
|
|
||||||
then builtins.toFile (toRustTarget platform + ".json") (builtins.toJSON platform.rustc.platform)
|
|
||||||
else toRustTarget platform;
|
|
||||||
|
|
||||||
# This just contains tools for now. But it would conceivably contain
|
# This just contains tools for now. But it would conceivably contain
|
||||||
# libraries too, say if we picked some default/recommended versions from
|
# libraries too, say if we picked some default/recommended versions from
|
||||||
|
|
|
@ -7,11 +7,11 @@ rec {
|
||||||
inherit rustc cargo;
|
inherit rustc cargo;
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchCargoTarball = buildPackages.callPackage ../../../build-support/rust/fetchCargoTarball.nix {
|
fetchCargoTarball = buildPackages.callPackage ../../../build-support/rust/fetch-cargo-tarball {
|
||||||
inherit cargo;
|
inherit cargo;
|
||||||
};
|
};
|
||||||
|
|
||||||
buildRustPackage = callPackage ../../../build-support/rust {
|
buildRustPackage = callPackage ../../../build-support/rust/build-rust-package {
|
||||||
inherit cargoBuildHook cargoCheckHook cargoInstallHook cargoSetupHook
|
inherit cargoBuildHook cargoCheckHook cargoInstallHook cargoSetupHook
|
||||||
fetchCargoTarball rustc;
|
fetchCargoTarball rustc;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue