Skip to content

ci: the device-only guard re-resolves the lock file it is judging - #962

Merged
nihalpasham merged 1 commit into
NVIDIA:mainfrom
vyncint:ci/device-only-guard-locked
Aug 17, 2026
Merged

nihalpasham merged 1 commit into
NVIDIA:mainfrom
vyncint:ci/device-only-guard-locked

Conversation

@vyncint

@vyncint vyncint commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

scripts/check-device-only-build.sh is the only guard in scripts/ that resolves a Cargo graph without --locked. Its sibling states the rule it is missing:

--locked so the guard reads the committed resolution rather than silently updating Cargo.lock to satisfy itself: a check that can rewrite its own input is not a check.
— scripts/check-dependency-licenses.sh

check-example-license-policy.sh passes it too, and #806 added it to all three executable cargo deny invocations for the same reason.

It matters more here than in either of those. This guard's whole assertion is about the resolved graph — "cuda-host, cuda-core and cuda-bindings are absent from it" — and crates/cuda-macros/tests/device-only/Cargo.lock is tracked. A resolution free to move is not the one the repository committed.

Reproduction

On a clean tree, delete the cuda-device package block from that committed lock, then run the guard exactly as cargo-deny.yml does:

Before

OK: device-only graph is host-free (8 packages).
OK: crates/cuda-macros/tests/device-only type-checks with the CUDA environment unset.
exit=0

…and git diff on the lock came back empty — cargo had quietly resolved it back to the committed content on the way past. The guard passed on a corrupt input and repaired that input, which is the failure mode that leaves nobody a reason to look.

After

error: cargo metadata failed for crates/cuda-macros/tests/device-only/Cargo.toml
       if it reports a stale lock file, commit the updated
       crates/cuda-macros/tests/device-only/Cargo.lock rather than letting the guard
       re-resolve it
exit=1

…and the lock is left exactly as the mutation made it (1 file changed, 7 deletions(-)).

For reference, cargo metadata --locked on the mutated lock reports:

error: cannot update the lock file .../device-only/Cargo.lock because --locked was passed to prevent this

Changes

  • --locked on cargo metadata and on cargo check, so the two invocations cannot disagree about which resolution is under test.
  • The cargo metadata error path now names the lock file, since "commit the updated lock" is the fix and re-resolving is what we just stopped doing silently.

Testing

Local, no GPU and no CUDA toolkit — the guard unsets the CUDA environment itself.

  • Clean tree passes unchanged (8 packages, fixture type-checks)
  • The mutation above now fails, and leaves the lock alone
  • Restoring the lock passes again
  • cargo oxide run <example> — not applicable, CI script only

`check-device-only-build.sh` is the only guard in scripts/ that resolves a
Cargo graph without `--locked`. Its sibling states the rule it is missing:

    # `--locked` so the guard reads the committed resolution rather than
    # silently updating Cargo.lock to satisfy itself: a check that can
    # rewrite its own input is not a check.
        -- scripts/check-dependency-licenses.sh

check-example-license-policy.sh passes `--locked` too, and NVIDIA#806 added it to
all three executable `cargo deny` invocations for the same reason.

It matters more here than in either of those, because this guard's whole
assertion is about the *resolved* graph -- "cuda-host, cuda-core and
cuda-bindings are absent from it". A resolution free to move is not the one
the repository committed, and `crates/cuda-macros/tests/device-only/Cargo.lock`
is tracked.

Reproduced on a clean tree by deleting the `cuda-device` package block from
that committed lock:

    before:  OK: device-only graph is host-free (8 packages).
             OK: ... type-checks with the CUDA environment unset.
             exit=0        # and `git diff` on the lock came back empty --
                           # cargo had quietly resolved it back

    after:   error: cargo metadata failed for .../device-only/Cargo.toml
             exit=1        # lock left exactly as the mutation made it

So the guard both passed on a corrupt input and repaired that input on its
way past, which is the failure mode that leaves nobody with a reason to
look. `cargo check` gets the flag as well, for the same reason and so the
two invocations cannot disagree about which resolution is under test.

The error path now names the lock file, since "commit the updated lock"
is the fix and re-resolving is what we just stopped doing silently.

Verified: clean tree passes unchanged; the mutation above now fails and
leaves the lock alone; restoring the lock passes again.

Signed-off-by: Vyncint Ng <[email protected]>
@nihalpasham nihalpasham added bug Something isn't working build-related Build scripts, toolchain discovery, or compilation setup supply-chain Dependency policy: licenses, sources, security advisories, lock files labels Aug 17, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

The premise checks out:

  • without --locked, cargo will quietly rewrite the very lock the guard is judging,
  • ran cargo metadata --locked against main's fixture: passes with the same host-free 8-package graph and the lock untouched, so CI stays green after this,
  • same convention ci: pin the lock on the root cargo-deny run #806 and the license guards already use.

Merging.

@nihalpasham
nihalpasham merged commit b735c78 into NVIDIA:main Aug 17, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working build-related Build scripts, toolchain discovery, or compilation setup supply-chain Dependency policy: licenses, sources, security advisories, lock files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants