Skip to content

Commit f7ca84f

Browse files
committed
Add docs for #[gdextension(entry_symbol)] key (now renamed from entry_point)
1 parent 6e23bb9 commit f7ca84f

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
lines changed

godot-core/src/deprecated.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,22 @@ pub use crate::emit_deprecated_warning;
3838
// Library-side deprecations
3939

4040
#[deprecated = "\nThe attribute key #[init(val = ...)] replaces #[init(default = ...)].\n\
41-
More information on https://github.com/godot-rust/gdext/pull/844."]
41+
More information on https://github.com/godot-rust/gdext/pull/844"]
4242
pub const fn init_default() {}
4343

4444
#[deprecated = "\nThe attribute key #[class(editor_plugin)] is now implied by #[class(base = EditorPlugin)]. It is ignored.\n\
45-
More information on https://github.com/godot-rust/gdext/pull/884."]
45+
More information on https://github.com/godot-rust/gdext/pull/884"]
4646
pub const fn class_editor_plugin() {}
4747

4848
#[deprecated = "\nThe attribute key #[class(hidden)] has been renamed to #[class(internal)], following Godot terminology.\n\
49-
More information on https://github.com/godot-rust/gdext/pull/884."]
49+
More information on https://github.com/godot-rust/gdext/pull/884"]
5050
pub const fn class_hidden() {}
5151

52+
#[deprecated = "\nThe attribute key #[gdextension(entry_point)] has been renamed to #[gdextension(entry_symbol)], for consistency \
53+
with the configuration key in the .gdextension file.\n\
54+
More information on https://github.com/godot-rust/gdext/pull/959"]
55+
pub const fn gdextension_entry_point() {}
56+
5257
// ----------------------------------------------------------------------------------------------------------------------------------------------
5358
// Godot-side deprecations
5459

godot-core/src/init/mod.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,14 @@ fn gdext_on_level_deinit(level: InitLevel) {
184184
/// Every library should have exactly one implementation of this trait. It is always used in combination with the
185185
/// [`#[gdextension]`][gdextension] proc-macro attribute.
186186
///
187+
/// # Example
187188
/// The simplest usage is as follows. This will automatically perform the necessary init and cleanup routines, and register
188189
/// all classes marked with `#[derive(GodotClass)]`, without needing to mention them in a central list. The order in which
189190
/// classes are registered is not specified.
190191
///
191192
/// ```
192-
/// # use godot::init::*;
193+
/// use godot::init::*;
194+
///
193195
/// // This is just a type tag without any functionality.
194196
/// // Its name is irrelevant.
195197
/// struct MyExtension;
@@ -198,10 +200,25 @@ fn gdext_on_level_deinit(level: InitLevel) {
198200
/// unsafe impl ExtensionLibrary for MyExtension {}
199201
/// ```
200202
///
201-
/// # Safety
202-
/// By using godot-rust, you accept the safety considerations [as outlined in the book][safety].
203-
/// Please make sure you fully understand the implications.
203+
/// # Custom entry symbol
204+
/// There is usually no reason to, but you can use a different entry point (C function in the dynamic library). This must match the key
205+
/// that you specify in the `.gdextension` file. Let's say your `.gdextension` file has such a section:
206+
/// ```toml
207+
/// [configuration]
208+
/// entry_symbol = "custom_name"
209+
/// ```
210+
/// then you can implement the trait like this:
211+
/// ```no_run
212+
/// # use godot::init::*;
213+
/// struct MyExtension;
204214
///
215+
/// #[gdextension(entry_symbol = custom_name)]
216+
/// unsafe impl ExtensionLibrary for MyExtension {}
217+
/// ```
218+
/// Note that this only changes the name. You cannot provide your own function -- use the [`on_level_init()`][ExtensionLibrary::on_level_init]
219+
/// hook for custom startup logic.
220+
///
221+
/// # Safety
205222
/// The library cannot enforce any safety guarantees outside Rust code, which means that **you as a user** are
206223
/// responsible to uphold them: namely in GDScript code or other GDExtension bindings loaded by the engine.
207224
/// Violating this may cause undefined behavior, even when invoking _safe_ functions.

godot-macros/src/gdextension.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,30 @@ pub fn attribute_gdextension(item: venial::Item) -> ParseResult<TokenStream> {
2828
let drained_attributes = std::mem::take(&mut impl_decl.attributes);
2929
let mut parser = KvParser::parse_required(&drained_attributes, "gdextension", &impl_decl)?;
3030
let entry_point = parser.handle_ident("entry_point")?;
31+
let entry_symbol = parser.handle_ident("entry_symbol")?;
3132
parser.finish()?;
3233

33-
let entry_point = entry_point.unwrap_or_else(|| ident("gdext_rust_init"));
34+
if entry_point.is_some() && entry_symbol.is_some() {
35+
return bail!(
36+
impl_decl.tk_impl,
37+
"Cannot specify both `entry_point` and `entry_symbol` in #[gdextension] attribute",
38+
);
39+
}
40+
41+
let deprecation = if entry_point.is_some() {
42+
quote! { ::godot::__deprecated::emit_deprecated_warning!(gdextension_entry_point); }
43+
} else {
44+
TokenStream::new()
45+
};
46+
47+
let entry_point = entry_symbol
48+
.or(entry_point)
49+
.unwrap_or_else(|| ident("gdext_rust_init"));
50+
3451
let impl_ty = &impl_decl.self_ty;
3552

3653
Ok(quote! {
54+
#deprecation
3755
#impl_decl
3856

3957
// This cfg cannot be checked from the outer proc-macro since its 'target' is the build

itest/rust/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mod register_tests;
1818
// ----------------------------------------------------------------------------------------------------------------------------------------------
1919
// Entry point
2020

21-
#[gdextension(entry_point=itest_init)]
21+
#[gdextension(entry_symbol = itest_init)]
2222
unsafe impl ExtensionLibrary for framework::IntegrationTests {
2323
fn on_level_init(level: InitLevel) {
2424
// Testing that we can initialize and use `Object`-derived classes during `Servers` init level. See `object_tests::init_level_test`.

0 commit comments

Comments
 (0)