Skip to content

Commit

Permalink
Merge pull request #1058 from godot-rust/bugfix/compile-time-validations
Browse files Browse the repository at this point in the history
Move some compile-time validations from godot to godot-ffi
  • Loading branch information
Bromeon authored Feb 24, 2025
2 parents 5b09d29 + 62059bb commit ceb7776
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
19 changes: 19 additions & 0 deletions godot-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@
#![cfg_attr(test, allow(unused))]

// ----------------------------------------------------------------------------------------------------------------------------------------------
// Validations

// More validations in godot crate. #[cfg]s are checked in godot-core.

#[cfg(all(feature = "codegen-lazy-fptrs", feature = "experimental-threads"))]
compile_error!(
"Cannot combine `lazy-function-tables` and `experimental-threads` features;\n\
thread safety for lazy-loaded function pointers is not yet implemented."
);

#[cfg(all(
feature = "experimental-wasm-nothreads",
feature = "experimental-threads"
))]
compile_error!("Cannot use 'experimental-threads' with a nothreads Wasm build yet.");

// ----------------------------------------------------------------------------------------------------------------------------------------------

// Output of generated code. Mimics the file structure, symbols are re-exported.
#[rustfmt::skip]
#[allow(
Expand Down
17 changes: 6 additions & 11 deletions godot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,19 @@ pub mod __docs;
// ----------------------------------------------------------------------------------------------------------------------------------------------
// Validations

#[cfg(all(feature = "lazy-function-tables", feature = "experimental-threads"))]
compile_error!("Thread safety for lazy function pointers is not yet implemented.");

#[cfg(all(
feature = "experimental-wasm-nothreads",
feature = "experimental-threads"
))]
compile_error!("Cannot use 'experimental-threads' with a nothreads Wasm build yet.");
// Many validations are moved to godot-ffi. #[cfg]s are not emitted in this crate, so move checks for those up to godot-core.

#[cfg(all(target_family = "wasm", not(feature = "experimental-wasm")))]
compile_error!("Must opt-in using `experimental-wasm` Cargo feature; keep in mind that this is work in progress");
compile_error!(
"Wasm target requires opt-in via `experimental-wasm` Cargo feature;\n\
keep in mind that this is work in progress."
);

// See also https://github.com/godotengine/godot/issues/86346.
// Could technically be moved to godot-codegen to reduce time-to-failure slightly, but would scatter validations even more.
#[cfg(all(feature = "double-precision", not(feature = "api-custom")))]
compile_error!("The feature `double-precision` currently requires `api-custom` due to incompatibilities in the GDExtension API JSON.");

// Note: #[cfg]s are not emitted in this crate, so move checks for those up to godot-core.

// ----------------------------------------------------------------------------------------------------------------------------------------------
// Modules

Expand Down

0 comments on commit ceb7776

Please sign in to comment.