Skip to content

Commit 0bb3ada

Browse files
authored
Merge pull request #769 from godot-rust/feature/prepare-crates
Packaging preparations
2 parents 7559474 + 5f42a21 commit 0bb3ada

File tree

27 files changed

+399
-174
lines changed

27 files changed

+399
-174
lines changed

.github/other/update-version.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
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+
# Small utility to run update crate versions, used by godot-rust developers.
8+
9+
# No args specified: do everything.
10+
if [ "$#" -eq 0 ]; then
11+
echo "Usage: update-version.sh <newVersion>"
12+
exit 1
13+
fi
14+
15+
# --help menu
16+
args=("$@")
17+
for arg in "${args[@]}"; do
18+
if [ "$arg" == "--help" ]; then
19+
echo "Usage: update-version.sh <newVersion>"
20+
echo ""
21+
echo "Replaces currently published version with <newVersion>".
22+
echo "Does not git commit."
23+
exit 0
24+
fi
25+
done
26+
27+
# Uncommitted changes, see https://stackoverflow.com/a/3879077.
28+
#if git diff --quiet --exit-code; then
29+
git diff-index --quiet HEAD -- || {
30+
echo "Repo contains uncommitted changes; make sure working tree is clean."
31+
exit 1
32+
}
33+
34+
# https://stackoverflow.com/a/11114547
35+
scriptFile=$(realpath "$0")
36+
scriptPath=$(dirname "$scriptFile")
37+
mainCargoToml="$scriptPath/../../godot/Cargo.toml"
38+
39+
newVersion="${args[0]}"
40+
oldVersion=$(grep -Po '^version = "\K[^"]*' "$mainCargoToml")
41+
42+
publishedCrates=(
43+
"godot-bindings"
44+
"godot-codegen"
45+
"godot-ffi"
46+
"godot-cell"
47+
"godot-core"
48+
"godot-macros"
49+
"godot"
50+
)
51+
52+
for crate in "${publishedCrates[@]}"; do
53+
# Don't just replace version string itself -- the following only replaces the crate's own version
54+
# (with 'version = "1.2.3"') and dependencies with "=1.2.3", which makes false positives unlikely
55+
sed -i "s!version = \"${oldVersion}\"!version = \"${newVersion}\"!g" "$scriptPath/../../$crate/Cargo.toml" || exit 2
56+
sed -i "s!\"=${oldVersion}\"!\"=${newVersion}\"!g" "$scriptPath/../../$crate/Cargo.toml" || exit 2
57+
done
58+
59+
# For `godot` itself, update the `documentation` metadata.
60+
sed -i "s!documentation = \"https://docs.rs/godot/$oldVersion\"!documentation = \"https://docs.rs/godot/$newVersion\"!g" "$mainCargoToml" || exit 2
61+
62+
git commit -am "Update crate version: $oldVersion -> $newVersion" || exit 2
63+
git tag "$newVersion" || exit 2
64+
65+
echo "SUCCESS: Updated version $oldVersion -> $newVersion"

.github/workflows/update-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ jobs:
128128
echo "DOCS_GENERATOR_TOKEN=github_pat_$token" >> $GITHUB_ENV
129129
130130
- name: "Notify doc workflow"
131-
uses: peter-evans/repository-dispatch@v2
131+
uses: peter-evans/repository-dispatch@v3
132132
with:
133133
token: ${{ env.DOCS_GENERATOR_TOKEN }}
134134
repository: godot-rust/dispatch-forwarder

godot-bindings/Cargo.toml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ rust-version = "1.78"
66
license = "MPL-2.0"
77
keywords = ["gamedev", "godot", "engine", "ffi", "sys"]
88
categories = ["game-engines", "graphics"]
9+
description = "Internal crate used by godot-rust"
10+
repository = "https://github.com/godot-rust/gdext"
11+
homepage = "https://godot-rust.github.io"
912

1013
# Since features are additive, and we want the user to user prebuilt by default, we need to have `prebuilt-godot` as the
1114
# default feature. However, it's not possible to _disable_ the prebuilt dependency when specifying `api-custom` (without
@@ -40,20 +43,20 @@ api-custom-extheader = []
4043

4144
[dependencies]
4245
# [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" }
46+
# [line] prebuilt-$kebabVersion = { optional = true, package = "gdextension-api", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "$dotVersion" }
47+
prebuilt-4-0 = { optional = true, package = "gdextension-api", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.0" }
48+
prebuilt-4-0-1 = { optional = true, package = "gdextension-api", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.0.1" }
49+
prebuilt-4-0-2 = { optional = true, package = "gdextension-api", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.0.2" }
50+
prebuilt-4-0-3 = { optional = true, package = "gdextension-api", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.0.3" }
51+
prebuilt-4-0-4 = { optional = true, package = "gdextension-api", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.0.4" }
52+
prebuilt-4-1 = { optional = true, package = "gdextension-api", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.1" }
53+
prebuilt-4-1-1 = { optional = true, package = "gdextension-api", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.1.1" }
54+
prebuilt-4-1-2 = { optional = true, package = "gdextension-api", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.1.2" }
55+
prebuilt-4-1-3 = { optional = true, package = "gdextension-api", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.1.3" }
56+
prebuilt-4-1-4 = { optional = true, package = "gdextension-api", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.1.4" }
57+
prebuilt-4-2 = { optional = true, package = "gdextension-api", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.2" }
58+
prebuilt-4-2-1 = { optional = true, package = "gdextension-api", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.2.1" }
59+
prebuilt-4-2-2 = { optional = true, package = "gdextension-api", git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.2.2" }
5760
# ]]
5861

5962
# Do not use bindgen 0.69, it contains regression that forces recompilation of code.

godot-bindings/src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
66
*/
77

8+
//! # Internal crate of [**godot-rust**](https://godot-rust.github.io)
9+
//!
10+
//! Do not depend on this crate directly, instead use the `godot` crate.
11+
//! No SemVer or other guarantees are provided.
12+
813
pub(crate) mod watch;
914

1015
use std::path::Path;
@@ -97,9 +102,12 @@ mod depend_on_prebuilt {
97102
}
98103

99104
pub(crate) fn get_godot_version() -> GodotVersion {
100-
let version: Vec<&str> = prebuilt::GODOT_VERSION.split('.').collect::<Vec<_>>();
105+
let version: Vec<&str> = prebuilt::GODOT_VERSION_STRING
106+
.split('.')
107+
.collect::<Vec<_>>();
108+
101109
GodotVersion {
102-
full_string: prebuilt::GODOT_VERSION.into(),
110+
full_string: prebuilt::GODOT_VERSION_STRING.to_string(),
103111
major: version[0].parse().unwrap(),
104112
minor: version[1].parse().unwrap(),
105113
patch: version

godot-cell/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ rust-version = "1.78"
66
license = "MPL-2.0"
77
keywords = ["gamedev", "godot", "engine", "ffi"]
88
categories = ["game-engines", "graphics"]
9+
description = "Internal crate used by godot-rust"
10+
repository = "https://github.com/godot-rust/gdext"
11+
homepage = "https://godot-rust.github.io"
912

1013
[features]
1114
proptest = ["dep:proptest"]

godot-cell/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
66
*/
77

8+
//! # Internal crate of [**godot-rust**](https://godot-rust.github.io)
9+
//!
10+
//! Do not depend on this crate directly, instead use the `godot` crate.
11+
//! No SemVer or other guarantees are provided.
12+
//!
13+
//! # Contributor docs
14+
//!
815
//! A re-entrant cell implementation which allows for `&mut` references to be reborrowed even while `&mut`
916
//! references still exist.
1017
//!

godot-codegen/Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@ rust-version = "1.78"
66
license = "MPL-2.0"
77
keywords = ["gamedev", "godot", "engine", "codegen"]
88
categories = ["game-engines", "graphics"]
9+
description = "Internal crate used by godot-rust"
10+
repository = "https://github.com/godot-rust/gdext"
11+
homepage = "https://godot-rust.github.io"
912

1013
[features]
11-
default = ["codegen-fmt"]
12-
codegen-fmt = []
14+
default = []
1315
codegen-full = []
1416
codegen-lazy-fptrs = []
17+
codegen-rustfmt = []
1518
double-precision = []
1619
api-custom = ["godot-bindings/api-custom"]
1720
experimental-godot-api = []
1821

1922
[dependencies]
20-
godot-bindings = { path = "../godot-bindings" }
23+
godot-bindings = { path = "../godot-bindings", version = "=0.1.0" }
2124

2225
heck = "0.4"
2326
nanoserde = "0.1.35"
@@ -31,7 +34,7 @@ quote = "1.0.29"
3134
regex = { version = "1.5.5", default-features = false, features = ["std", "unicode-bool", "unicode-gencat"] }
3235

3336
[build-dependencies]
34-
godot-bindings = { path = "../godot-bindings" } # emit_godot_version_cfg
37+
godot-bindings = { path = "../godot-bindings", version = "=0.1.0" } # emit_godot_version_cfg
3538

3639
# https://docs.rs/about/metadata
3740
[package.metadata.docs.rs]

godot-codegen/src/formatter/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
66
*/
77

8-
#![cfg(feature = "codegen-fmt")]
8+
#![cfg(not(feature = "codegen-rustfmt"))]
99

1010
use proc_macro2::{Delimiter, Spacing, TokenStream, TokenTree};
1111

@@ -37,7 +37,7 @@ use proc_macro2::{Delimiter, Spacing, TokenStream, TokenTree};
3737
/// - anonymous function literals are a bit weird because the `|` don't have
3838
/// joint spacing when they come out of a `TokenStream` and identifiers don't
3939
/// have any spacing information attached, so it looks like `| arg |`.
40-
/// Also to know whether it's a chained bitwise or a closure would need more
40+
/// Also, to know whether it's a chained bitwise or, a closure would need more
4141
/// information. `move | arg | x`
4242
/// - Because we don't keep track of what's a type and what's an expression,
4343
/// generic parameters look a bit spaced out. `T < A, B >`

godot-codegen/src/generator/enums.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ pub(crate) fn make_deprecated_enumerators(enum_: &Enum) -> TokenStream {
354354

355355
let decl = quote! {
356356
#[deprecated = #msg]
357+
#[doc(hidden)] // No longer advertise in API docs.
357358
pub const #pascal_name: #enum_name = Self::#name;
358359
};
359360

godot-codegen/src/lib.rs

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
66
*/
77

8+
//! # Internal crate of [**godot-rust**](https://godot-rust.github.io)
9+
//!
10+
//! Do not depend on this crate directly, instead use the `godot` crate.
11+
//! No SemVer or other guarantees are provided.
12+
813
// Codegen has no FFI and thus no reason to use unsafe code.
914
#![forbid(unsafe_code)]
1015

@@ -46,16 +51,47 @@ fn write_file(path: &Path, contents: String) {
4651
.unwrap_or_else(|e| panic!("failed to write code file to {};\n\t{}", path.display(), e));
4752
}
4853

49-
#[cfg(feature = "codegen-fmt")]
54+
#[cfg(not(feature = "codegen-rustfmt"))]
5055
fn submit_fn(path: PathBuf, tokens: TokenStream) {
5156
write_file(&path, formatter::format_tokens(tokens));
5257
}
5358

54-
#[cfg(not(feature = "codegen-fmt"))]
55-
fn submit_fn(path: PathBuf, tokens: TokenStream) {
56-
write_file(&path, tokens.to_string());
59+
#[cfg(feature = "codegen-rustfmt")]
60+
mod rustfmt {
61+
use super::*;
62+
use std::process::Command;
63+
use std::sync::Mutex;
64+
65+
pub fn submit_fn(path: PathBuf, tokens: TokenStream) {
66+
write_file(&path, tokens.to_string());
67+
FILES_TO_RUSTFMT.lock().unwrap().push(path);
68+
}
69+
70+
pub fn rustfmt_files() {
71+
let out_files = FILES_TO_RUSTFMT.lock().unwrap();
72+
println!("Format {} generated files...", out_files.len());
73+
74+
for files in out_files.chunks(20) {
75+
let mut command = Command::new("rustfmt");
76+
for file in files {
77+
command.arg(file);
78+
}
79+
80+
let status = command.status().expect("failed to invoke rustfmt");
81+
if !status.success() {
82+
panic!("rustfmt failed on {:?}", command);
83+
}
84+
}
85+
86+
println!("Rustfmt completed successfully");
87+
}
88+
89+
static FILES_TO_RUSTFMT: Mutex<Vec<PathBuf>> = Mutex::new(Vec::new());
5790
}
5891

92+
#[cfg(feature = "codegen-rustfmt")]
93+
pub(crate) use rustfmt::*;
94+
5995
pub fn generate_sys_files(
6096
sys_gen_path: &Path,
6197
h_path: &Path,
@@ -94,6 +130,12 @@ pub fn generate_sys_files(
94130

95131
generate_sys_module_file(sys_gen_path, &mut submit_fn);
96132
watch.record("generate_module_file");
133+
134+
#[cfg(feature = "codegen-rustfmt")]
135+
{
136+
rustfmt_files();
137+
watch.record("rustfmt");
138+
}
97139
}
98140

99141
pub fn generate_core_files(core_gen_path: &Path) {
@@ -146,5 +188,11 @@ pub fn generate_core_files(core_gen_path: &Path) {
146188
);
147189
watch.record("generate_native_structures_files");
148190

191+
#[cfg(feature = "codegen-rustfmt")]
192+
{
193+
rustfmt_files();
194+
watch.record("rustfmt");
195+
}
196+
149197
watch.write_stats_to(&core_gen_path.join("codegen-stats.txt"));
150198
}

0 commit comments

Comments
 (0)