2018-11-19 15:49:56 +01:00
|
|
|
#!/usr/bin/env sh
|
2015-09-17 08:54:56 +02:00
|
|
|
|
2015-09-18 02:45:10 +02:00
|
|
|
# Builds documentation for all target triples that we have a registered URL for
|
|
|
|
# in liblibc. This scrapes the list of triples to document from `src/lib.rs`
|
|
|
|
# which has a bunch of `html_root_url` directives we pick up.
|
|
|
|
|
2018-11-19 15:49:56 +01:00
|
|
|
set -ex
|
2015-09-17 08:54:56 +02:00
|
|
|
|
2021-02-26 01:21:17 +01:00
|
|
|
TARGET_DOC_DIR="target/doc"
|
|
|
|
README="README.md"
|
|
|
|
PLATFORM_SUPPORT="platform-support.md"
|
2015-09-18 02:45:10 +02:00
|
|
|
|
2021-02-26 01:21:17 +01:00
|
|
|
rm -rf "$TARGET_DOC_DIR"
|
|
|
|
mkdir -p "$TARGET_DOC_DIR"
|
2015-09-17 08:54:56 +02:00
|
|
|
|
2019-05-28 19:10:23 +02:00
|
|
|
if ! rustc --version | grep -E "nightly" ; then
|
|
|
|
echo "Building the documentation requires a nightly Rust toolchain"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
rustup component add rust-src
|
|
|
|
|
2019-02-13 13:59:17 +01:00
|
|
|
# List all targets that do currently build successfully:
|
|
|
|
# shellcheck disable=SC1003
|
|
|
|
grep '[\d|\w|-]* \\' ci/build.sh > targets
|
|
|
|
sed -i.bak 's/ \\//g' targets
|
2019-10-16 20:57:53 +02:00
|
|
|
grep '^[_a-zA-Z0-9-]*$' targets | sort > tmp && mv tmp targets
|
2015-09-17 18:52:21 +02:00
|
|
|
|
2019-02-13 13:59:17 +01:00
|
|
|
# Create a markdown list of supported platforms in $PLATFORM_SUPPORT
|
|
|
|
rm $PLATFORM_SUPPORT || true
|
|
|
|
|
|
|
|
printf '### Platform-specific documentation\n' >> $PLATFORM_SUPPORT
|
|
|
|
|
|
|
|
while read -r target; do
|
2019-02-20 17:57:01 +01:00
|
|
|
echo "documenting ${target}"
|
2015-09-17 19:05:36 +02:00
|
|
|
|
2019-02-20 17:57:01 +01:00
|
|
|
case "${target}" in
|
|
|
|
*apple*)
|
|
|
|
# FIXME:
|
|
|
|
# We can't build docs of apple targets from Linux yet.
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
2019-02-20 13:11:30 +01:00
|
|
|
|
2019-02-20 17:57:01 +01:00
|
|
|
rustup target add "${target}" || true
|
2019-02-20 18:42:34 +01:00
|
|
|
|
2019-08-14 17:32:21 +02:00
|
|
|
# Enable extra configuration flags:
|
|
|
|
export RUSTDOCFLAGS="--cfg freebsd11"
|
|
|
|
|
2020-07-25 00:09:43 +02:00
|
|
|
# If cargo doc fails, then try with unstable feature:
|
2019-02-20 18:42:34 +01:00
|
|
|
if ! cargo doc --target "${target}" \
|
2021-07-24 23:37:30 +02:00
|
|
|
--no-default-features --features const-extern-fn,extra_traits ; then
|
2020-07-25 00:09:43 +02:00
|
|
|
cargo doc --target "${target}" \
|
|
|
|
-Z build-std=core,alloc \
|
2021-07-24 23:37:30 +02:00
|
|
|
--no-default-features --features const-extern-fn,extra_traits
|
2019-02-20 18:42:34 +01:00
|
|
|
fi
|
2019-02-13 13:59:17 +01:00
|
|
|
|
2021-02-26 01:21:17 +01:00
|
|
|
mkdir -p "${TARGET_DOC_DIR}/${target}"
|
2019-02-20 17:57:01 +01:00
|
|
|
cp -r "target/${target}/doc" "${TARGET_DOC_DIR}/${target}"
|
|
|
|
|
2021-03-03 16:04:29 +01:00
|
|
|
echo "* [${target}](${target}/doc/libc/index.html)" >> $PLATFORM_SUPPORT
|
2019-02-13 13:59:17 +01:00
|
|
|
done < targets
|
2015-09-17 18:52:21 +02:00
|
|
|
|
2019-02-13 13:59:17 +01:00
|
|
|
# Replace <div class="platform_support"></div> with the contents of $PLATFORM_SUPPORT
|
|
|
|
cp $README $TARGET_DOC_DIR
|
|
|
|
line=$(grep -n '<div class="platform_docs"></div>' $README | cut -d ":" -f 1)
|
2015-09-17 08:54:56 +02:00
|
|
|
|
2019-02-13 13:59:17 +01:00
|
|
|
{ head -n "$((line-1))" $README; cat $PLATFORM_SUPPORT; tail -n "+$((line+1))" $README; } > $TARGET_DOC_DIR/$README
|
2015-09-17 08:54:56 +02:00
|
|
|
|
2020-07-08 03:37:13 +02:00
|
|
|
cp $TARGET_DOC_DIR/$README $TARGET_DOC_DIR/index.md
|
|
|
|
|
|
|
|
RUSTDOCFLAGS="--enable-index-page --index-page=${TARGET_DOC_DIR}/index.md -Zunstable-options" cargo doc
|
|
|
|
|
|
|
|
# Tweak style
|
|
|
|
cp ci/rust.css $TARGET_DOC_DIR
|
|
|
|
sed -ie "8i <link rel=\"stylesheet\" type=\"text/css\" href=\"normalize.css\">" $TARGET_DOC_DIR/index.html
|
|
|
|
sed -ie "9i <link rel=\"stylesheet\" type=\"text/css\" href=\"rust.css\">" $TARGET_DOC_DIR/index.html
|
2020-07-08 00:32:18 +02:00
|
|
|
|
2019-02-21 10:18:06 +01:00
|
|
|
# Copy the licenses
|
|
|
|
cp LICENSE-* $TARGET_DOC_DIR/
|