#!/usr/bin/env bash # Renders the consumer reference of the new API's frozen surface, warnings # denied. CI runs it after the ordinary documentation build; so does the gate in CONTRIBUTING.md. # # scripts/api-docs # render into /doc/metal2vulkan # scripts/api-docs --open # and open it in a browser # # It is the ordinary rustdoc build of the library with every feature: the crate root shows the new # API's public module roots, `Budget`, and `CancelToken`, and hides the hidden crate-root # modules (`env_vars` and `repro`, which the binary uses). Hidden items and # submodules inside the roots stay hidden. # `crates/metal2vulkan/tests/api_surface.rs` keeps that set equal to the pinned surface table. # # The previous output is removed first, so no page of another build survives in the reference. # Rustdoc renders a link to an item it does not document (a hidden or internal one) as its # bracketed text, without a warning; the script fails when a page shows one, so the reference # never points at internals. # # It first fails on a lab job's id (`m3-max-NNNN`, or `job NNNN`) in the prose docs a reader takes # measurements from: they state each measurement by its card, driver and OS, and the id stays in # the commit message that carries it. set -euo pipefail cd "$(dirname "$0")/.." case "${1-}" in "" | --open) ;; *) echo "usage: scripts/api-docs [--open]" >&2 exit 64 ;; esac prose=(crates/metal2vulkan-runtime/README.md docs/API.md docs/REPLAY-STREAM.md docs/VALIDATION.md) if grep -nE '\bm3-max-[0-9]+|\b[Jj]obs? [0-9]{3,}' "${prose[@]}" >&2; then echo "scripts/api-docs: a lab job id in the prose docs above; state the card, driver and OS" >&2 exit 1 fi target_dir=$(cargo metadata --format-version 1 --no-deps | sed -n 's/.*"target_directory":"\([^"]*\)".*/\1/p') doc="$target_dir/doc/metal2vulkan" rm -rf "$doc" export RUSTDOCFLAGS="${RUSTDOCFLAGS-} -D warnings" cargo doc -p metal2vulkan --lib --no-deps --all-features if [ ! -f "$doc/pipeline/index.html" ]; then echo "scripts/api-docs: $doc has no pipeline module page" >&2 exit 1 fi unresolved=$(find "$doc" -name '*.html' -print0 | xargs -0 grep -L 'http-equiv="refresh"' | tr '\n' '\0' | xargs -0 grep -Ho '\[[^<]*\]' || true) if [ -n "$unresolved" ]; then echo "scripts/api-docs: links that did not resolve (to hidden or internal items):" >&2 printf '%s\n' "$unresolved" | sed "s#^$doc/##" >&2 exit 1 fi echo "scripts/api-docs: rendered $doc/index.html" if [ "${1-}" = --open ]; then cargo doc -p metal2vulkan --lib --no-deps --all-features --open fi