Skip to content

Commit

Permalink
Merge pull request #777 from godot-rust/feature/prepare-crates-2
Browse files Browse the repository at this point in the history
Packaging preparations II
  • Loading branch information
Bromeon authored Jun 24, 2024
2 parents 4c8ea83 + 5b75729 commit e25e994
Show file tree
Hide file tree
Showing 21 changed files with 422 additions and 104 deletions.
13 changes: 1 addition & 12 deletions .github/composite/godot-itest/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,8 @@ runs:
PATCHED_VERSION: ${{ inputs.godot-prebuilt-patch }}
# sed -i'' needed for macOS compatibility, see https://stackoverflow.com/q/4247068
run: |
# Find the godot4-prebuilt version that gdext currently depends on.
defaultVersion=$(grep '^default =' "godot-bindings/Cargo.toml" | sed -n 's/.*prebuilt-\([0-9]*-[0-9]*\).*/\1/p' | tr '-' '.')
if [ -z "$defaultVersion" ]; then
echo "::error::prebuilt version not found or format is incorrect."
exit 1
else
echo "Default prebuilt version: $defaultVersion"
fi
# Specify `api-*` feature for godot crate if needed.
if [[ "$PATCHED_VERSION" != $defaultVersion ]]; then
.github/other/patch-prebuilt.sh "$PATCHED_VERSION"
fi
.github/other/patch-prebuilt.sh "$PATCHED_VERSION"
# Reduce versions to "major.minor" format.
apiVersion=$(echo "$PATCHED_VERSION" | sed -E 's/([0-9]+\.[0-9]+)\.[0-9]+/\1/')
Expand Down
75 changes: 75 additions & 0 deletions .github/other/apply-doc-cfg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash
# Copyright (c) godot-rust; Bromeon and contributors.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

# Adds #[doc(cfg(...))] annotations to Rust docs, based on #[cfg(...)] in the source code.

# Keep in sync with the same file in website repo.

# Usage:
# apply-doc-cfg.sh [--install-sd] [--rustfmt]

set -e


for arg in "$@"; do
case "$arg" in
--install-sd)
installSd="true"
;;
--rustfmt)
rustfmt="true"
;;
*)
echo "Unknown argument: $arg"
exit 1
;;
esac
done

SD_VERSION="1.0.0"
PRE="DocCfg | "

# For gdext, add feature/cfg annotations in docs. This needs nightly rustdoc + custom preprocessing.
# Replace #[cfg(...)] with #[doc(cfg(...))], a nightly feature: https://doc.rust-lang.org/unstable-book/language-features/doc-cfg.html
# Potential alternative: https://docs.rs/doc-cfg/latest/doc_cfg
if [[ "$installSd" == "true" ]]; then
# Install sd (modern sed). No point in waiting for eternal `cargo install` if we can fetch a prebuilt binary in 1s.
echo "$PRE install sd (modern sed)..."
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
mkdir -p /tmp/tools
tar -zxvf archive.tar.gz -C /tmp/tools --strip-components=1
sd=/tmp/tools/sd
else
sd=sd
fi

echo "$PRE preprocess docs..."

# Enable feature in each lib.rs file.
# Note: first command uses sed because it's easier, and only handful of files.
find . -type f -name "lib.rs" -exec sed -i '1s/^/#![cfg_attr(published_docs, feature(doc_cfg))]\n/' {} +

# Then do the actual replacements.
# Could use \( -path "..." -o -path "..." \) to limit to certain paths.
# Do NOT include './target/debug/build/*' because generated files cannot be modified -- rustdoc will rerun the generation.
# This is done by directly emitting #[cfg_attr(published_docs, doc(cfg(...)))] in the godot-codegen crate, and that cfg is passed below.
find . -type f -name '*.rs' \
\( -path './godot' -o -path './godot-*' \) \
| while read -r file; do
# Replace #[cfg(...)] with #[doc(cfg(...))]. Do not insert a newline, in case the #[cfg] is commented-out.
# shellcheck disable=SC2016
$sd '(\#\[(cfg\(.+?\))\])(\s*)([A-Za-z]|#\[)' '$1 #[cfg_attr(published_docs, doc($2))]$3$4' "$file"
# $sd '(\#\[(cfg\(.+?\))\])\s*([A-Za-z]|#\[)' '$1 #[doc($2)]\n$3' "$file"
# ^^^^^^^^^^^^^^^^^ require that #[cfg] is followed by an identifier or a #[ attribute start.
# This avoids some usages of function-local #[cfg]s, although by far not all. Others generate warnings, which is fine.
done

if [[ "$rustfmt" == "true" ]]; then
echo "$PRE Format code using rustfmt..."
cargo fmt --all
fi

echo "$PRE Docs post-processed."
22 changes: 17 additions & 5 deletions .github/other/update-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@
# Small utility to run update crate versions, used by godot-rust developers.

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

# --help menu
args=("$@")
for arg in "${args[@]}"; do
if [ "$arg" == "--help" ]; then
echo "Usage: update-version.sh <newVersion>"
if [[ "$arg" == "--help" ]]; then
echo "Usage: update-version.sh <VER> [--no-tag]"
echo ""
echo "Replaces currently published version with <newVersion>".
echo "Does not git commit."
exit 0
fi

if [[ "$arg" == "--no-tag" ]]; then
noTag="true"
fi
done

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

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

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

if [[ "$noTag" == "true" ]]; then
echo "Skipped creating tag."
else
git tag "v$newVersion" || exit 2
echo "Created tag v$newVersion."
fi

echo ""
echo "SUCCESS: Updated version $oldVersion -> $newVersion"
7 changes: 4 additions & 3 deletions .github/workflows/full-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ defaults:
# cancel-in-progress: true

jobs:
# Keep all in sync with minimal-ci and release-version.
rustfmt:
runs-on: ubuntu-20.04
steps:
Expand Down Expand Up @@ -304,20 +305,20 @@ jobs:
# If ever moving to ubuntu-latest, need to manually install libtinfo5 for LLVM.

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

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

- name: linux-features-experimental
os: ubuntu-20.04
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/minimal-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ jobs:
- name: "Install Rust"
uses: ./.github/composite/rust
with:
rust: stable
components: rustfmt

- name: "Check rustfmt"
Expand Down Expand Up @@ -158,7 +157,7 @@ jobs:
os: ubuntu-20.04
artifact-name: linux-nightly
godot-binary: godot.linuxbsd.editor.dev.x86_64
rust-extra-args: --features godot/codegen-full
rust-extra-args: --features godot/__codegen-full
with-hot-reload: true

- name: linux-features-experimental
Expand Down
Loading

0 comments on commit e25e994

Please sign in to comment.