rustc: fix build for no_std targets

This commit is contained in:
Alex Martens 2022-10-07 07:35:29 -07:00
parent 8e9a77e2b5
commit bac7ee3208
3 changed files with 8 additions and 1 deletions

View file

@ -38,4 +38,9 @@ rec {
if platform ? rustc.platform
then builtins.toFile (toRustTarget platform + ".json") (builtins.toJSON platform.rustc.platform)
else toRustTarget platform;
# Returns true if the target is no_std
# https://github.com/rust-lang/rust/blob/2e44c17c12cec45b6a682b1e53a04ac5b5fcc9d2/src/bootstrap/config.rs#L415-L421
IsNoStdTarget = platform: let rustTarget = toRustTarget platform; in
builtins.any (t: lib.hasInfix t rustTarget) ["-none" "nvptx" "switch" "-uefi"];
}

View file

@ -28,7 +28,7 @@ in
lib = lib';
# Backwards compat before `lib` was factored out.
inherit (lib') toTargetArch toTargetOs toRustTarget toRustTargetSpec;
inherit (lib') toTargetArch toTargetOs toRustTarget toRustTargetSpec IsNoStdTarget;
# This just contains tools for now. But it would conceivably contain
# libraries too, say if we picked some default/recommended versions from

View file

@ -107,6 +107,8 @@ in stdenv.mkDerivation rec {
"${setHost}.musl-root=${pkgsBuildHost.targetPackages.stdenv.cc.libc}"
] ++ optionals stdenv.targetPlatform.isMusl [
"${setTarget}.musl-root=${pkgsBuildTarget.targetPackages.stdenv.cc.libc}"
] ++ optionals (rust.IsNoStdTarget stdenv.targetPlatform) [
"--disable-docs"
];
# The bootstrap.py will generated a Makefile that then executes the build.