From bac7ee3208209cca6d8c58ade2f25e3f91053848 Mon Sep 17 00:00:00 2001 From: Alex Martens Date: Fri, 7 Oct 2022 07:35:29 -0700 Subject: [PATCH] rustc: fix build for no_std targets --- pkgs/build-support/rust/lib/default.nix | 5 +++++ pkgs/development/compilers/rust/default.nix | 2 +- pkgs/development/compilers/rust/rustc.nix | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/rust/lib/default.nix b/pkgs/build-support/rust/lib/default.nix index 2be0c2567879..5eac208cc31c 100644 --- a/pkgs/build-support/rust/lib/default.nix +++ b/pkgs/build-support/rust/lib/default.nix @@ -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"]; } diff --git a/pkgs/development/compilers/rust/default.nix b/pkgs/development/compilers/rust/default.nix index 7c78a784575a..ef01cbf2abc1 100644 --- a/pkgs/development/compilers/rust/default.nix +++ b/pkgs/development/compilers/rust/default.nix @@ -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 diff --git a/pkgs/development/compilers/rust/rustc.nix b/pkgs/development/compilers/rust/rustc.nix index bb5bc1bb1d73..94b7171c02d3 100644 --- a/pkgs/development/compilers/rust/rustc.nix +++ b/pkgs/development/compilers/rust/rustc.nix @@ -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.