From: Pierre-Emmanuel Patry Date: Wed, 26 Jul 2023 14:48:37 +0000 (+0200) Subject: gccrs: proc_macro: Add is_available callback X-Git-Tag: basepoints/gcc-15~2295 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0763eac05f6e8adf05a1d94fc80ded1a9e14f2c;p=thirdparty%2Fgcc.git gccrs: proc_macro: Add is_available callback Add a callback from gcc to determine wether the bridge is available or not. gcc/rust/ChangeLog: * expand/rust-proc-macro.cc (available): Add symbol registration. (load_macros_array): Likewise. libgrust/ChangeLog: * libproc_macro/proc_macro.cc (not_available): Add a function to express bridge unavailability. * libproc_macro/proc_macro.h (not_available): Likewise. * libproc_macro/registration.h: Add symbol type. 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 7843ead44122..b6cfe2543941 100644 --- a/gcc/rust/expand/rust-proc-macro.cc +++ b/gcc/rust/expand/rust-proc-macro.cc @@ -56,6 +56,12 @@ static_assert ( ProcMacro::from_str_function_t>::value, "Registration callback signature not synced, check proc macro internals."); +static bool +available () +{ + return true; +} + template bool register_callback (void *handle, Symbol, std::string symbol_name, @@ -95,6 +101,9 @@ load_macros_array (std::string path) if (!REGISTER_CALLBACK (handle, __gccrs_proc_macro_from_str_fn, tokenstream_from_string)) return nullptr; + if (!REGISTER_CALLBACK (handle, __gccrs_proc_macro_is_available_fn, + available)) + return nullptr; // FIXME: Add CrateStableId handling, right now all versions may be loaded, // even incompatible ones. diff --git a/libgrust/libproc_macro/proc_macro.cc b/libgrust/libproc_macro/proc_macro.cc index a40469197217..1e9e3fdfaeda 100644 --- a/libgrust/libproc_macro/proc_macro.cc +++ b/libgrust/libproc_macro/proc_macro.cc @@ -49,6 +49,14 @@ Procmacro::make_bang (const char *name, BangMacro macro) return {BANG, payload}; } +bool +not_available () +{ + return false; +} + } // namespace ProcMacro ProcMacro::from_str_function_t __gccrs_proc_macro_from_str_fn = nullptr; +ProcMacro::is_available_function_t __gccrs_proc_macro_is_available_fn + = ProcMacro::not_available; diff --git a/libgrust/libproc_macro/proc_macro.h b/libgrust/libproc_macro/proc_macro.h index 80dd28216afa..0b3ec3c4d55b 100644 --- a/libgrust/libproc_macro/proc_macro.h +++ b/libgrust/libproc_macro/proc_macro.h @@ -99,6 +99,9 @@ struct ProcmacroArray Procmacro *macros; }; +bool +not_available (); + } // namespace ProcMacro #endif /* ! PROC_MACRO_H */ diff --git a/libgrust/libproc_macro/registration.h b/libgrust/libproc_macro/registration.h index 5cefc37de111..76688632ced2 100644 --- a/libgrust/libproc_macro/registration.h +++ b/libgrust/libproc_macro/registration.h @@ -29,9 +29,12 @@ namespace ProcMacro { using from_str_function_t = ProcMacro::TokenStream (*) (std::string &, bool &); +using is_available_function_t = bool (*) (); } // namespace ProcMacro extern "C" ProcMacro::from_str_function_t __gccrs_proc_macro_from_str_fn; +extern "C" ProcMacro::is_available_function_t + __gccrs_proc_macro_is_available_fn; #endif /* !REGISTRATION_H */