From 52afb9021917dfe77afdb193ebf1f8322ca8f2ef Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 29 Apr 2025 11:43:54 +0200 Subject: [PATCH] Get `rustdoc` flags from `Cargo.toml`. --- .github/workflows/build.yml | 41 ++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cacfb443..3421fa2a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ on: env: CARGO_TERM_COLOR: always - RUSTFLAGS: '-D warnings' + RUSTFLAGS: "-D warnings" jobs: # Run MIRI tests on nightly @@ -182,11 +182,6 @@ jobs: doc: name: doc runs-on: ubuntu-latest - strategy: - matrix: - target: - - x86_64-unknown-linux-gnu - - thumbv7m-none-eabi steps: - name: Checkout uses: actions/checkout@v4 @@ -213,14 +208,40 @@ jobs: ${{ runner.OS }}-build-${{ hashFiles('**/Cargo.lock') }} ${{ runner.OS }}-build- - - name: Install nightly Rust with target (${{ matrix.target }}) + - name: Get metadata + id: metadata + run: | + set -euo pipefail + + docsrs_metadata="$(cargo metadata --format-version 1 | jq '.packages[] | select(.name == "heapless") | .metadata.docs.rs')" + features=($(jq --raw-output '.features[]' <<< "${docsrs_metadata}")) + rustdocflags=(-D warnings --cfg docsrs $(jq --raw-output '.["rustdoc-args"][]' <<< "${docsrs_metadata}")) + targets=($(jq --raw-output '.targets[]' <<< "${docsrs_metadata}")) + + echo "features=${features[*]}" >> "${GITHUB_OUTPUT}" + echo "rustdocflags=${rustdocflags[*]}" >> "${GITHUB_OUTPUT}" + echo "targets=${targets[*]}" >> "${GITHUB_OUTPUT}" + + - name: Install nightly Rust with targets (${{ steps.metadata.outputs.targets }}) uses: dtolnay/rust-toolchain@nightly with: - targets: ${{ matrix.target }} + targets: ${{ steps.metadata.outputs.targets }} - name: cargo rustdoc - env: {"RUSTDOCFLAGS": "-D warnings --cfg docsrs"} - run: cargo rustdoc --target=${{ matrix.target }} --features="alloc bytes defmt mpmc_large portable-atomic-critical-section serde ufmt" + run: | + set -euo pipefail + + targets=(${targets}) + + for target in "${targets[@]}"; do + set -x + cargo rustdoc --target "${target}" --features "${features}" + set +x + done + env: + features: ${{ steps.metadata.outputs.features }} + RUSTDOCFLAGS: ${{ steps.metadata.outputs.rustdocflags }} + targets: ${{ steps.metadata.outputs.targets }} # Run cpass tests testcpass: