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]>
---
 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 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";
-- 
2.50.1

Reply via email to