|
| 1 | +#!/usr/bin/env bash |
| 2 | +#LICENSE Portions Copyright 2026 PgCentral Foundation, Inc. <contact@pgcentral.org> |
| 3 | +#LICENSE |
| 4 | +#LICENSE All rights reserved. |
| 5 | +#LICENSE |
| 6 | +#LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file. |
| 7 | + |
| 8 | +set -euo pipefail |
| 9 | + |
| 10 | +PG_VER="${PG_VER:-14}" |
| 11 | +PG_FEATURE="pg${PG_VER#pg}" |
| 12 | +TOOLCHAIN="${DOCSRS_TOOLCHAIN:-nightly}" |
| 13 | +PACKAGE_DIR="${CARGO_TARGET_DIR:-target}/package" |
| 14 | + |
| 15 | +echo "Checking packaged pgrx-bindgen dependency metadata" |
| 16 | +# Package the local internal dependency too so unpublished release-candidate |
| 17 | +# workspace versions do not force pgrx-bindgen to resolve it from crates.io. |
| 18 | +cargo "+${TOOLCHAIN}" package --allow-dirty --no-verify -p pgrx-pg-config -p pgrx-bindgen |
| 19 | + |
| 20 | +shopt -s nullglob |
| 21 | +crates=("${PACKAGE_DIR}"/pgrx-bindgen-*.crate) |
| 22 | +if (( ${#crates[@]} == 0 )); then |
| 23 | + echo "Could not find packaged pgrx-bindgen crate in ${PACKAGE_DIR}" >&2 |
| 24 | + exit 1 |
| 25 | +fi |
| 26 | +crate="$(ls -t "${crates[@]}" | head -n 1)" |
| 27 | + |
| 28 | +tmpdir="$(mktemp -d)" |
| 29 | +trap 'rm -rf "${tmpdir}"' EXIT |
| 30 | + |
| 31 | +manifest_path="$(tar -tf "${crate}" | grep '/Cargo.toml$' | head -n 1)" |
| 32 | +lock_path="$(tar -tf "${crate}" | grep '/Cargo.lock$' | head -n 1 || true)" |
| 33 | + |
| 34 | +tar -xOf "${crate}" "${manifest_path}" > "${tmpdir}/Cargo.toml" |
| 35 | +if grep -A 8 '^\[dependencies.bindgen\]' "${tmpdir}/Cargo.toml" | grep -q '"experimental"'; then |
| 36 | + echo "pgrx-bindgen package enables bindgen/experimental, which breaks docs.rs via annotate-snippets" >&2 |
| 37 | + exit 1 |
| 38 | +fi |
| 39 | + |
| 40 | +if [[ -n "${lock_path}" ]]; then |
| 41 | + tar -xOf "${crate}" "${lock_path}" > "${tmpdir}/Cargo.lock" |
| 42 | + if grep -q 'name = "annotate-snippets"' "${tmpdir}/Cargo.lock"; then |
| 43 | + echo "pgrx-bindgen package lockfile contains annotate-snippets; check bindgen features" >&2 |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | +fi |
| 47 | + |
| 48 | +echo "Running docs.rs-style rustdoc check for pgrx with ${PG_FEATURE} cshim" |
| 49 | +host="$(rustc "+${TOOLCHAIN}" -vV | awk '/^host:/ { print $2 }')" |
| 50 | +rustdoc_cmd=( |
| 51 | + cargo "+${TOOLCHAIN}" rustdoc |
| 52 | + -p pgrx |
| 53 | + --lib |
| 54 | + --no-default-features |
| 55 | + --features "${PG_FEATURE} cshim" |
| 56 | + -Zrustdoc-map |
| 57 | + -Zhost-config |
| 58 | + -Ztarget-applies-to-host |
| 59 | +) |
| 60 | + |
| 61 | +docsrs_target="${DOCSRS_TARGET:-}" |
| 62 | +if [[ -z "${docsrs_target}" && "${host}" == "x86_64-unknown-linux-gnu" ]]; then |
| 63 | + docsrs_target="x86_64-unknown-linux-gnu" |
| 64 | +fi |
| 65 | + |
| 66 | +if [[ -n "${docsrs_target}" ]]; then |
| 67 | + rustdoc_cmd+=(--target "${docsrs_target}") |
| 68 | +fi |
| 69 | + |
| 70 | +docsrs_rustdocflags="${RUSTDOCFLAGS:-}" |
| 71 | +docsrs_rustdocflags="${docsrs_rustdocflags:+${docsrs_rustdocflags} }--cfg docsrs -Z unstable-options --emit=invocation-specific --cap-lints warn" |
| 72 | + |
| 73 | +DOCS_RS=1 RUSTDOCFLAGS="${docsrs_rustdocflags}" "${rustdoc_cmd[@]}" |
0 commit comments