@@ -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
104105fi
105106
106107# Build docs
107108echo " $PRE build Rust docs of crate '$mainCrate ' ($features )..."
108109up=" .."
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"
111113cargo +nightly doc -p $mainCrate $features --no-deps --target-dir $up /target
112114# mkdir -p "$up/target/doc"
113115cd $up
0 commit comments