gio: Convenience macro for implementing DBus interfaces#1934
gio: Convenience macro for implementing DBus interfaces#1934tautropfli wants to merge 6 commits into
Conversation
d2013b8 to
2a95f9f
Compare
| fn info(&self) -> *mut #gio::ffi::GDBusInterfaceInfo { | ||
| use #gio::glib::translate::*; | ||
| static INFO: ::std::sync::OnceLock<#gio::DBusInterfaceInfo> = ::std::sync::OnceLock::new(); | ||
| let info = INFO.get_or_init(|| #interface_info); |
There was a problem hiding this comment.
Why do you need a OnceLock for this, it's all constant data that should reside in .rodata?
There was a problem hiding this comment.
method return types are sadly not known at macro evaluation time, see my other reply
| let variant = (#(#arg_idents,)*).to_variant(); | ||
| for connection in connections { | ||
| connection.emit_signal( | ||
| None, |
There was a problem hiding this comment.
There should be a way to specify this. (See this patch for Vala.)
| // | ||
| // Each function argument maps neatly to an in arg so we know the count and their names at generation time. | ||
| // | ||
| // The out args come from the return type for which we know how many tuple elements it has only at runtime |
There was a problem hiding this comment.
I don't think I understand this. Why do we only know that at runtime?
There was a problem hiding this comment.
Proc macros don't have access to type information, only syntax. So we can only recognize tuples that are directly specified as return type using tuple syntax but not type aliases for tuples or structs that marshal to tuple variants.
There was a problem hiding this comment.
We could use const evaluation here, but that would require everything related to the StaticVariantType to be marked const.
There was a problem hiding this comment.
Proc macros don't have access to type information, only syntax.
That looks very unfortunate...
So we can only recognize tuples that are directly specified as return type using tuple syntax but not type aliases for tuples or structs that marshal to tuple variants.
We should require people to always use plain tuples without aliases then (i.e. emit a compile-time error if they don't). Lest we fall into the same trap as zbus.
There was a problem hiding this comment.
Alternatively, yes, using traits for this would make sense. Can't we require the return type to impl some trait (be it StaticVariantType or not) that has a const VARIANT_TYPE: &'static str?
There was a problem hiding this comment.
So we can only recognize tuples that are directly specified as return type using tuple syntax but not type aliases for tuples or structs that marshal to tuple variants.
We should require people to always use plain tuples without aliases then
I should have specified a bit better, my comment was about what information we have at macro evaluation time. At runtime (through StaticVariantType) we do know if a type is a tuple. That's why I currently generate code that puts together the out_args at runtime rather than at macro expansion time.
So right now there is no disconnect between introspection and return value.
Making a const version of StaticVariantType is probably a whole project onto itself 😅 I would rather not have to parse variant strings.
2a95f9f to
f096ca3
Compare
f096ca3 to
9679b6b
Compare
9679b6b to
5109ab3
Compare
(Veeeery WIP)
Edit: I have started working on a new version with the shape suggested in the «Rust ❤️ GNOME» Matrix room. For reference, the old version (the one currently described in this PR's description) can be found in the dbus-interface-derive-v2 branch.
My goal is to have a macro very similar to what zbus has with their
#[zbus::interface]macro.There's no need to specify an XML as the
DBusInterfaceInfois also generated.I originally wanted the macro to implementDBusInterfaceSkeletonbut this interface has so many footguns that I decided to go with my own traitDBusExportableInterfacefor now.It essentially exposes all the parts that are usually passed to
register_object.The macro implements the
DBusInterfaceSkeletoninterface.Todo
[ ] Convenience for registering an object that implementsNot needed since we implementDBusExportableInterfaceDBusInterfaceSkeleton.