#[gdextension(discovery)]
to expose static information about registered classes
#986
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note
It's completely unclear if we can merge this feature, and in which form. There are quite a few open points, and there may be better approaches to achieve the same.
Allows dependent crates to statically discover classes registered by a Rust extension.
Rationale
The idea is to provide a mechanism that allows tools and integrations to query information about an extension at build time. For example, this allows validations, data extraction/generation, etc. It is limited to downstream crates depending on the crate declaring the extension, in particular their
build.rs
file. If a crate is used for discovery, then it must declarecrate-type = ["cdylib", "rlib"]
, i.e. both a C dynamic library for GDExtension and a Rust library.The API is kept deliberately minimal -- it does not strive to cover the entire reflection API that Godot provides. Many tools may be better fitted as a direct integration into the Godot editor, or as runtime code querying Godot's
ClassDB
API.Usage
To make use of discovery, your entry point trait needs to have the
discover
attribute:To access the exposed API in a dependent crate in
build.rs
, you can callMyExtension::discover()
:Problems
On one hand, the
Cargo.toml
optioncauses the following warning:
On the other, there are several CI issues. I'm also not sure if
hot-reload
is a good place, but I'd rather add two extra crates just for this.The reason for choosing this approach is to enable post-build actions (by moving them into a dependent crate). Given the issues and the need for another crate just for this, I'm not fully convinced this is the best approach. Maybe a custom tool as actual post-build step, which can invoke headless Godot via
ClassDB
introspection, is more versatile. Or maybe a binary which loads thecdylib
via existing or separate entry point, thus not causing therlib
conflict.