Skip to content

Commit e25e994

Browse files
authored
Merge pull request #777 from godot-rust/feature/prepare-crates-2
Packaging preparations II
2 parents 4c8ea83 + 5b75729 commit e25e994

File tree

21 files changed

+422
-104
lines changed

21 files changed

+422
-104
lines changed

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

+1-12
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,8 @@ runs:
9595
PATCHED_VERSION: ${{ inputs.godot-prebuilt-patch }}
9696
# sed -i'' needed for macOS compatibility, see https://stackoverflow.com/q/4247068
9797
run: |
98-
# Find the godot4-prebuilt version that gdext currently depends on.
99-
defaultVersion=$(grep '^default =' "godot-bindings/Cargo.toml" | sed -n 's/.*prebuilt-\([0-9]*-[0-9]*\).*/\1/p' | tr '-' '.')
100-
if [ -z "$defaultVersion" ]; then
101-
echo "::error::prebuilt version not found or format is incorrect."
102-
exit 1
103-
else
104-
echo "Default prebuilt version: $defaultVersion"
105-
fi
106-
10798
# Specify `api-*` feature for godot crate if needed.
108-
if [[ "$PATCHED_VERSION" != $defaultVersion ]]; then
109-
.github/other/patch-prebuilt.sh "$PATCHED_VERSION"
110-
fi
99+
.github/other/patch-prebuilt.sh "$PATCHED_VERSION"
111100
112101
# Reduce versions to "major.minor" format.
113102
apiVersion=$(echo "$PATCHED_VERSION" | sed -E 's/([0-9]+\.[0-9]+)\.[0-9]+/\1/')

.github/other/apply-doc-cfg.sh

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
# Adds #[doc(cfg(...))] annotations to Rust docs, based on #[cfg(...)] in the source code.
8+
9+
# Keep in sync with the same file in website repo.
10+
11+
# Usage:
12+
# apply-doc-cfg.sh [--install-sd] [--rustfmt]
13+
14+
set -e
15+
16+
17+
for arg in "$@"; do
18+
case "$arg" in
19+
--install-sd)
20+
installSd="true"
21+
;;
22+
--rustfmt)
23+
rustfmt="true"
24+
;;
25+
*)
26+
echo "Unknown argument: $arg"
27+
exit 1
28+
;;
29+
esac
30+
done
31+
32+
SD_VERSION="1.0.0"
33+
PRE="DocCfg | "
34+
35+
# For gdext, add feature/cfg annotations in docs. This needs nightly rustdoc + custom preprocessing.
36+
# Replace #[cfg(...)] with #[doc(cfg(...))], a nightly feature: https://doc.rust-lang.org/unstable-book/language-features/doc-cfg.html
37+
# Potential alternative: https://docs.rs/doc-cfg/latest/doc_cfg
38+
if [[ "$installSd" == "true" ]]; then
39+
# Install sd (modern sed). No point in waiting for eternal `cargo install` if we can fetch a prebuilt binary in 1s.
40+
echo "$PRE install sd (modern sed)..."
41+
curl -L https://github.com/chmln/sd/releases/download/v${SD_VERSION}/sd-v${SD_VERSION}-x86_64-unknown-linux-musl.tar.gz -o archive.tar.gz
42+
mkdir -p /tmp/tools
43+
tar -zxvf archive.tar.gz -C /tmp/tools --strip-components=1
44+
sd=/tmp/tools/sd
45+
else
46+
sd=sd
47+
fi
48+
49+
echo "$PRE preprocess docs..."
50+
51+
# Enable feature in each lib.rs file.
52+
# Note: first command uses sed because it's easier, and only handful of files.
53+
find . -type f -name "lib.rs" -exec sed -i '1s/^/#![cfg_attr(published_docs, feature(doc_cfg))]\n/' {} +
54+
55+
# Then do the actual replacements.
56+
# Could use \( -path "..." -o -path "..." \) to limit to certain paths.
57+
# Do NOT include './target/debug/build/*' because generated files cannot be modified -- rustdoc will rerun the generation.
58+
# This is done by directly emitting #[cfg_attr(published_docs, doc(cfg(...)))] in the godot-codegen crate, and that cfg is passed below.
59+
find . -type f -name '*.rs' \
60+
\( -path './godot' -o -path './godot-*' \) \
61+
| while read -r file; do
62+
# Replace #[cfg(...)] with #[doc(cfg(...))]. Do not insert a newline, in case the #[cfg] is commented-out.
63+
# shellcheck disable=SC2016
64+
$sd '(\#\[(cfg\(.+?\))\])(\s*)([A-Za-z]|#\[)' '$1 #[cfg_attr(published_docs, doc($2))]$3$4' "$file"
65+
# $sd '(\#\[(cfg\(.+?\))\])\s*([A-Za-z]|#\[)' '$1 #[doc($2)]\n$3' "$file"
66+
# ^^^^^^^^^^^^^^^^^ require that #[cfg] is followed by an identifier or a #[ attribute start.
67+
# This avoids some usages of function-local #[cfg]s, although by far not all. Others generate warnings, which is fine.
68+
done
69+
70+
if [[ "$rustfmt" == "true" ]]; then
71+
echo "$PRE Format code using rustfmt..."
72+
cargo fmt --all
73+
fi
74+
75+
echo "$PRE Docs post-processed."

.github/other/update-version.sh

+17-5
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,25 @@
77
# Small utility to run update crate versions, used by godot-rust developers.
88

99
# No args specified: do everything.
10-
if [ "$#" -eq 0 ]; then
11-
echo "Usage: update-version.sh <newVersion>"
10+
if [[ "$#" -eq 0 ]]; then
11+
echo "Usage: update-version.sh <VER> [--no-tag]"
1212
exit 1
1313
fi
1414

1515
# --help menu
1616
args=("$@")
1717
for arg in "${args[@]}"; do
18-
if [ "$arg" == "--help" ]; then
19-
echo "Usage: update-version.sh <newVersion>"
18+
if [[ "$arg" == "--help" ]]; then
19+
echo "Usage: update-version.sh <VER> [--no-tag]"
2020
echo ""
2121
echo "Replaces currently published version with <newVersion>".
2222
echo "Does not git commit."
2323
exit 0
2424
fi
25+
26+
if [[ "$arg" == "--no-tag" ]]; then
27+
noTag="true"
28+
fi
2529
done
2630

2731
# Uncommitted changes, see https://stackoverflow.com/a/3879077.
@@ -39,6 +43,7 @@ mainCargoToml="$scriptPath/../../godot/Cargo.toml"
3943
newVersion="${args[0]}"
4044
oldVersion=$(grep -Po '^version = "\K[^"]*' "$mainCargoToml")
4145

46+
# Keep in sync with release-version.yml.
4247
publishedCrates=(
4348
"godot-bindings"
4449
"godot-codegen"
@@ -60,6 +65,13 @@ done
6065
sed -i "s!documentation = \"https://docs.rs/godot/$oldVersion\"!documentation = \"https://docs.rs/godot/$newVersion\"!g" "$mainCargoToml" || exit 2
6166

6267
git commit -am "Update crate version: $oldVersion -> $newVersion" || exit 2
63-
git tag "$newVersion" || exit 2
6468

69+
if [[ "$noTag" == "true" ]]; then
70+
echo "Skipped creating tag."
71+
else
72+
git tag "v$newVersion" || exit 2
73+
echo "Created tag v$newVersion."
74+
fi
75+
76+
echo ""
6577
echo "SUCCESS: Updated version $oldVersion -> $newVersion"

.github/workflows/full-ci.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ defaults:
3535
# cancel-in-progress: true
3636

3737
jobs:
38+
# Keep all in sync with minimal-ci and release-version.
3839
rustfmt:
3940
runs-on: ubuntu-20.04
4041
steps:
@@ -304,20 +305,20 @@ jobs:
304305
# If ever moving to ubuntu-latest, need to manually install libtinfo5 for LLVM.
305306

306307
# Uses full+experimental codegen, so that compatibility breakage towards nightly is detected.
307-
# If the experimental part causes problems, consider using only godot/codegen-full.
308+
# If the experimental part causes problems, consider using only godot/__codegen-full.
308309
- name: linux-full
309310
os: ubuntu-20.04
310311
artifact-name: linux-nightly
311312
godot-binary: godot.linuxbsd.editor.dev.x86_64
312-
rust-extra-args: --features godot/codegen-full
313+
rust-extra-args: --features godot/__codegen-full
313314
with-hot-reload: true
314315

315316
# Combines now a lot of features, but should be OK. lazy-function-tables doesn't work with experimental-threads.
316317
- name: linux-double-lazy
317318
os: ubuntu-20.04
318319
artifact-name: linux-double-nightly
319320
godot-binary: godot.linuxbsd.editor.dev.double.x86_64
320-
rust-extra-args: --features godot/api-custom,godot/double-precision,godot/codegen-full,godot/lazy-function-tables
321+
rust-extra-args: --features godot/api-custom,godot/double-precision,godot/__codegen-full,godot/lazy-function-tables
321322

322323
- name: linux-features-experimental
323324
os: ubuntu-20.04

.github/workflows/minimal-ci.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ jobs:
4646
- name: "Install Rust"
4747
uses: ./.github/composite/rust
4848
with:
49-
rust: stable
5049
components: rustfmt
5150

5251
- name: "Check rustfmt"
@@ -158,7 +157,7 @@ jobs:
158157
os: ubuntu-20.04
159158
artifact-name: linux-nightly
160159
godot-binary: godot.linuxbsd.editor.dev.x86_64
161-
rust-extra-args: --features godot/codegen-full
160+
rust-extra-args: --features godot/__codegen-full
162161
with-hot-reload: true
163162

164163
- name: linux-features-experimental

0 commit comments

Comments
 (0)