Skip to content

Commit

Permalink
Check for changes to the public API
Browse files Browse the repository at this point in the history
We would like to get to a stage where we can commit to the public API.
To help us achieve this add a script that generates the public API and
checks it against three committed files, one for each feature set: no
features, alloc, std.

The idea is that with this applied any PR that changes the public API
should include a final patch that is just the changes to the api/*.txt
files, that way reviewers can discuss the changes without even needing
to look at the code, quickly giving concept ACK/NACKs. We also run the
script in CI to make sure we have not accidentally changed the public
API so that we can be confident that don't break semver during releases.
The script can also be used to diff between two release versions to get
a complete list of API changes, useful for writing release notes and for
users upgrading.

There is a development burden involved if we apply this patch.
  • Loading branch information
tcharding committed Oct 26, 2023
1 parent d61f5f9 commit cbfecd0
Show file tree
Hide file tree
Showing 6 changed files with 2,643 additions and 0 deletions.
533 changes: 533 additions & 0 deletions api/all-features.txt

Large diffs are not rendered by default.

527 changes: 527 additions & 0 deletions api/alloc.txt

Large diffs are not rendered by default.

510 changes: 510 additions & 0 deletions api/core2.txt

Large diffs are not rendered by default.

533 changes: 533 additions & 0 deletions api/default-features.txt

Large diffs are not rendered by default.

508 changes: 508 additions & 0 deletions api/no-default-features.txt

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions contrib/check-for-api-changes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
#
# Checks the public API of crates, exits with non-zero if there are currently
# changes to the public API not already committed to in the various api/*.txt
# files.

set -e

export RUSTDOCFLAGS='-A rustdoc::broken-intra-doc-links'
REPO_DIR=$(git rev-parse --show-toplevel)
API_DIR="$REPO_DIR/api"
CMD="cargo +nightly public-api --simplified"

# cargo public-api uses nightly so the toolchain must be available.
if ! cargo +nightly --version > /dev/null; then
echo "script requires a nightly toolchain to be installed (possibly >= nightly-2023-05-24)" >&2
exit 1
fi

pushd "$REPO_DIR" > /dev/null
$CMD --no-default-features | sort --unique > "$API_DIR/no-default-features.txt"
$CMD | sort --unique > "$API_DIR/default-features.txt"
$CMD --no-default-features --features=alloc | sort --unique > "$API_DIR/alloc.txt"
$CMD --no-default-features --features=core2 | sort --unique > "$API_DIR/core2.txt"
$CMD --all-features | sort --unique > "$API_DIR/all-features.txt"

if [[ $(git status --porcelain api) ]]; then
echo "You have introduced changes to the public API, commit the changes to api/ currently in your working directory" >&2
else
echo "No changes to the current public API"
fi
popd > /dev/null

0 comments on commit cbfecd0

Please sign in to comment.