From: Pierre-Emmanuel Patry Date: Thu, 15 Jun 2023 14:37:07 +0000 (+0200) Subject: gccrs: import: Load procedural macros into external crate X-Git-Tag: basepoints/gcc-15~2322 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37451ad09f7edc081700909208f90b9eea1eb592;p=thirdparty%2Fgcc.git gccrs: import: Load procedural macros into external crate 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 --- diff --git a/gcc/rust/expand/rust-proc-macro.cc b/gcc/rust/expand/rust-proc-macro.cc index 6ba87b6dd1b3..acd7f711a28f 100644 --- a/gcc/rust/expand/rust-proc-macro.cc +++ b/gcc/rust/expand/rust-proc-macro.cc @@ -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); diff --git a/gcc/rust/metadata/rust-imports.cc b/gcc/rust/metadata/rust-imports.cc index 669cecb29c32..78b27eaa8848 100644 --- a/gcc/rust/metadata/rust-imports.cc +++ b/gcc/rust/metadata/rust-imports.cc @@ -164,11 +164,13 @@ Import::try_package_in_directory (const std::string &filename, return std::make_pair (nullptr, std::vector{}); } + auto macros = load_macros (found_filename); + // The export data may not be in this file. std::unique_ptr s = Import::find_export_data (found_filename, fd, location); if (s != nullptr) - return std::make_pair (std::move (s), std::vector{}); + 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{}); + return std::make_pair (NULL, macros); } // Given import "*PFILENAME", where *PFILENAME does not exist, try