Skip to content

Commit e1f1ce3

Browse files
authored
Merge pull request #740 from godot-rust/qol/cfg-cleanup
`api-4-x-y` features; automated version sync; `#[cfg]` cleanup.
2 parents e4603ce + 8b9a1a3 commit e1f1ce3

File tree

21 files changed

+592
-157
lines changed

21 files changed

+592
-157
lines changed

.github/composite/godot-itest/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ runs:
104104
echo "Default prebuilt version: $defaultVersion"
105105
fi
106106
107-
# Apply [patch] for godot4-prebuilt crate if needed.
107+
# Specify `api-*` feature for godot crate if needed.
108108
if [[ "$PATCHED_VERSION" != $defaultVersion ]]; then
109109
.github/other/patch-prebuilt.sh "$PATCHED_VERSION"
110110
fi

.github/other/patch-prebuilt.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ if [[ "$version" == "nightly" ]]; then
1414
# Do not use extraFeatures="api-custom" here. They just want to use nightly Godot with current API.
1515
extraFeatures=""
1616
else
17-
# Extract "major.minor" from "major.minor[.patch]".
18-
dashedVersion=$(echo "$version" | cut -d '.' -f 1,2 | sed 's/\./-/')
17+
# Extract "major.minor" from "major.minor[.patch]" -- disabled.
18+
# dashedVersion=$(echo "$version" | cut -d '.' -f 1,2 | sed 's/\./-/')
19+
20+
# Convert . to - for feature name.
21+
dashedVersion="${version//./-}"
1922
extraFeatures=", \"api-$dashedVersion\""
2023
fi
2124

.github/workflows/full-ci.yml

+13-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ jobs:
4848
- name: "Check rustfmt"
4949
run: cargo fmt --all -- --check
5050

51+
- name: "Run custom repo checks"
52+
run: |
53+
cargo run -p repo-tweak
54+
git diff --quiet --exit-code || {
55+
echo "::error::Godot versions out of sync; update with `cargo run -p repo-tweak`."
56+
echo "Differences:"
57+
echo "----------------------------------------------------"
58+
git diff
59+
echo "----------------------------------------------------"
60+
exit 1
61+
}
62+
5163
5264
# Needs to be its own job (apart from sync-doc), because lints don't work with --no-deps, and because it contributes to ci-status.
5365
doc-lints:
@@ -362,7 +374,7 @@ jobs:
362374
os: ubuntu-20.04
363375
artifact-name: linux-memcheck-4.1
364376
godot-binary: godot.linuxbsd.editor.dev.x86_64.llvm.san
365-
godot-prebuilt-patch: '4.1.4'
377+
godot-prebuilt-patch: '4.1' # check compat of API 4.1.0 with newer binaries.
366378
rust-toolchain: nightly
367379
rust-env-rustflags: -Zrandomize-layout -Zsanitizer=address
368380
# Sanitizers can't build proc-macros and build scripts; with --target, cargo ignores RUSTFLAGS for those two.

.github/workflows/minimal-ci.yml

+11
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ jobs:
5252
- name: "Check rustfmt"
5353
run: cargo fmt --all -- --check
5454

55+
- name: "Run custom repo checks"
56+
run: |
57+
cargo run -p repo-tweak
58+
git diff --quiet --exit-code || {
59+
echo "::error::Godot versions out of sync; update with `cargo run -p repo-tweak`."
60+
echo "Differences:"
61+
echo "----------------------------------------------------"
62+
git diff
63+
echo "----------------------------------------------------"
64+
exit 1
65+
}
5566
5667
# Needs to be its own job (apart from sync-doc), because lints don't work with --no-deps, and because it contributes to ci-status.
5768
doc-lints:

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ members = [
1111

1212
# Godot integration
1313
"itest/rust",
14+
"itest/repo-tweak",
1415
"examples/dodge-the-creeps/rust",
1516
"examples/hot-reload/rust",
1617
]

godot-bindings/Cargo.toml

+39-6
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,49 @@ categories = ["game-engines", "graphics"]
1212
# requiring no-default-features), so we unfortunately still need to depend on prebuilt and just ignore it.
1313
# The artifact generator explicitly excludes that though (to avoid a quasi-circular dependency back to its repo).
1414
[features]
15+
# [version-sync] [[
16+
# [line] api-$kebabVersion = ["dep:prebuilt-$kebabVersion"]
1517
api-4-0 = ["dep:prebuilt-4-0"]
18+
api-4-0-1 = ["dep:prebuilt-4-0-1"]
19+
api-4-0-2 = ["dep:prebuilt-4-0-2"]
20+
api-4-0-3 = ["dep:prebuilt-4-0-3"]
21+
api-4-0-4 = ["dep:prebuilt-4-0-4"]
1622
api-4-1 = ["dep:prebuilt-4-1"]
23+
api-4-1-1 = ["dep:prebuilt-4-1-1"]
24+
api-4-1-2 = ["dep:prebuilt-4-1-2"]
25+
api-4-1-3 = ["dep:prebuilt-4-1-3"]
26+
api-4-1-4 = ["dep:prebuilt-4-1-4"]
27+
api-4-2 = ["dep:prebuilt-4-2"]
28+
api-4-2-1 = ["dep:prebuilt-4-2-1"]
29+
api-4-2-2 = ["dep:prebuilt-4-2-2"]
30+
# ]]
31+
32+
# [version-sync] [[
33+
# [include] current.minor
34+
# [line] default = ["dep:prebuilt-$kebabVersion"]
1735
default = ["dep:prebuilt-4-2"]
36+
# ]]
37+
1838
api-custom = ["dep:bindgen", "dep:regex", "dep:which"]
1939
api-custom-extheader = []
2040

21-
2241
[dependencies]
23-
prebuilt-4-0 = { optional = true, package = "godot4-prebuilt", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.0.4" }
24-
prebuilt-4-1 = { optional = true, package = "godot4-prebuilt", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.1.4" }
25-
prebuilt-4-2 = { optional = true, package = "godot4-prebuilt", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.2.2" }
42+
# [version-sync] [[
43+
# [line] prebuilt-$kebabVersion = { optional = true, package = "godot4-prebuilt", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "$dotVersion" }
44+
prebuilt-4-0 = { optional = true, package = "godot4-prebuilt", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.0" }
45+
prebuilt-4-0-1 = { optional = true, package = "godot4-prebuilt", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.0.1" }
46+
prebuilt-4-0-2 = { optional = true, package = "godot4-prebuilt", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.0.2" }
47+
prebuilt-4-0-3 = { optional = true, package = "godot4-prebuilt", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.0.3" }
48+
prebuilt-4-0-4 = { optional = true, package = "godot4-prebuilt", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.0.4" }
49+
prebuilt-4-1 = { optional = true, package = "godot4-prebuilt", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.1" }
50+
prebuilt-4-1-1 = { optional = true, package = "godot4-prebuilt", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.1.1" }
51+
prebuilt-4-1-2 = { optional = true, package = "godot4-prebuilt", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.1.2" }
52+
prebuilt-4-1-3 = { optional = true, package = "godot4-prebuilt", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.1.3" }
53+
prebuilt-4-1-4 = { optional = true, package = "godot4-prebuilt", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.1.4" }
54+
prebuilt-4-2 = { optional = true, package = "godot4-prebuilt", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.2" }
55+
prebuilt-4-2-1 = { optional = true, package = "godot4-prebuilt", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.2.1" }
56+
prebuilt-4-2-2 = { optional = true, package = "godot4-prebuilt", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.2.2" }
57+
# ]]
2658

2759
# Do not use bindgen 0.69, it contains regression that forces recompilation of code.
2860
bindgen = { optional = true, version = "0.68", default-features = false, features = ["runtime"] }
@@ -40,5 +72,6 @@ regex = { version = "1.5.5", default-features = false, features = ["std", "unico
4072
features = ["experimental-godot-api"]
4173
rustdoc-args = ["--cfg", "published_docs"]
4274

43-
[lints.rust]
44-
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(published_docs)'] }
75+
# Currently causes "unused manifest key" warnings. Maybe re-enable in the future, to make `published_docs` known.
76+
#[lints.rust]
77+
#unexpected_cfgs = { level = "warn", check-cfg = ['cfg(published_docs)'] }

godot-bindings/src/import.rs

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
//! Versions to be updated whenever Godot releases a new patch version we support.
9+
//!
10+
//! This file contains several templating comments, who are substituted by the machinery itest/repo-tweak.
11+
//! When modifying those, make sure to rerun.
12+
13+
/// All stable Godot releases _and_ upcoming next minor release.
14+
pub const ALL_VERSIONS: &[(u8, u8, u8)] = &[
15+
// [version-sync] [[
16+
// [include] past+current+future
17+
// [line] \t$triple,
18+
(4, 0, 0),
19+
(4, 0, 1),
20+
(4, 0, 2),
21+
(4, 0, 3),
22+
(4, 0, 4),
23+
(4, 1, 0),
24+
(4, 1, 1),
25+
(4, 1, 2),
26+
(4, 1, 3),
27+
(4, 1, 4),
28+
(4, 2, 0),
29+
(4, 2, 1),
30+
(4, 2, 2),
31+
(4, 3, 0),
32+
// ]]
33+
];
34+
35+
// [version-sync] [[
36+
// [line] #[cfg(feature = "api-$kebabVersion")]\npub use prebuilt_$snakeVersion as prebuilt;\n
37+
#[cfg(feature = "api-4-0")]
38+
pub use prebuilt_4_0 as prebuilt;
39+
40+
#[cfg(feature = "api-4-0-1")]
41+
pub use prebuilt_4_0_1 as prebuilt;
42+
43+
#[cfg(feature = "api-4-0-2")]
44+
pub use prebuilt_4_0_2 as prebuilt;
45+
46+
#[cfg(feature = "api-4-0-3")]
47+
pub use prebuilt_4_0_3 as prebuilt;
48+
49+
#[cfg(feature = "api-4-0-4")]
50+
pub use prebuilt_4_0_4 as prebuilt;
51+
52+
#[cfg(feature = "api-4-1")]
53+
pub use prebuilt_4_1 as prebuilt;
54+
55+
#[cfg(feature = "api-4-1-1")]
56+
pub use prebuilt_4_1_1 as prebuilt;
57+
58+
#[cfg(feature = "api-4-1-2")]
59+
pub use prebuilt_4_1_2 as prebuilt;
60+
61+
#[cfg(feature = "api-4-1-3")]
62+
pub use prebuilt_4_1_3 as prebuilt;
63+
64+
#[cfg(feature = "api-4-1-4")]
65+
pub use prebuilt_4_1_4 as prebuilt;
66+
67+
#[cfg(feature = "api-4-2")]
68+
pub use prebuilt_4_2 as prebuilt;
69+
70+
#[cfg(feature = "api-4-2-1")]
71+
pub use prebuilt_4_2_1 as prebuilt;
72+
73+
#[cfg(feature = "api-4-2-2")]
74+
pub use prebuilt_4_2_2 as prebuilt;
75+
76+
// ]]
77+
78+
// If none of the api-* features are provided, use default prebuilt version (typically latest Godot stable release).
79+
80+
// [version-sync] [[
81+
// [line] \tfeature = "api-$kebabVersion",
82+
// [pre] #[cfg(not(any(
83+
// [post] \tfeature = "api-custom",\n)))]
84+
#[cfg(not(any(
85+
feature = "api-4-0",
86+
feature = "api-4-0-1",
87+
feature = "api-4-0-2",
88+
feature = "api-4-0-3",
89+
feature = "api-4-0-4",
90+
feature = "api-4-1",
91+
feature = "api-4-1-1",
92+
feature = "api-4-1-2",
93+
feature = "api-4-1-3",
94+
feature = "api-4-1-4",
95+
feature = "api-4-2",
96+
feature = "api-4-2-1",
97+
feature = "api-4-2-2",
98+
feature = "api-custom",
99+
)))]
100+
// ]]
101+
102+
// [version-sync] [[
103+
// [include] current.minor
104+
// [line] pub use prebuilt_$snakeVersion as prebuilt;
105+
pub use prebuilt_4_2 as prebuilt;
106+
// ]]

0 commit comments

Comments
 (0)