Skip to content

The no_std targets seem hardcoded in bootstraping #97322

Closed
@Ayush1325

Description

@Ayush1325

I was trying to build library/core for x86_64-unknown-uefi. However, it was trying to build library/test and by extension library/std for some reason. This is odd since the UEFI targets are no_std targets according to rust platform support. The error I was getting is as follows:

error[E0658]: use of unstable library feature 'restricted_std'
  |
  = help: add `#![feature(restricted_std)]` to the crate attributes to enable

For more information about this error, try `rustc --explain E0658`.
warning: `test` (lib) generated 1 warning (1 duplicate)
error: could not compile `test` due to previous error; 1 warning emitted

Building for some other no_std targets such as x86_64-unknown-none works fine and only builds core, rustc-std-workspace-core, compiler_builtins and alloc.

After some digging around, I found that this can be fixed by making the following changes

--- a/src/bootstrap/config.rs
+++ b/src/bootstrap/config.rs
@@ -363,7 +363,7 @@ pub struct Target {
 impl Target {
     pub fn from_triple(triple: &str) -> Self {
         let mut target: Self = Default::default();
-        if triple.contains("-none") || triple.contains("nvptx") {
+        if triple.contains("-none") || triple.contains("nvptx") || triple.contains("-uefi") {
             target.no_std = true;
         }
         target

However, hardcoding no_std like this doesn't seem to be a good solution. Maybe #95503 will solve this but I don't really know. So just wanted to bring this to community's attention (unless everyone is already aware of this).

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions