Skip to content

Commit

Permalink
proc_macro: Add is_available callback
Browse files Browse the repository at this point in the history
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.

ChangeLog:

	* libgrust/libproc_macro/proc_macro.cc (not_available): Add a
	function to express bridge unavailability.
	* libgrust/libproc_macro/proc_macro.h (not_available): Likewise.
	* libgrust/libproc_macro/registration.h: Add symbol type.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
  • Loading branch information
P-E-P committed Jul 26, 2023
1 parent 2615215 commit 646355c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions gcc/rust/expand/rust-proc-macro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename Symbol, typename Callback>
bool
register_callback (void *handle, Symbol, std::string symbol_name,
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions libgrust/libproc_macro/proc_macro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 3 additions & 0 deletions libgrust/libproc_macro/proc_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ struct ProcmacroArray
Procmacro *macros;
};

bool
not_available ();

} // namespace ProcMacro

#endif /* ! PROC_MACRO_H */
3 changes: 3 additions & 0 deletions libgrust/libproc_macro/registration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 646355c

Please sign in to comment.