[gccrs COMMIT 10/14] Export extern block metadata

gerris.rs@gmail.com gerris.rs@gmail.com
Thu Jul 2 12:35:12 GMT 2026


From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

Extern block metadata is required to identify intrinsics from an extern
crate.

gcc/rust/ChangeLog:

	* metadata/rust-export-metadata.cc (ExportContext::begin_extern_block):
	Dump the prefix of an extern block.
	(ExportContext::end_extern_block): Likewise with extern block suffix.
	* metadata/rust-export-metadata.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
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/09d2e57605ec02f31f9f303efa1ca93e64c896d4

The commit has NOT been mentioned in any issue.

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

 gcc/rust/metadata/rust-export-metadata.cc | 18 ++++++++++++++++++
 gcc/rust/metadata/rust-export-metadata.h  |  2 ++
 2 files changed, 20 insertions(+)

diff --git a/gcc/rust/metadata/rust-export-metadata.cc b/gcc/rust/metadata/rust-export-metadata.cc
index 93574284c..3388d0e92 100644
--- a/gcc/rust/metadata/rust-export-metadata.cc
+++ b/gcc/rust/metadata/rust-export-metadata.cc
@@ -106,6 +106,18 @@ ExportContext::emit_function (AST::Function &fn)
   public_interface_buffer += oss.str ();
 }
 
+void
+ExportContext::begin_extern_block (AST::ExternBlock &block)
+{
+  public_interface_buffer += "extern \"" + block.get_abi () + "\" {\n";
+}
+
+void
+ExportContext::end_extern_block ()
+{
+  public_interface_buffer += "}\n";
+}
+
 void
 ExportContext::begin_module (const AST::Module &module)
 {
@@ -152,6 +164,12 @@ public:
   {
     ctx.emit_function (function);
   }
+  void visit (AST::ExternBlock &block) override
+  {
+    ctx.begin_extern_block (block);
+    AST::DefaultASTVisitor::visit (block);
+    ctx.end_extern_block ();
+  }
   void visit (AST::Trait &trait) override { ctx.emit_trait (trait); }
   void visit (AST::Module &module) override
   {
diff --git a/gcc/rust/metadata/rust-export-metadata.h b/gcc/rust/metadata/rust-export-metadata.h
index 399b92951..17dc20a7d 100644
--- a/gcc/rust/metadata/rust-export-metadata.h
+++ b/gcc/rust/metadata/rust-export-metadata.h
@@ -42,6 +42,8 @@ public:
 
   void emit_trait (AST::Trait &trait);
   void emit_function (AST::Function &fn);
+  void begin_extern_block (AST::ExternBlock &block);
+  void end_extern_block ();
   void emit_use_declaration (AST::UseDeclaration &use_decl);
   void begin_module (const AST::Module &module);
   void end_module (const AST::Module &module);
-- 
2.54.0



More information about the Gcc-rust mailing list