@@ -62,46 +62,20 @@ git log -n 1
6262echo " ========================================"
6363
6464
65- # For gdext, add feature/cfg annotations in docs. This needs nightly rustdoc + custom preprocessing.
66- # Replace #[cfg(...)] with #[doc(cfg(...))], a nightly feature: https://doc.rust-lang.org/unstable-book/language-features/doc-cfg.html
67- # Potential alternative: https://docs.rs/doc-cfg/latest/doc_cfg
68- #
65+
6966# TODO currently, this uses gdext master without custom-godot, so latest 4.x features (of the in-dev version) are not available.
7067# We cannot just pretend we are on 4.x, because code will not compile with the default C/JSON headers. We would need custom-godot
7168# and a running engine, which is a bit overkill.
7269if [[ " $repo " == " gdext" ]]; then
73- # Install sd (modern sed). No point in waiting for eternal `cargo install` if we can fetch a prebuilt binary in 1s.
74- echo " $PRE install sd (modern sed)..."
75- 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
76- mkdir -p tools
77- tar -zxvf archive.tar.gz -C tools --strip-components=1
78-
79- echo " $PRE preprocess docs..."
80-
8170 # Patch Cargo.toml to pull from nightly prebuilt artifacts.
8271 # This allows to use JSON and C headers from the in-development Godot 4.x engine, enabling latest #[cfg(since_api = "4.x")] features for docs.
8372 cat >> " Cargo.toml" << - HEREDOC
8473[patch."https://github.com/godot-rust/godot4-prebuilt"]
8574gdextension-api = { git = "https://github.com//godot-rust/godot4-prebuilt", branch = "nightly" }
8675HEREDOC
8776
88- # Enable feature in each lib.rs file.
89- # Note: first command uses sed because it's easier, and only handful of files.
90- find . -type f -name " lib.rs" -exec sed -i ' 1s/^/#![feature(doc_cfg)]\n/' {} +
91-
92- # Then do the actual replacements.
93- # Could use \( -path "..." -o -path "..." \) to limit to certain paths.
94- # Do NOT include './target/debug/build/*' because generated files cannot be modified -- rustdoc will rerun the generation.
95- # This is done by directly emitting #[cfg_attr(published_docs, doc(cfg(...)))] in the godot-codegen crate, and that cfg is passed below.
96- find . -type f -name ' *.rs' \
97- \( -path ' ./godot' -o -path ' ./godot-*' \) \
98- | while read -r file; do
99- # Replace #[cfg(...)] with #[doc(cfg(...))]. Do not insert a newline, in case the #[cfg] is commented-out.
100- # shellcheck disable=SC2016
101- ./tools/sd ' (\#\[(cfg\(.+?\))\])\s*([A-Za-z]|#\[)' ' $1 #[doc($2)]\n$3' " $file "
102- # ^^^^^^^^^^^^^^^^^ require that #[cfg] is followed by an identifier or a #[ attribute start.
103- # This avoids some usages of function-local #[cfg]s, although by far not all. Others generate warnings, which is fine.
104- done
77+ # Apply #[doc(cfg(...))] to all docs. No rustfmt needed.
78+ documentation/apply-doc-cfg.sh --install-sd
10579fi
10680
10781# Build docs
0 commit comments