Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions .github/workflows/breaking-change.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Breaking Change

# A workflow of its own, so that editing the title of a pull request, which this check depends
# on, does not rerun the whole test suite.
on:
pull_request:
branches:
- main
types: [opened, synchronize, reopened, edited]

# The job only reads the repository, so the token does not need more than that.
permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
semver:
name: Breaking Change
runs-on: ubuntu-latest

steps:
# The baseline is built from the base commit, which a shallow clone does not contain.
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

- name: Install cargo-semver-checks
uses: taiki-e/install-action@4a76afe23f9e08d2d9550fb56e556444e8611d21 # v2.90.4
with:
tool: cargo-semver-checks

- name: Cache dependencies
uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
shared-key: semver

# Decides whether the pull request breaks the public API of `get-size2` compared to its
# base, with every feature enabled. A breaking pull request has to say so with the `!` of a
# conventional commit title (`feat!: ...`), which is what the changelog is generated from.
#
# Limits: only the API is compared. A change of behavior, like different reported sizes,
# goes unnoticed, as do some API changes the tool has no lint for (for example a relaxed
# bound on a trait method). The derive macro is not covered either, since a proc-macro
# crate has no library API to compare. A passing job is therefore no proof of compatibility.
#
# The title and the base commit are passed through the environment, never interpolated
# into the script, since the title is written by the author of the pull request.
- name: Compare the public API with the base branch
shell: bash
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
status=0
cargo semver-checks -p get-size2 --all-features --release-type minor \
--baseline-rev "$BASE_SHA" || status=$?

marked=false
if [[ "$PR_TITLE" =~ ^[a-zA-Z]+(\([^\)]*\))?!: ]]; then
marked=true
fi

# 0: compatible, 100: at least one breaking change, anything else: the tool itself failed.
case "$status" in
0)
verdict="No breaking API change detected."
result=0
;;
100)
if [[ "$marked" == true ]]; then
verdict="Breaking API change detected, and the title marks it as breaking."
result=0
else
verdict="Breaking API change detected, but the title does not mark it. Use a title like \`feat!: ...\`."
result=1
fi
;;
*)
verdict="cargo-semver-checks failed with exit code $status, so there is no verdict. See the log."
result=1
;;
esac

echo "### Breaking change check" >> "$GITHUB_STEP_SUMMARY"
echo "$verdict" >> "$GITHUB_STEP_SUMMARY"
if [[ "$result" -ne 0 ]]; then
echo "::error::$verdict"
else
echo "$verdict"
fi
exit "$result"
184 changes: 92 additions & 92 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ on:
pull_request:
branches:
- main
# `edited` reruns the breaking change check once the title gains or loses its `!` marker.
types: [opened, synchronize, reopened, edited]
# New advisories and toolchain releases show up without anyone pushing, so everything also runs
# once a week.
schedule:
Expand All @@ -21,9 +19,10 @@ permissions:
contents: read

# A newer push to a pull request supersedes the runs of the previous one. Every other run gets a
# group of its own, so runs on `main`, of tags and of the schedule are never cancelled or dropped.
# group of its own, named after its ref and commit, so runs on `main`, of tags and of the
# schedule are never cancelled or dropped, not even a tag pushed for the commit `main` is at.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
group: ${{ github.workflow }}-${{ github.event.pull_request.number || format('{0}-{1}', github.ref, github.sha) }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
Expand Down Expand Up @@ -80,6 +79,15 @@ jobs:
os: macos-latest
- name: Windows
os: windows-latest
# Emulated targets on which hash tables scan their control bytes differently: 16 bytes
# at once with LSX, and a plain machine word without SSE2. The allocator ground truth
# test keeps the reconstructed table sizes honest on them.
- name: LoongArch
os: ubuntu-latest
target: loongarch64-unknown-linux-gnu
- name: x86 without SSE2
os: ubuntu-latest
target: i586-unknown-linux-gnu

env:
# Empty for the native builds, which then target their host.
Expand Down Expand Up @@ -118,7 +126,7 @@ jobs:

- name: Test
shell: bash
run: cargo test --all --all-features $TARGET_FLAG
run: cargo test --all --all-features --no-fail-fast $TARGET_FLAG

no-std:
name: Build (no_std)
Expand Down Expand Up @@ -153,6 +161,21 @@ jobs:
cargo hack build -p get-size2 --each-feature --exclude-all-features
--exclude-features default,std,dashmap,parking_lot --target thumbv7m-none-eabi

# A target without atomic compare-and-swap: `alloc` provides no `Arc` there, and the
# fallbacks of `portable-atomic` are unavailable. Most integrations do not support such a
# target themselves, so only the tiers of this crate and the features meant for it are
# built, in every combination. The second build covers the cfg through which
# `portable-atomic` is told to assume a single core, which no feature can stand in for.
- name: Build for a target without compare-and-swap
run: |
rustup target add thumbv6m-none-eabi
cargo build -p get-size2 --no-default-features --target thumbv6m-none-eabi
RUSTFLAGS="--cfg portable_atomic_unsafe_assume_single_core" \
cargo build -p get-size2 --no-default-features --features portable-atomic \
--target thumbv6m-none-eabi
cargo hack build -p get-size2 --feature-powerset \
--include-features alloc,derive,portable-atomic,portable-atomic-critical-section --target thumbv6m-none-eabi

msrv:
name: MSRV
runs-on: ubuntu-latest
Expand All @@ -177,7 +200,7 @@ jobs:
# out, since their dependencies raise their own minimum version independently of us.
#
# No lockfile is committed, so this builds against the newest `syn`, `quote` and
# `attribute-derive`. Should one of them raise its minimum version, this job fails on an
# `proc-macro2`. Should one of them raise its minimum version, this job fails on an
# unrelated change. That is intended: it is what users on that toolchain would hit as well.
- name: Build without default features
run: cargo +1.85 build -p get-size2 --no-default-features
Expand Down Expand Up @@ -210,87 +233,6 @@ jobs:
RUSTDOCFLAGS: -D warnings --cfg docsrs
run: cargo +nightly doc --all-features --no-deps

semver:
name: Breaking Change
# Compares against the base of a pull request, so there is nothing to do for other events.
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
needs: [typos, cargo-machete]

steps:
# The baseline is built from the base commit, which a shallow clone does not contain.
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

- name: Install cargo-semver-checks
uses: taiki-e/install-action@4a76afe23f9e08d2d9550fb56e556444e8611d21 # v2.90.4
with:
tool: cargo-semver-checks

- name: Cache dependencies
uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
shared-key: semver

# Decides whether the pull request breaks the public API of `get-size2` compared to its
# base, with every feature enabled. A breaking pull request has to say so with the `!` of a
# conventional commit title (`feat!: ...`), which is what the changelog is generated from.
#
# Limits: only the API is compared. A change of behavior, like different reported sizes,
# goes unnoticed, as do some API changes the tool has no lint for (for example a relaxed
# bound on a trait method). The derive macro is not covered either, since a proc-macro
# crate has no library API to compare. A passing job is therefore no proof of compatibility.
#
# The title and the base commit are passed through the environment, never interpolated
# into the script, since the title is written by the author of the pull request.
- name: Compare the public API with the base branch
shell: bash
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
status=0
cargo semver-checks -p get-size2 --all-features --release-type minor \
--baseline-rev "$BASE_SHA" || status=$?

marked=false
if [[ "$PR_TITLE" =~ ^[a-zA-Z]+(\([^\)]*\))?!: ]]; then
marked=true
fi

# 0: compatible, 100: at least one breaking change, anything else: the tool itself failed.
case "$status" in
0)
verdict="No breaking API change detected."
result=0
;;
100)
if [[ "$marked" == true ]]; then
verdict="Breaking API change detected, and the title marks it as breaking."
result=0
else
verdict="Breaking API change detected, but the title does not mark it. Use a title like \`feat!: ...\`."
result=1
fi
;;
*)
verdict="cargo-semver-checks failed with exit code $status, so there is no verdict. See the log."
result=1
;;
esac

echo "### Breaking change check" >> "$GITHUB_STEP_SUMMARY"
echo "$verdict" >> "$GITHUB_STEP_SUMMARY"
if [[ "$result" -ne 0 ]]; then
echo "::error::$verdict"
else
echo "$verdict"
fi
exit "$result"

check:
name: Lint
runs-on: ubuntu-latest
Expand Down Expand Up @@ -337,10 +279,67 @@ jobs:
- name: Verify coverage threshold
run: >
cargo tarpaulin
--package get-size2
--workspace
--all-features
--exclude-files 'crates/get-size2/examples/*'
--fail-under 90

wasi:
name: Test (WASI)
runs-on: ubuntu-latest
needs: [typos, cargo-machete]

steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

# Installs the target and `wasmtime` as its test runner.
- name: Set up toolchain
uses: taiki-e/setup-cross-toolchain-action@12b7ad4acfa95a1476779d6c06699b96ec1691f8 # v1.42.0
with:
target: wasm32-wasip1

- name: Cache dependencies
uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
shared-key: wasi

# WebAssembly has a table layout of its own and no threads, which the unit tests spawn.
# The integration tests need none and compare the reported sizes with the allocator.
- name: Test
run: >
cargo test -p get-size2 --all-features --target wasm32-wasip1
--test allocation_ground_truth --test public_api

miri:
name: Miri
runs-on: ubuntu-latest
needs: [typos, cargo-machete]

steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Set up toolchain
run: rustup toolchain install nightly --profile minimal --component miri

- name: Cache dependencies
uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
shared-key: miri

# The standard library selects a portable hash table implementation under Miri, which the
# size reconstruction has to follow. The interpreter is slow, so only the integration
# tests run, with their largest cases left out.
- name: Test
run: >
cargo +nightly miri test -p get-size2 --all-features
--test allocation_ground_truth --test public_api

publish-check:
name: Publish Check
runs-on: ubuntu-latest
Expand All @@ -353,7 +352,8 @@ jobs:
with:
shared-key: publish
- run: cargo fetch
- name: cargo publish get-size2
run: cargo publish --dry-run -p get-size2
- name: cargo publish get-size-derive2
run: cargo publish --dry-run -p get-size-derive2
# Packages both crates in one go, so `get-size2` is verified against the derive macro of
# this very commit. Published one by one, the check would fail on the commit which bumps
# the version, as the new derive macro is not on crates.io yet.
- name: cargo publish
run: cargo publish --dry-run --workspace
12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ version = "0.11.1"
authors = ["Denis Kerp", "Nicolas"]

[workspace.dependencies]
syn = "3"
# The lowest versions the derive macro has been built and tested with.
syn = "3.0.4"
get-size-derive2 = { version = "0.11.1", path = "crates/get-size-derive2" }
quote = "1"
proc-macro2 = "1"
attribute-derive = "0.11"
quote = "1.0.40"
proc-macro2 = "1.0.95"

[workspace.lints.rust]
unsafe_code = "deny"
# Set through `RUSTFLAGS` by users of `portable-atomic` on single core targets.
unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(portable_atomic_unsafe_assume_single_core)',
] }
deprecated = "warn"
elided_lifetimes_in_paths = "warn"
rust_2021_prelude_collisions = "warn"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Issues and pull requests are welcome. `cargo test --all --all-features`, `cargo

## Minimum supported Rust version

The crate itself and the `derive` feature build with Rust 1.85. The optional integrations follow the requirements of the crates they integrate, which may be newer, currently up to Rust 1.90 for `roaring`.
The crate itself and the `derive` feature build with Rust 1.85. The optional integrations follow the requirements of the crates they integrate, which are often newer; `cargo` reports the version a feature needs.

## License

Expand Down
1 change: 0 additions & 1 deletion crates/get-size-derive2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ proc-macro = true
syn = { workspace = true, features = ["derive", "parsing"] }
quote.workspace = true
proc-macro2.workspace = true
attribute-derive.workspace = true

[dev-dependencies]
get-size2 = { path = "../get-size2", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/get-size-derive2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ For fields whose type does not implement `GetSize`, the `#[get_size(...)]` attri
| `#[get_size(ignore)]` | Field | Skips the field, contributing `0` |
| `#[get_size(size = 1024)]` | Field | Accounts the field with a fixed number of bytes |
| `#[get_size(size_fn = my_helper)]` | Field | Calls `my_helper(&field)` to determine the heap size, a path like `helpers::my_helper` works as well |
| `#[get_size(ignore(A, B))]` | Struct or enum | Drops the `GetSize` bound on the listed generic types |
| `#[get_size(ignore(A, B))]` | Struct or enum | Drops the `GetSize` bound on the listed generic types. Also accepted on a variant, where it applies to the whole enum |

## Documentation

Expand Down
Loading
Loading