From 62059bb923b9b6791d193d9fb34d9b5e3c43fe2f Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Mon, 24 Feb 2025 21:45:12 +0100 Subject: [PATCH] Move some compile-time validations from godot to godot-ffi --- godot-ffi/src/lib.rs | 19 +++++++++++++++++++ godot/src/lib.rs | 17 ++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/godot-ffi/src/lib.rs b/godot-ffi/src/lib.rs index e2ea0f9e5..d5ee1f52d 100644 --- a/godot-ffi/src/lib.rs +++ b/godot-ffi/src/lib.rs @@ -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( diff --git a/godot/src/lib.rs b/godot/src/lib.rs index 44d84c479..bbe33ef6e 100644 --- a/godot/src/lib.rs +++ b/godot/src/lib.rs @@ -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