Skip to content

ci: Build less for native tests on Windows and macOS - #1691

Merged
coroiu merged 3 commits into
mainfrom
ci/trim-native-test-builds
Oct 29, 2026
Merged

coroiu merged 3 commits into
mainfrom
ci/trim-native-test-builds

Conversation

@coroiu

@coroiu coroiu commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-46493

📔 Objective

On the 4-vCPU runners, the Windows test build is CPU-bound, so compiling less makes the job shorter. Each change was measured as an A/B on the same Windows runner, in both orders, with dependencies already built as with a warm cache:

Change Workspace rebuild on Windows
opt-level = 0 for bitwarden-api-api and bitwarden-api-identity, in CI only 13-16% faster, test run time unchanged
Skip bitwarden-uniffi, uniffi-bindgen, bitwarden-wasm-internal and wasm-bindgen-cli-runner on Windows and macOS 12-13% faster

The opt-level override is appended to .cargo/config.toml on the runner, so local dev and debug WASM builds keep opt-level = 1. Cargo ignores per-package opt-level from environment variables, and a config file reaches every cargo command in the job.

The skipped crates' native tests are platform-independent and still run on Linux. The uniffi code that differs per platform is gated on Android and iOS, which no test job runs. The Swift, Android and WASM workflows build those targets.

Together with #1690, the Windows job went from about 24.8 to 16 min in the same A/B setup. The build-side savings don't fully add up (about 200 s combined against 280 s measured one by one). With #1683's cache, most PRs rebuild fewer crates, so the saving per PR is smaller. It matters most when a core crate changes. I did not measure macOS.

The pwsh step from #1690 uses ${{ matrix.exclude }} as well. It has to build the same packages as the test step, or it rebuilds the workspace crates on Windows and macOS.

🤖 AI-assisted review

Local review (code-review-local) of the branch diff: 0 findings, none deferred.

@coroiu coroiu added the ai-review Request a Claude code review label Oct 28, 2026
Comment thread Cargo.toml Resolved
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

This PR changes only .github/workflows/rust-test.yml. On macOS and Windows, the native test matrix now skips the four binding crates. On every runner, the job appends opt-level = 0 for the two generated API crates to .cargo/config.toml. The build, test, and pwsh integration steps all pass the same ${{ matrix.exclude }}, which resolves the earlier finding about the pwsh step. The scripting_integration test lives in bitwarden-access-connector, which is not excluded. The config append runs before ci-build-cache.sh mark and record, so the recorded hash of .cargo/config.toml is the same on every run and the append does not cause a rebuild.

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🔍 SDK Breaking Change Detection

SDK Version: ci/trim-native-test-builds (c8a13ba)

⚠️ If breaking changes are detected, a corresponding pull request addressing them must be ready for merge in the affected client repository.

Client Status Details
android ✅ No breaking changes detected Compilation passed with new SDK version - View Details
typescript ✅ No breaking changes detected Compilation passed with new SDK version - View Details

Breaking change detection uses the build of the SDK from this branch, including any incompatibities pre-existing on or merged into this branch. Check the workflow logs to confirm.
Results update as workflows complete.

@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.56%. Comparing base (7179491) to head (0ce2146).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1691      +/-   ##
==========================================
- Coverage   87.62%   87.56%   -0.07%     
==========================================
  Files         683      667      -16     
  Lines      105230   104390     -840     
==========================================
- Hits        92208    91408     -800     
+ Misses      13022    12982      -40     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coroiu
coroiu added this pull request to stack #1686 October 28, 2026 14:43
@coroiu
coroiu force-pushed the ci/trim-native-test-builds branch from a1054cf to dc74664 Compare October 28, 2026 15:15
@coroiu
coroiu marked this pull request as ready for review October 28, 2026 15:16
@coroiu
coroiu requested a review from a team as a code owner October 28, 2026 15:16
@coroiu
coroiu requested a review from dani-garcia October 28, 2026 15:16
@coroiu
coroiu force-pushed the ci/trim-native-test-builds branch from dc74664 to e817ebb Compare October 28, 2026 15:39
dani-garcia
dani-garcia previously approved these changes Oct 28, 2026
run: |
cat >> .cargo/config.toml <<'EOF'

[profile.dev.package.bitwarden-api-api]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could do this universally, these crates don't have a lot of code per request, so it probably wont affect performance much.

coroiu added a commit that referenced this pull request Oct 29, 2026
## 🎟️ Tracking

No ticket. Found while measuring Windows CI times. The measurement is in
run 40661023259 on the throwaway branch `ci/windows-speed-experiments`.

## 📔 Objective

The pwsh integration step in `rust-test.yml` recompiled about 219 crates
before running about 25 s of tests. `-p bitwarden-access-connector
--all-features` resolves a different feature set than the `--workspace
--all-features` step before it, so cargo can't reuse that build. On
Windows the compile took 339 s. Linux and macOS spend 2-4 min on the
step.

Selecting the test target under the workspace feature set compiles in
0.9 s on Windows and runs the same 5 tests.

The step now only runs `tests/scripting_integration.rs`. All
`#[ignore]`d tests in the crate are in that file, and the workflow
comment says new ones belong there too.

If #1691 merges as well, this step also needs `${{ matrix.exclude }}`,
so its features match the trimmed build on Windows and macOS.

## 🤖 AI-assisted review

Local review (`code-review-local`) of the branch diff: 0 findings, none
deferred.
@coroiu
coroiu force-pushed the ci/trim-native-test-builds branch from e817ebb to c7bf152 Compare October 29, 2026 08:08

- name: Test
run: cargo test --workspace --all-features
run: cargo test --workspace --all-features ${{ matrix.exclude }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ IMPORTANT: This step passes ${{ matrix.exclude }} but the pwsh integration step below (line 125) does not, so on Windows and macOS its package selection no longer matches this build.

Details and fix

The PR description says the pwsh step needs ${{ matrix.exclude }} once this PR and #1690 are both merged, because otherwise it rebuilds on Windows and macOS. #1690 is already in this branch's history (7179491), so that condition is met now. The comment above that step also says its features must match this step so it can reuse the build.

Change line 125 to:

        run: cargo test --workspace --all-features ${{ matrix.exclude }} --test scripting_integration -- --ignored --test-threads=1

Without the change, the pwsh step resolves features for the full workspace, while the build and test steps resolve them for the reduced set. On the two slowest runners, that can bring back the recompile that #1690 removed.

code-review

Base automatically changed from ci/cache-workspace-build to main October 29, 2026 12:39
Windows test builds are CPU-bound, so less compiled code means a shorter
job. Measured on windows-2022 with dependencies already built:

- opt-level 0 for bitwarden-api-api and bitwarden-api-identity: the
  workspace rebuild is 13-16% faster and test run time is unchanged.
- Skipping bitwarden-uniffi, uniffi-bindgen, bitwarden-wasm-internal and
  wasm-bindgen-cli-runner on Windows and macOS: about 12-13% faster. Their
  native tests are platform-independent and keep running on Linux; the
  uniffi code that differs per platform is gated on android/ios, which no
  test job runs.

Together with the pwsh integration step fix, the Windows job went from
about 24.8 to 16 min in an A/B on the same runner.
Local dev and debug WASM builds keep opt-level 1 for these crates. The override is appended to .cargo/config.toml on the runner, so every cargo command in the job gets it.
The step has to use the same packages and features as the test step, or
cargo rebuilds the workspace crates for it.
@coroiu
coroiu force-pushed the ci/trim-native-test-builds branch from 91d5e57 to 0ce2146 Compare October 29, 2026 12:39
@coroiu
coroiu requested a review from dani-garcia October 29, 2026 12:39
@coroiu
coroiu enabled stacked auto-merge (squash) October 29, 2026 12:40
@coroiu
coroiu merged commit d7ab996 into main Oct 29, 2026
60 of 61 checks passed
@coroiu
coroiu deleted the ci/trim-native-test-builds branch October 29, 2026 12:49
bw-ghapp Bot added a commit to bitwarden/sdk-swift that referenced this pull request Oct 29, 2026
coroiu added a commit that referenced this pull request Nov 3, 2026
**TL;DR: The build and lint workflows only rebuild what a PR changed.**
With the Rust tests fixed in #1683, the slowest checks on a PR were the
WASM build (19.6 min median), Android (16.4), Swift (16.4) and Lint
(14.8). Each now uses the build cache from #1683, through a shared
action in bitwarden/gh-actions, and drops duplicate work, so a typical
PR's checks should finish in about 10 minutes, and much of that is the
clients and Android breaking-change checks.

## 🎟️ Tracking

No ticket. Follow-up to #1683, #1690 and #1691. Uses the
`cargo-build-cache` action from bitwarden/gh-actions#1006.

## 📔 Objective

Each workflow was measured on its own experiment branch with
`workflow_dispatch`, against the latest successful PR run on `main`.
Single runs per scenario.

| Workflow | PR median on `main` (before) | Leaf-crate change |
`bitwarden-core` change |
|---|---|---|---|
| Lint | 14.8 min | 1.9 min | 3.1 min |
| WASM build | 19.6 min | 4.4 min (PR mode) | 8.9 min (full build) |
| Swift | 16.4 min | Build job 4.2 min | 9.3 min (whole run) |
| Android | 16.4 min | Build jobs about 2 min, Combine about 2 min |
Build jobs about 2.5-3 min |

The clients and Android breaking-change checks (about 5 min each) wait
on the other repo and are unchanged. I haven't measured a full PR end to
end, since the experiments ran as dispatches.

One commit per fix:

**Swift**
- Build the three Apple targets in one cargo call. Each target ended
with a single-threaded LTO step, and now those steps overlap. Output is
byte-identical.
- Build cache in the Build job.

**Android**
- Build cache per ABI. rust-cache did restore, but its cleanup deletes
`target/<triple>/release` before saving, so about 318 dependencies
compiled in every run. The `cross` image digest is part of the key,
because the NDK and linker are not in cargo's fingerprints. The
workspace is mounted at the same path inside the container, so the mtime
marking works there too.
- Cache `cross` itself (`.bin`), which was compiled from git on every
run (42 s). This cache has no restore keys, because cargo-run-bin stores
`cross` under its version, not its git rev.
- Gradle build cache for the demo app build. Tasks with unchanged inputs
come from the cache. A PR that changes the uniffi API changes the
bindings, so those PRs get less out of it.

**Lint**
- Run clippy once. `lint.sh` set `RUSTFLAGS="-D warnings"`, so its
clippy run after the SARIF step rechecked all ~630 crates. The SARIF
step is now the gate, with `pipefail`, and findings are still uploaded
when it fails.
- Build cache for clippy, doc and udeps. Before, the shared rust-cache
key held no `target/` at all.
- Keep udeps fresh across toolchain installs. cargo-udeps records the
nightly sysroot files in every crate's dep-info, and a fresh toolchain
install gives them new mtimes, so all 547 dependencies were checked
again.

**WASM**
- `fix:` The `bitwarden-wasm-internal` build script reran on any file
change but not on a changed `SDK_VERSION` or a new commit. With a cached
`target/`, the package could embed an old version string. It now reruns
on those.
- Build cache per license.
- Keep the rust-src mtimes stable. `-Zbuild-std` compiles the standard
library from rust-src, which gets new mtimes on every toolchain install,
so all 364 crates rebuilt even with the cache.
- Run `wasm-opt` once. The bundler and nodejs `.wasm` files were
byte-identical in every run, so the second is a copy. The script checks
this each time and falls back to optimizing both.
- Build the MVP/wasm2js fallback in parallel with the SIMD build
(`build.sh -p`, used in CI). Local `./build.sh -r` stays sequential.
- On pull requests, skip `wasm-opt`, `wasm2js` and `terser` for the
fallback (`build.sh -s`). Nothing in the PR flow loads the fallback: the
clients check only type-checks the package, and the integration tests
load the Node build. The MVP cargo build and the check that both builds
share one glue file still run. `main` builds the full package as before.

### What a PR no longer checks

- `wasm-opt`, `wasm2js` and `terser` on the WASM fallback. Failures
there show up on `main`.
- The PR package's fallback file is a stub, the same as in debug builds.

### Output

- WASM: all 751 package files are byte-identical between a clean build
and a cached build, except `VERSION` (the commit hash).
- Swift: the `.a` files and all generated `.swift`, `.h` and
`.modulemap` files are byte-identical to `main`. The xcframework's
`Info.plist` differs only in the order of `AvailableLibraries`, which
also changes between runs on `main`.

### Good to know

- Builds on `main`, including the ones that publish, also use the cache.
The comparisons above showed no difference from clean builds.
- The first run of each workflow after merge has no cache yet and takes
about as long as before this change.
- The last two commits replace the cache steps in all workflows,
including `rust-test.yml` from #1683, with one
`bitwarden/gh-actions/cargo-build-cache` step, and delete
`scripts/ci-build-cache.sh`. The action uses the same logic, and is
measured as fast as the copies in all five workflows. Its cache keys
start with `cargo-build-`, so the first run of each workflow after merge
is cold, including Rust tests.
- The action saves through `actions/cache` at the end of the job, which
only happens when the job succeeded. A job that fails after a successful
build, for example on a failing test, no longer saves its build output,
and the next run falls back to an older cache. Lint already behaved that
way.
- Pre-existing and out of scope here: the `cross` images (`:main`),
`binaryen` and `terser` are unpinned.

## 🤖 AI-assisted review

- Multi-agent review (architecture, code quality, bug analysis,
security, then validation and severity audit). Two Refactor findings, no
Blockers or Important ones.
- Fixed: the Android `.bin` cache had a prefix restore key.
cargo-run-bin stores `cross` under its version only, not its git rev, so
after a rev bump the old binary would have been restored and used on
`main`. The cache now has no restore keys.
- Addressed: the cache steps were copied into six places. The last
commit replaces them with the shared action from
bitwarden/gh-actions#1006.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants