]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: import: Load procedural macros into external crate
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Thu, 15 Jun 2023 14:37:07 +0000 (16:37 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:55:58 +0000 (18:55 +0100)
Load the procedural macro array into the external crate structure.

gcc/rust/ChangeLog:

* metadata/rust-imports.cc (Import::try_package_in_directory):
Add call to load macros before loading metadatas.
* expand/rust-proc-macro.cc: Return empty vector instead of
panicking on error.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/expand/rust-proc-macro.cc
gcc/rust/metadata/rust-imports.cc

index 6ba87b6dd1b35c7e89fc6c5b9fcaab7b11aeb4c8..acd7f711a28f1959a210abbcc3508d803026de95 100644 (file)
@@ -115,7 +115,7 @@ load_macros (std::string path)
   const ProcMacro::ProcmacroArray *array = load_macros_array (path);
   // Did not load the proc macro
   if (array == nullptr)
-    rust_unreachable ();
+    return {};
 
   rust_debug ("Found %lu procedural macros", array->length);
 
index 669cecb29c3294b2f8ce9a6e7f2073cd72d3b5c8..78b27eaa88489f9aa96e253dfe43c57a0e5577a6 100644 (file)
@@ -164,11 +164,13 @@ Import::try_package_in_directory (const std::string &filename,
        return std::make_pair (nullptr, std::vector<ProcMacro::Procmacro>{});
     }
 
+  auto macros = load_macros (found_filename);
+
   // The export data may not be in this file.
   std::unique_ptr<Stream> s
     = Import::find_export_data (found_filename, fd, location);
   if (s != nullptr)
-    return std::make_pair (std::move (s), std::vector<ProcMacro::Procmacro>{});
+    return std::make_pair (std::move (s), macros);
 
   close (fd);
 
@@ -176,7 +178,7 @@ Import::try_package_in_directory (const std::string &filename,
                 "%s exists but does not contain any Rust export data",
                 found_filename.c_str ());
 
-  return std::make_pair (NULL, std::vector<ProcMacro::Procmacro>{});
+  return std::make_pair (NULL, macros);
 }
 
 // Given import "*PFILENAME", where *PFILENAME does not exist, try