From: Pierre-Emmanuel Patry Date: Wed, 25 Feb 2026 00:52:20 +0000 (+0100) Subject: gccrs: Add no_std attribute X-Git-Tag: basepoints/gcc-17~590 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7b991c9d520beecfb14cd75f0444eb84aef8bcb0;p=thirdparty%2Fgcc.git gccrs: Add no_std attribute Add a no_std attribute, when both no_std and no_core attributes are missing, inject an external std crate. gcc/rust/ChangeLog: * rust-session-manager.cc (Session::compile_crate): Inject std crate when both no_std and no_core attributes are missing. * util/rust-attribute-values.h: Add no_std attribute value. Signed-off-by: Pierre-Emmanuel Patry --- diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index a74b99754b8..97300e4a17f 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -681,6 +681,12 @@ Session::compile_crate (const char *filename) std::string (Values::Attributes::NO_CORE))) { parsed_crate.inject_extern_crate ("core"); + // #![no_core] implies #![no_std] + if (!has_attribute (parsed_crate, + std::string (Values::Attributes::NO_STD))) + { + parsed_crate.inject_extern_crate ("std"); + } } if (last_step == CompileOptions::CompileStep::Expansion) diff --git a/gcc/rust/util/rust-attribute-values.h b/gcc/rust/util/rust-attribute-values.h index f4146b8802a..7f0b5ca7866 100644 --- a/gcc/rust/util/rust-attribute-values.h +++ b/gcc/rust/util/rust-attribute-values.h @@ -38,6 +38,7 @@ public: static constexpr auto &LANG = "lang"; static constexpr auto &LINK_NAME = "link_name"; static constexpr auto &NO_CORE = "no_core"; + static constexpr auto &NO_STD = "no_std"; static constexpr auto &LINK_SECTION = "link_section"; static constexpr auto &NO_MANGLE = "no_mangle"; static constexpr auto &EXPORT_NAME = "export_name";