From c0763eac05f6e8adf05a1d94fc80ded1a9e14f2c Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Wed, 26 Jul 2023 16:48:37 +0200 Subject: [PATCH] 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 --- gcc/rust/expand/rust-proc-macro.cc | 9 +++++++++ libgrust/libproc_macro/proc_macro.cc | 8 ++++++++ libgrust/libproc_macro/proc_macro.h | 3 +++ libgrust/libproc_macro/registration.h | 3 +++ 4 files changed, 23 insertions(+) diff --git a/gcc/rust/expand/rust-proc-macro.cc b/gcc/rust/expand/rust-proc-macro.cc index 7843ead4412..b6cfe254394 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 a4046919721..1e9e3fdfaed 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 80dd28216af..0b3ec3c4d55 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 5cefc37de11..76688632ced 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 */