Merge pull request #190697 from newAM/rustc-fix-embedded

rustc: fix build for no_std targets
This commit is contained in:
Jörg Thalheim 2022-10-07 16:50:56 +02:00 committed by GitHub
commit c4e25f230b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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.