Skip to content

Commit ccd862b

Browse files
committed
Run rustdoc with --cfg published_docs, to enable special attributes from codegen
1 parent 737b2a0 commit ccd862b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

documentation/put.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ case $repo in
2020
;;
2121
"gdext")
2222
mainCrate="godot"
23+
# `experimental-godot-api` is needed to allow "only available in ..." labels with #[doc(cfg)].
2324
# Could add experimental-threads in the future, but for now it's unstable and possibly more confusing.
2425
features="--features experimental-godot-api"
2526
;;
@@ -89,25 +90,26 @@ HEREDOC
8990
find . -type f -name "lib.rs" -exec sed -i '1s/^/#![feature(doc_cfg)]\n/' {} +
9091

9192
# Then do the actual replacements.
92-
find . \( \
93-
-path "./godot" -o \
94-
-path "./godot-*" \) \
95-
-type f -name '*.rs' | while read -r file; do
96-
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
9799
# Replace #[cfg(...)] with #[doc(cfg(...))]. Do not insert a newline, in case the #[cfg] is commented-out.
98100
# shellcheck disable=SC2016
99101
./tools/sd '(\#\[(cfg\(.+?\))\])\s*([A-Za-z]|#\[)' '$1 #[doc($2)]\n$3' "$file"
100102
# ^^^^^^^^^^^^^^^^^ require that #[cfg] is followed by an identifier or a #[ attribute start.
101103
# This avoids some usages of function-local #[cfg]s, although by far not all. Others generate warnings, which is fine.
102-
103104
done
104105
fi
105106

106107
# Build docs
107108
echo "$PRE build Rust docs of crate '$mainCrate' ($features)..."
108109
up=".."
110+
111+
export RUSTFLAGS="--cfg published_docs -A unused_imports -A dead_code -A unexpected_cfgs"
109112
# shellcheck disable=SC2086
110-
export RUSTFLAGS="-A unused_imports -A dead_code -A unexpected_cfgs"
111113
cargo +nightly doc -p $mainCrate $features --no-deps --target-dir $up/target
112114
#mkdir -p "$up/target/doc"
113115
cd $up

0 commit comments

Comments
 (0)