From: Pierre-Emmanuel Patry <[email protected]>

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 <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/9cb6b939046eeb3983425d930923a3df2a32f07c

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4447

 gcc/rust/rust-session-manager.cc      | 6 ++++++
 gcc/rust/util/rust-attribute-values.h | 1 +
 2 files changed, 7 insertions(+)

diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index a74b99754..97300e4a1 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 f4146b880..7f0b5ca78 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";

base-commit: 06575e73b81b2dc403a6f795a356bb48905a79ee
-- 
2.53.0

Reply via email to