Skip to content

ci: extend the license inventory guard to the example workspaces - #664

Merged
nihalpasham merged 3 commits into
NVIDIA:mainfrom
vyncint:fix/license-guard-example-workspaces
Aug 6, 2026
Merged

nihalpasham merged 3 commits into
NVIDIA:mainfrom
vyncint:fix/license-guard-example-workspaces

Conversation

@vyncint

@vyncint vyncint commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Addresses #663.

cargo deny check resolves the root workspace, and the guard from #662 checks that same graph. Every example under crates/rustc-codegen-cuda/examples/ sets its own [workspace], so neither sees any of them — six examples declare third-party dependencies, pulling 68 distinct crates recorded in neither place, with no license gate over any of them.

Not a violation today: deny.toml's allow-list plausibly covers all 68. The problem is that nothing would say so if it did not.

What the guard now does

For each example lock file, every package must be covered — in the root graph, in the CSV, or carrying no source field.

That last case is a path dependency, first-party by construction. Name matching is avoided deliberately: cutile_inter_kernel pulls cuda-core, cuda-async and cuda-bindings by git rather than by path, so a heuristic over crate names would misfile first-party crates as third-party. I only found that by checking, having assumed the opposite.

Lock files are parsed directly rather than via cargo metadata — resolving 178 workspaces would be slow and would need the network. The existing cargo-deny / license-manifest job already runs this script and stays CPU-only, so there is no workflow change.

It also skips the 172 examples that declare only path dependencies, so in practice this checks 6 workspaces.

Rows added

Eight crates, for the five small examples:

Crate Version License Pulled by
tokio, tokio-macros 1.52.3, 2.7.0 MIT async_mlp, async_vecadd
rayon, rayon-core 1.12.0, 1.13.0 MIT OR Apache-2.0 hashmap_v2, hashmap_v3
crossbeam-deque, -epoch, -utils 0.8.6, 0.9.18, 0.8.21 MIT OR Apache-2.0 via rayon
libm 0.2.16 MIT libm_math

Every license, repository and description is read from that crate's own manifest rather than transcribed from memory — libm is plain MIT, not the dual license the others use, which is exactly the sort of thing worth not guessing in a license file.

Following #631 and #662: the CSV edit is insert-only (git diff --numstat is 8 0, no existing row modified), rows land in the file's existing LC_ALL=C order, and CRLF endings are preserved via binary I/O.

The one thing left open

cutile_inter_kernel sits in INVENTORY_EXEMPT_EXAMPLES. Its git dependency on cutile-rs resolves ~60 further crates — wasm-bindgen, wit-bindgen, wasmparser, windows-targets — that exist in this tree only to build one interop example. Whether those belong in the inventory is the question in #663, and I would rather leave a documented, single-line lever than add 60 rows on a guess. Delete that one entry and the guard requires the rows instead.

Names in that list are validated against the examples on disk, so a typo or a rename fails the run rather than quietly exempting nothing — or everything. Given that this PR exists because a guard's coverage stopped short of what it appeared to check, an exemption that could silently widen seemed worth closing off.

Verification

CPU-only; no GPU, CUDA toolkit or LLVM.

# Scenario Expected Result
1 Guard against the CSV as it is on main fail exit 1, lists the 6 examples and 68 crates
2 After adding the rows pass exit 0, both halves report OK
3 Delete a new row (rayon) fail exit 1, names rayon
4 Drop the exemption fail exit 1, names cutile_inter_kernel
5 Typo the exemption fail exit 1, "names no such example: cutile_inter_kernl"
6 Lock glob matches nothing fail exit 1, "parse self-test failed: found 0 example lock files"

3–6 follow the #643 lesson, and #662's locale bug: a guard that cannot fail loudly is the defect, not the coverage gap.

bash -n clean, the root-workspace half still reports its 51 crates unchanged, and CONTRIBUTING.md gains four lines so the rule is discoverable before CI enforces it.

Not included

crates/rustc-codegen-cuda is its own workspace too, and was the follow-up suggested on #662 — but I measured it and its 93-package graph is a strict subset of the root's 160, so cargo deny check already covers every third-party crate the shipped backend uses. Only the first-party rustc_codegen_cuda crate itself lacks a row. Nothing to enforce there; noted in #663 rather than changed here.

`cargo deny check` resolves the root workspace, and the guard added in NVIDIA#662
checks that same graph against dependency-licenses.csv. Every example under
crates/rustc-codegen-cuda/examples/ sets its own `[workspace]`, so neither sees
any of them. Six examples declare third-party dependencies, pulling 68 distinct
crates recorded in neither place, and nothing enforced the license policy over
them.

The guard now also reads the example lock files. A package counts as covered
when it appears in the root graph, has a CSV row, or carries no `source` field
-- that last case being a path dependency, first-party by construction. Name
matching is avoided deliberately: cutile_inter_kernel pulls cuda-core and its
siblings by git rather than by path, so a heuristic over names would misfile
first-party crates as third-party.

Lock files are parsed directly rather than through `cargo metadata`, because
resolving 178 separate workspaces would be slow and would need the network. The
existing `cargo-deny / license-manifest` job already runs this script and stays
CPU-only.

Rows added for the eight crates the five small examples pull: tokio and
tokio-macros (MIT), rayon, rayon-core and crossbeam-{deque,epoch,utils}
(MIT OR Apache-2.0), and libm (MIT). Each license, repository and description
is read from the crate's own manifest rather than transcribed. The CSV edit is
insert-only -- `git diff --numstat` is `8 0` -- rows land in the file's existing
LC_ALL=C order, and its CRLF line endings are preserved.

cutile_inter_kernel is listed in INVENTORY_EXEMPT_EXAMPLES for now: its git
dependency on cutile-rs resolves ~60 further crates that exist in this tree
only to build one interop example, and whether those belong in the inventory is
the open question in NVIDIA#663. Deleting the entry requires the rows instead. Names
in that list are checked against the examples on disk, so a typo or a rename
fails the run rather than quietly exempting nothing -- or everything.

Verified: passes clean; fails naming the crate when a new row is deleted; fails
naming cutile_inter_kernel when the exemption is dropped; fails with "no such
example" on a typo'd exemption; and the lock-parse self-test fires when the glob
matches nothing.

Refs NVIDIA#663

Signed-off-by: Vyncint Ng <[email protected]>
Suggested by @nihalpasham reviewing NVIDIA#662. Without it the guard may resolve and
rewrite Cargo.lock to satisfy its own query, which means a check that can
modify its own input -- and in CI it would quietly paper over a stale lockfile
rather than reporting one.

Verified: `cargo metadata --locked --format-version 1` exits 0 against the
committed lockfile, and the guard still reports both halves OK.

Signed-off-by: Vyncint Ng <[email protected]>
@vyncint

vyncint commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Pushed a10bb84d: --locked on the cargo metadata call, which you suggested reviewing #662. It seemed better folded in here than sent as a follow-up, since it touches the same line this PR already moves — a separate PR would just conflict.

Verified cargo metadata --locked --format-version 1 exits 0 against the committed lockfile, and the guard still reports both halves OK.

Your other #662 follow-up — a second pass over crates/rustc-codegen-cuda — I measured and did not act on: its 93-package graph is a strict subset of the root's 160, so cargo deny check already covers every third-party crate the shipped backend uses. Only the first-party rustc_codegen_cuda crate itself lacks a CSV row. Noted in #663 rather than changed here, since there is nothing to enforce.

The lockfile glob was depth-1 only, so a Cargo.lock inside a nested
sub-workspace (cutile_inter_kernel/simt already has one, with 59
registry-sourced packages) was never opened and a future example with a
nested workspace would escape the guard silently. Search recursively
and attribute each lockfile to its top-level example so the exemption
list keeps working however deep the lock sits. Also drop the stale
'178 separate workspaces' count from the comment.
@nihalpasham nihalpasham added enhancement New feature or request build-related Build scripts, toolchain discovery, or compilation setup labels Aug 6, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

The guard architecture is consistent with the #662 first half (presence-only, no network, same CI job) and the design choices held up under review — first-party by absence of a lock source field, exemption list validated against disk, parse self-tests against the silent-blindness failure mode. I pushed one commit on top:

@nihalpasham
nihalpasham merged commit 62e999c into NVIDIA:main Aug 6, 2026
58 of 65 checks passed
vyncint added a commit to vyncint/cuda-oxide that referenced this pull request Aug 6, 2026
`cargo deny check` resolves the root workspace. Every example under
crates/rustc-codegen-cuda/examples/ sets its own `[workspace]`, so the root run
stops at that boundary and the license, source and advisory policies never see
any crate an example pulls on its own. NVIDIA#664 closed the inventory half of this;
this closes the policy half.

The gap is 131 distinct crates: the root workspace resolves 139 third-party
crates, and the example locks add 131 beyond it. All 187 examples add at least
one.

I had written in NVIDIA#663 that this was "not a violation today". That was wrong.
Running the policy over the example workspaces finds a live advisory:

    error[vulnerability]: Invalid pointer dereference in `fmt::Pointer` impl
    crossbeam-epoch 0.9.18 — RUSTSEC-2026-0204
      crossbeam-epoch v0.9.18
      └── crossbeam-deque v0.8.6
          └── rayon-core v1.13.0
              └── rayon v1.12.0
                  └── hashmap_v2 v0.1.0

so this also bumps crossbeam-epoch to 0.9.20 in the two rayon examples, without
which the new guard would fail on the tree it is added to. Both still build.

The guard runs one cargo-deny per distinct third-party dependency set rather
than one per example: because each example depends on cuda-core and friends by
path, every lock re-lists the root workspace's own transitive crates, and
grouping by the exact set of (name, version) pairs collapses 187 workspaces to
27 runs. That is an equivalence rather than a sample -- licenses, sources and
advisories are per-crate properties, so two workspaces resolving an identical
crate set get an identical verdict, and `bans.multiple-versions` is "warn" and
cannot change the exit status.

cutile_inter_kernel is exempt, because it cannot satisfy the policy as written:

    error[source-not-allowed]: detected 'git' source not explicitly allowed  (x7)
    error[unlicensed]: cuda-bindings = 0.1.0 is unlicensed

The first would need cutile-rs added to `[sources] allow-git`, the second a
license field on a crate this repository does not own. Both are policy calls, so
the example is listed rather than the policy loosened -- the same reason it is
already exempt from the inventory guard. As there, every exempt name is checked
against the examples on disk, so a typo or a rename fails the run instead of
quietly exempting nothing, or everything.

Measured: 186 of 187 example workspaces satisfy deny.toml unchanged.

Refs NVIDIA#663

Signed-off-by: Vyncint Ng <[email protected]>
nihalpasham added a commit that referenced this pull request Aug 7, 2026
* ci: enforce deny.toml over the example workspaces

`cargo deny check` resolves the root workspace. Every example under
crates/rustc-codegen-cuda/examples/ sets its own `[workspace]`, so the root run
stops at that boundary and the license, source and advisory policies never see
any crate an example pulls on its own. #664 closed the inventory half of this;
this closes the policy half.

The gap is 131 distinct crates: the root workspace resolves 139 third-party
crates, and the example locks add 131 beyond it. All 187 examples add at least
one.

I had written in #663 that this was "not a violation today". That was wrong.
Running the policy over the example workspaces finds a live advisory:

    error[vulnerability]: Invalid pointer dereference in `fmt::Pointer` impl
    crossbeam-epoch 0.9.18 — RUSTSEC-2026-0204
      crossbeam-epoch v0.9.18
      └── crossbeam-deque v0.8.6
          └── rayon-core v1.13.0
              └── rayon v1.12.0
                  └── hashmap_v2 v0.1.0

so this also bumps crossbeam-epoch to 0.9.20 in the two rayon examples, without
which the new guard would fail on the tree it is added to. Both still build.

The guard runs one cargo-deny per distinct third-party dependency set rather
than one per example: because each example depends on cuda-core and friends by
path, every lock re-lists the root workspace's own transitive crates, and
grouping by the exact set of (name, version) pairs collapses 187 workspaces to
27 runs. That is an equivalence rather than a sample -- licenses, sources and
advisories are per-crate properties, so two workspaces resolving an identical
crate set get an identical verdict, and `bans.multiple-versions` is "warn" and
cannot change the exit status.

cutile_inter_kernel is exempt, because it cannot satisfy the policy as written:

    error[source-not-allowed]: detected 'git' source not explicitly allowed  (x7)
    error[unlicensed]: cuda-bindings = 0.1.0 is unlicensed

The first would need cutile-rs added to `[sources] allow-git`, the second a
license field on a crate this repository does not own. Both are policy calls, so
the example is listed rather than the policy loosened -- the same reason it is
already exempt from the inventory guard. As there, every exempt name is checked
against the examples on disk, so a typo or a rename fails the run instead of
quietly exempting nothing, or everything.

Measured: 186 of 187 example workspaces satisfy deny.toml unchanged.

Refs #663

Signed-off-by: Vyncint Ng <[email protected]>

* ci(example-policy): check per lock file, key on source, drop --config, add --locked and parse floors

Four hardenings layered on the guard, none architectural:

- Group and check per lock file rather than per example directory, so a
  nested sub-workspace's own resolved graph is policy-checked instead of
  only contributing to its parent's grouping key. An exemption still
  covers every lock under the exempt example.
- Include the source string in the grouping triple: the sources policy
  judges where a crate comes from, so the same (name, version) from
  crates.io and from a git fork must not share a representative.
- Drop --config: cargo-deny resolves deny.toml by walking up from the
  manifest directory (verified on 0.19 and 0.20), while a top-level
  --config flag only exists on 0.20, so the flag made the script fail on
  every older cargo-deny for no coverage gain. Add --locked so a stale
  lock fails the run instead of being silently re-resolved away from the
  graph that determined its grouping.
- Add the sibling guard's parse self-test floors (>= 20 lock files,
  >= 100 parsed packages) so regex rot fails loudly instead of
  collapsing every workspace into one vacuous group.

Also refresh crossbeam-epoch to 0.9.20 in dependency-licenses.csv to
match the bumped hashmap_v2/v3 locks, and correct the measured counts
(187 lock files, 26 representative runs).

Verified: the guard passes end to end against this tree (26
representatives, advisories/bans/licenses/sources ok), the exempt-typo
and missing-locks paths fail loudly by name, the inventory guard stays
green after the CSV refresh, and hashmap_v2/v3 build and PASS the
smoketest on sm_120 with the patched crossbeam-epoch.

---------

Signed-off-by: Vyncint Ng <[email protected]>
Co-authored-by: nihalpasham <[email protected]>
nihalpasham pushed a commit that referenced this pull request Aug 17, 2026
Each guard exempts cutile_inter_kernel and justifies it the same way:

  check-dependency-licenses.sh:
    Whether those belong in the inventory is the open question in #663
  check-example-license-policy.sh:
    Both are policy calls for a maintainer, and they are the open question
    in #663 ... Delete the entry once that is settled.

#663 closed on 2026-08-10. I closed it, saying both halves were enforced in CI,
and that was overstated: #664 and #681 did cover every *other* example
workspace, but this one is on both exemption lists, so its ~60 git-pulled
crates get neither a CSV row nor a `cargo deny check`. Two readers are now sent
to a resolved thread to find a decision that was never made.

The decisions are unchanged and still the maintainer's:

  * `deny.toml`'s `allow-git` lists only pliron, not cutile-rs;
  * the `unlicensed` error names cutile-rs's own vendored `cuda-bindings`
    0.1.0, not this repository's crate of the same name -- ours is 0.2.1 and
    inherits the workspace license -- so that one is not ours to fix at all.

So this repoints both comments at #953, which tracks exactly those two, and
says plainly what the exemption withholds: not just the inventory rows, but the
policy check too, making this the one such hole in the tree. The previous
wording let a reader of the inventory guard assume `cargo deny` still covered
these crates.

Comment-only. Both guards pass unchanged: 55 declared crates recorded, every
example workspace's third-party crates covered, and deny.toml holding over
every example outside POLICY_EXEMPT_EXAMPLES.

Signed-off-by: Vyncint Ng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build-related Build scripts, toolchain discovery, or compilation setup enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants