Skip to content

Commit 01678e5

Browse files
authored
Merge pull request #809 from godot-rust/bugfix/api-exclusivity-check
Fix validation for `api-*` mutual exclusivity
2 parents 421324a + a267495 commit 01678e5

File tree

4 files changed

+44
-22
lines changed

4 files changed

+44
-22
lines changed

godot-bindings/build.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) godot-rust; Bromeon and contributors.
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
// `api-*` validation is required here because otherwise, user gets confusing error about conflicting module imports.
9+
// We can also not use this in dependent crates, e.g. in godot/build.rs, since this crate is compiled before and already causes the error.
10+
// It's the only purpose of this build.rs file. If a better solution is found, this file can be removed.
11+
12+
#[rustfmt::skip]
13+
fn main() {
14+
let mut count = 0;
15+
if cfg!(feature = "api-custom") { count += 1; }
16+
17+
// [version-sync] [[
18+
// [line] \tif cfg!(feature = "api-$kebabVersion") { count += 1; }
19+
if cfg!(feature = "api-4-0") { count += 1; }
20+
if cfg!(feature = "api-4-0-1") { count += 1; }
21+
if cfg!(feature = "api-4-0-2") { count += 1; }
22+
if cfg!(feature = "api-4-0-3") { count += 1; }
23+
if cfg!(feature = "api-4-0-4") { count += 1; }
24+
if cfg!(feature = "api-4-1") { count += 1; }
25+
if cfg!(feature = "api-4-1-1") { count += 1; }
26+
if cfg!(feature = "api-4-1-2") { count += 1; }
27+
if cfg!(feature = "api-4-1-3") { count += 1; }
28+
if cfg!(feature = "api-4-1-4") { count += 1; }
29+
if cfg!(feature = "api-4-2") { count += 1; }
30+
if cfg!(feature = "api-4-2-1") { count += 1; }
31+
if cfg!(feature = "api-4-2-2") { count += 1; }
32+
// ]]
33+
34+
assert!(count <= 1, "ERROR: at most one `api-*` feature can be enabled");
35+
}

godot-cell/src/borrow_state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
/// This state upholds these invariants:
1111
/// - You can only take a shared borrow when there is no accessible mutable borrow.
1212
/// - You can only take a mutable borrow when there is neither an accessible mutable borrow, nor a shared
13-
/// borrow.
13+
/// borrow.
1414
/// - You can only set a mutable borrow as inaccessible when an accessible mutable borrow exists.
1515
/// - You can only unset a mutable borrow as inaccessible when there is no accessible mutable borrow and no
16-
/// shared borrows.
16+
/// shared borrows.
1717
///
1818
/// If a catastrophic error occurs, then the state will be poisoned. If the state is poisoned then that's
1919
/// almost certainly an implementation bug, and should never happen. But in an abundance of caution it is

godot-core/src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ pub mod tools;
3232
mod storage;
3333
pub use godot_ffi as sys;
3434

35+
// ----------------------------------------------------------------------------------------------------------------------------------------------
36+
// Validations (see also godot/lib.rs)
37+
38+
#[cfg(all(feature = "docs", before_api = "4.3"))]
39+
compile_error!("Generating editor docs for Rust symbols requires at least Godot 4.3.");
40+
3541
// ----------------------------------------------------------------------------------------------------------------------------------------------
3642
// Generated code
3743

godot/src/lib.rs

+1-20
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,7 @@ compile_error!("Must opt-in using `experimental-wasm` Cargo feature; keep in min
148148
#[cfg(all(feature = "double-precision", not(feature = "api-custom")))]
149149
compile_error!("The feature `double-precision` currently requires `api-custom` due to incompatibilities in the GDExtension API JSON.");
150150

151-
#[cfg(all(feature = "register-docs", before_api = "4.3"))]
152-
compile_error!("Generating editor docs for Rust symbols requires at least Godot 4.3.");
153-
154-
const fn _validate_features() {
155-
let mut count = 0;
156-
157-
if cfg!(feature = "api-4-0") {
158-
count += 1;
159-
}
160-
if cfg!(feature = "api-4-1") {
161-
count += 1;
162-
}
163-
if cfg!(feature = "api-custom") {
164-
count += 1;
165-
}
166-
167-
assert!(count <= 1, "at most one `api-*` feature can be enabled");
168-
}
169-
170-
const _: () = _validate_features();
151+
// Note: #[cfg]s are not emitted in this crate, so move checks for those up to godot-core.
171152

172153
// ----------------------------------------------------------------------------------------------------------------------------------------------
173154
// Modules

0 commit comments

Comments
 (0)