2019-11-08 12:04:53 +00:00
|
|
|
{ rustcVersion
|
|
|
|
, rustcSha256
|
2020-01-18 09:57:13 +00:00
|
|
|
, enableRustcDev ? true
|
2019-11-08 12:04:53 +00:00
|
|
|
, bootstrapVersion
|
|
|
|
, bootstrapHashes
|
|
|
|
, selectRustPackage
|
2020-02-22 23:34:05 +00:00
|
|
|
, rustcPatches ? []
|
2020-12-14 08:40:37 +00:00
|
|
|
, llvmBootstrapForDarwin
|
|
|
|
, llvmShared
|
|
|
|
, llvmSharedForBuild
|
|
|
|
, llvmSharedForHost
|
|
|
|
, llvmSharedForTarget
|
2019-11-08 12:04:53 +00:00
|
|
|
}:
|
2019-06-16 20:59:06 +01:00
|
|
|
{ stdenv, lib
|
2018-11-21 01:47:45 +00:00
|
|
|
, buildPackages
|
|
|
|
, newScope, callPackage
|
2018-10-26 16:06:56 +01:00
|
|
|
, CoreFoundation, Security
|
2019-06-16 20:59:06 +01:00
|
|
|
, pkgsBuildTarget, pkgsBuildBuild
|
2020-10-01 22:51:46 +01:00
|
|
|
, makeRustPlatform
|
2018-11-21 01:47:45 +00:00
|
|
|
}: rec {
|
2020-09-29 06:15:06 +01:00
|
|
|
# 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;
|
|
|
|
|
2020-10-14 04:37:29 +01:00
|
|
|
# Returns the name of the rust target, even if it is custom. Adjustments are
|
|
|
|
# because rust has slightly different naming conventions than we do.
|
2018-12-21 00:28:09 +00:00
|
|
|
toRustTarget = platform: with platform.parsed; let
|
2020-11-28 19:32:43 +00:00
|
|
|
cpu_ = platform.rustc.platform.arch or {
|
2018-12-21 00:28:09 +00:00
|
|
|
"armv7a" = "armv7";
|
|
|
|
"armv7l" = "armv7";
|
|
|
|
"armv6l" = "arm";
|
2021-05-15 16:43:51 +01:00
|
|
|
"armv5tel" = "armv5te";
|
2020-12-27 09:13:27 +00:00
|
|
|
"riscv64" = "riscv64gc";
|
2020-09-29 06:15:06 +01:00
|
|
|
}.${cpu.name} or cpu.name;
|
2020-03-12 13:56:55 +00:00
|
|
|
in platform.rustc.config
|
|
|
|
or "${cpu_}-${vendor.name}-${kernel.name}${lib.optionalString (abi.name != "unknown") "-${abi.name}"}";
|
2018-12-21 00:28:09 +00:00
|
|
|
|
2020-10-14 04:37:29 +01:00
|
|
|
# Returns the name of the rust target if it is standard, or the json file
|
|
|
|
# containing the custom target spec.
|
|
|
|
toRustTargetSpec = platform:
|
2020-11-28 19:32:43 +00:00
|
|
|
if (platform.rustc or {}) ? platform
|
|
|
|
then builtins.toFile (toRustTarget platform + ".json") (builtins.toJSON platform.rustc.platform)
|
2020-10-14 04:37:29 +01:00
|
|
|
else toRustTarget platform;
|
|
|
|
|
2018-11-21 01:47:45 +00:00
|
|
|
# This just contains tools for now. But it would conceivably contain
|
|
|
|
# libraries too, say if we picked some default/recommended versions from
|
|
|
|
# `cratesIO` to build by Hydra and/or try to prefer/bias in Cargo.lock for
|
|
|
|
# all vendored Carnix-generated nix.
|
|
|
|
#
|
|
|
|
# In the end game, rustc, the rust standard library (`core`, `std`, etc.),
|
|
|
|
# and cargo would themselves be built with `buildRustCreate` like
|
|
|
|
# everything else. Tools and `build.rs` and procedural macro dependencies
|
|
|
|
# would be taken from `buildRustPackages` (and `bootstrapRustPackages` for
|
|
|
|
# anything provided prebuilt or their build-time dependencies to break
|
|
|
|
# cycles / purify builds). In this way, nixpkgs would be in control of all
|
|
|
|
# bootstrapping.
|
|
|
|
packages = {
|
2019-11-08 12:04:53 +00:00
|
|
|
prebuilt = callPackage ./bootstrap.nix {
|
|
|
|
version = bootstrapVersion;
|
|
|
|
hashes = bootstrapHashes;
|
|
|
|
};
|
2018-11-21 01:47:45 +00:00
|
|
|
stable = lib.makeScope newScope (self: let
|
|
|
|
# Like `buildRustPackages`, but may also contain prebuilt binaries to
|
|
|
|
# break cycle. Just like `bootstrapTools` for nixpkgs as a whole,
|
|
|
|
# nothing in the final package set should refer to this.
|
|
|
|
bootstrapRustPackages = self.buildRustPackages.overrideScope' (_: _:
|
|
|
|
lib.optionalAttrs (stdenv.buildPlatform == stdenv.hostPlatform)
|
2019-11-08 12:04:53 +00:00
|
|
|
(selectRustPackage buildPackages).packages.prebuilt);
|
2018-11-21 01:47:45 +00:00
|
|
|
bootRustPlatform = makeRustPlatform bootstrapRustPackages;
|
|
|
|
in {
|
|
|
|
# Packages suitable for build-time, e.g. `build.rs`-type stuff.
|
2019-11-08 12:04:53 +00:00
|
|
|
buildRustPackages = (selectRustPackage buildPackages).packages.stable;
|
2018-11-21 01:47:45 +00:00
|
|
|
# Analogous to stdenv
|
|
|
|
rustPlatform = makeRustPlatform self.buildRustPackages;
|
2019-04-23 14:25:12 +01:00
|
|
|
rustc = self.callPackage ./rustc.nix ({
|
2019-11-08 12:04:53 +00:00
|
|
|
version = rustcVersion;
|
|
|
|
sha256 = rustcSha256;
|
2020-01-18 09:57:13 +00:00
|
|
|
inherit enableRustcDev;
|
2020-12-14 08:40:37 +00:00
|
|
|
inherit llvmShared llvmSharedForBuild llvmSharedForHost llvmSharedForTarget;
|
2019-11-08 12:04:53 +00:00
|
|
|
|
2020-02-22 23:34:05 +00:00
|
|
|
patches = rustcPatches;
|
|
|
|
|
2018-11-21 01:47:45 +00:00
|
|
|
# Use boot package set to break cycle
|
|
|
|
rustPlatform = bootRustPlatform;
|
2019-04-23 14:25:12 +01:00
|
|
|
} // lib.optionalAttrs (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) {
|
2020-12-14 08:40:37 +00:00
|
|
|
stdenv = llvmBootstrapForDarwin.stdenv;
|
|
|
|
pkgsBuildBuild = pkgsBuildBuild // { targetPackages.stdenv = llvmBootstrapForDarwin.stdenv; };
|
|
|
|
pkgsBuildHost = pkgsBuildBuild // { targetPackages.stdenv = llvmBootstrapForDarwin.stdenv; };
|
|
|
|
pkgsBuildTarget = pkgsBuildTarget // { targetPackages.stdenv = llvmBootstrapForDarwin.stdenv; };
|
2019-04-23 14:25:12 +01:00
|
|
|
});
|
2019-08-16 11:26:51 +01:00
|
|
|
rustfmt = self.callPackage ./rustfmt.nix { inherit Security; };
|
2019-03-12 01:19:48 +00:00
|
|
|
cargo = self.callPackage ./cargo.nix {
|
2018-11-21 01:47:45 +00:00
|
|
|
# Use boot package set to break cycle
|
|
|
|
rustPlatform = bootRustPlatform;
|
|
|
|
inherit CoreFoundation Security;
|
2019-03-12 01:19:48 +00:00
|
|
|
};
|
2019-08-15 15:13:01 +01:00
|
|
|
clippy = self.callPackage ./clippy.nix { inherit Security; };
|
2019-08-16 18:03:38 +01:00
|
|
|
rls = self.callPackage ./rls { inherit CoreFoundation Security; };
|
2018-11-21 01:47:45 +00:00
|
|
|
});
|
2016-06-14 11:49:48 +01:00
|
|
|
};
|
|
|
|
}
|