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
46 changes: 42 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ jobs:
rust: ${{ steps.classify.outputs.rust }}
rust_full: ${{ steps.classify.outputs.rust_full }}
rust_packages: ${{ steps.classify.outputs.rust_packages }}
rust_targets: ${{ steps.classify.outputs.rust_targets }}
rust_lint_packages: ${{ steps.classify.outputs.rust_lint_packages }}
rust_lint_features: ${{ steps.classify.outputs.rust_lint_features }}
rust_lint_targets: ${{ steps.classify.outputs.rust_lint_targets }}
rust_doc_libraries: ${{ steps.classify.outputs.rust_doc_libraries }}
rust_sv_tests: ${{ steps.classify.outputs.rust_sv_tests }}
rust_features: ${{ steps.classify.outputs.rust_features }}
rust_filter: ${{ steps.classify.outputs.rust_filter }}
rust_libraries: ${{ steps.classify.outputs.rust_libraries }}
Expand Down Expand Up @@ -139,15 +145,42 @@ jobs:
fi

- name: cargo clippy
if: needs.changes.result != 'success' || needs.changes.outputs.rust == 'true'
if: (needs.changes.result != 'success' || needs.changes.outputs.rust == 'true') && needs.changes.outputs.rust_full != 'false'
run: cargo clippy --locked -p celox-test-suite -p celox -p celox-frontend-core -p celox-frontend-sv -p celox-frontend-veryl -p celox-macros -p celox-napi -p celox-sv-analyzer -p celox-ts-gen -p celox-vpi -p lydite-ir -p lydite -p lydite-celox -p lydite-solver -p lydite-syntax -p lydite-verify --all-targets --features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus --no-deps

- name: Lint the crates this pull request can affect
if: needs.changes.outputs.rust_full == 'false' && needs.changes.outputs.rust_lint_packages != ''
env:
PACKAGES: ${{ needs.changes.outputs.rust_lint_packages }}
FEATURES: ${{ needs.changes.outputs.rust_lint_features }}
TARGETS: ${{ needs.changes.outputs.rust_lint_targets }}
run: |
args=()
for package in $PACKAGES; do args+=(-p "$package"); done
if [ -n "$FEATURES" ]; then args+=(--features "$FEATURES"); fi
if [ -n "$TARGETS" ]; then
for target in $TARGETS; do args+=(--test "$target"); done
else
args+=(--all-targets)
fi
cargo clippy --locked "${args[@]}" --no-deps

- name: Build Rust API documentation
if: needs.changes.result != 'success' || needs.changes.outputs.rust == 'true'
if: (needs.changes.result != 'success' || needs.changes.outputs.rust == 'true') && needs.changes.outputs.rust_full != 'false'
env:
RUSTDOCFLAGS: -D warnings
run: cargo doc --locked --workspace --no-deps

- name: Build the API documentation this pull request can affect
if: needs.changes.outputs.rust_full == 'false' && needs.changes.outputs.rust_doc_libraries != ''
env:
RUSTDOCFLAGS: -D warnings
LIBRARIES: ${{ needs.changes.outputs.rust_doc_libraries }}
run: |
args=()
for package in $LIBRARIES; do args+=(-p "$package"); done
cargo doc --locked --no-deps "${args[@]}"

- uses: pnpm/action-setup@v6
if: needs.changes.result != 'success' || needs.changes.outputs.javascript == 'true'

Expand Down Expand Up @@ -197,10 +230,12 @@ jobs:
save-if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}

- uses: actions/setup-python@v7
if: needs.changes.outputs.rust_full != 'false' || contains(format(' {0} ', needs.changes.outputs.rust_packages), ' celox-vpi ')
with:
python-version: "3.14"

- name: Install cocotb
if: needs.changes.outputs.rust_full != 'false' || contains(format(' {0} ', needs.changes.outputs.rust_packages), ' celox-vpi ')
run: python -m pip install cocotb==2.1.0

- name: Install cargo-nextest
Expand All @@ -227,12 +262,14 @@ jobs:
PACKAGES: ${{ needs.changes.outputs.rust_packages }}
FEATURES: ${{ needs.changes.outputs.rust_features }}
FILTER: ${{ needs.changes.outputs.rust_filter }}
TARGETS: ${{ needs.changes.outputs.rust_targets }}
run: |
echo "Packages: $PACKAGES"
echo "Filter: $FILTER"
args=()
for package in $PACKAGES; do args+=(-p "$package"); done
if [ -n "$FEATURES" ]; then args+=(--features "$FEATURES"); fi
for target in $TARGETS; do args+=(--test "$target"); done
cargo nextest run --locked --profile ci \
--no-tests=pass "${args[@]}" -E "$FILTER"

Expand Down Expand Up @@ -359,7 +396,7 @@ jobs:
sv-tests:
name: sv-tests conformance
needs: changes
if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.rust == 'true') }}
if: ${{ !cancelled() && (needs.changes.result != 'success' || (needs.changes.outputs.rust == 'true' && needs.changes.outputs.rust_sv_tests != 'false')) }}
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
Expand Down Expand Up @@ -506,6 +543,7 @@ jobs:
CHANGES_RESULT: ${{ needs.changes.result }}
RUST_REQUIRED: ${{ needs.changes.outputs.rust }}
RUST_RESULT: ${{ needs.rust-tests.result }}
SV_TESTS_REQUIRED: ${{ needs.changes.outputs.rust != 'false' && needs.changes.outputs.rust_sv_tests != 'false' }}
SV_TESTS_RESULT: ${{ needs.sv-tests.result }}
# Platform coverage is mandatory in queue and full validation runs.
ARM64_REQUIRED: ${{ needs.changes.outputs.queue != 'false' && needs.changes.outputs.rust != 'false' }}
Expand All @@ -524,7 +562,7 @@ jobs:
if [ "$RUST_REQUIRED" != false ] || [ "$RUST_RESULT" != skipped ]; then
test "$RUST_RESULT" = success
fi
if [ "$RUST_REQUIRED" != false ] || [ "$SV_TESTS_RESULT" != skipped ]; then
if [ "$SV_TESTS_REQUIRED" != false ] || [ "$SV_TESTS_RESULT" != skipped ]; then
test "$SV_TESTS_RESULT" = success
fi
if [ "$ARM64_REQUIRED" != false ] || [ "$ARM64_RESULT" != skipped ]; then
Expand Down
28 changes: 24 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,30 @@ Lydite has its own test cadence (`scripts/ci-lydite-changes.mjs`):
excludes them, and fails on selected-job failures or cancellations. Repository
branch protection must require this check to make it a merge gate.

The classifier selects CI jobs, not individual Rust tests. Selected Rust CI
still runs the Celox workspace suite with CI features, doctests, default-feature
checks, ARM64 backend checks, and the explicit cocotb test. Local validation
uses the finer behavior-based matrix above.
Ordinary PRs also scope Rust compilation and execution:

- Library changes select the crate and its transitive consumers. Backend and
SV frontend changes narrow Celox integration tests to the affected variants;
shared implementation changes retain all affected variants.
- A single package's integration test or recognized Insta snapshot changes
select only the corresponding test binaries, using Cargo `--test` as well
as a nextest filter. Shared helpers and fixtures retain the package's tests;
mixed library/test changes combine their requirements.
- Clippy selects affected crates and test targets, including Lydite. Rust API
documentation and doctests select libraries reached through runtime/build
dependencies; dev-only consumers still run tests but do not rebuild their
API documentation. Test-only changes skip API documentation and doctests.
- sv-tests conformance runs when the Celox library or its runtime/build
dependencies change, or its runner/expectations change. Test infrastructure
and downstream consumers do not select this separate release-mode build.
- Python/cocotb setup runs only when VPI tests are selected.

Queue drafts, merge groups, releases, `ci:full`, and daily/manual full runs
retain the existing workspace tests, lint, documentation, sv-tests and platform
coverage. Cargo manifest, lockfile, toolchain, unknown-path and failed scope
analysis changes fall back to broad validation. Required checks permit skips
only when explicitly unneeded and still reject failures and cancellations.
Local validation uses the behavior-based matrix above.

| Cadence | Coverage |
| --- | --- |
Expand Down
24 changes: 21 additions & 3 deletions scripts/ci-changes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -314,20 +314,30 @@ export function celoxRustTestScope(files, packages) {

// Queue drafts, merge groups, releases and daily runs keep the Celox
// workspace. Lydite tests run independently in lydite-checks.yml.
function rustScopeOutputs(files) {
export function rustScopeOutputs(files) {
let scope = { full: true };
let checks;
if (files !== null) {
try {
const root = fileURLToPath(new URL("../", import.meta.url));
scope = celoxRustTestScope(files, readWorkspace(root));
const packages = readWorkspace(root);
scope = celoxRustTestScope(files, packages);
// Lydite owns its tests, but lint and API documentation still live here.
checks = rustTestScope(files, packages);
} catch (error) {
console.warn(`Unable to scope the Rust tests: ${error.message}`);
}
}
if (scope.full) {
if (scope.full || !checks || checks.full) {
return {
rust_full: true,
rust_packages: "",
rust_targets: "",
rust_lint_packages: "",
rust_lint_features: "",
rust_lint_targets: "",
rust_doc_libraries: "",
rust_sv_tests: true,
rust_features: "",
rust_filter: "",
rust_libraries: "",
Expand All @@ -337,6 +347,14 @@ function rustScopeOutputs(files) {
return {
rust_full: false,
rust_packages: scope.packages.join(" "),
rust_targets: scope.targets.join(" "),
rust_lint_packages: checks.packages.join(" "),
rust_lint_features: checks.features.join(","),
rust_lint_targets: checks.targets.join(" "),
rust_doc_libraries: checks.libraries.join(" "),
// Test-only and consumer changes cannot change sv-tests results.
rust_sv_tests: scope.libraries.includes("celox") || files.some((path) =>
/^(?:\.\/)?(?:conformance\/sv-tests\/|crates\/celox\/examples\/sv_tests\.rs$)/.test(path)),
rust_features: scope.features.join(","),
rust_filter: scope.filter,
rust_libraries: scope.libraries.join(" "),
Expand Down
52 changes: 52 additions & 0 deletions scripts/ci-changes.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
classifyFiles,
cutsRelease,
isReleaseMergeGroup,
rustScopeOutputs,
} from "./ci-changes.mjs";

const none = {
Expand Down Expand Up @@ -147,6 +148,12 @@ test("full validation overrides even an empty valid diff", () => {
// The whole Rust workspace, with no package scope or filter.
rust_full: true,
rust_packages: false,
rust_targets: false,
rust_lint_packages: false,
rust_lint_features: false,
rust_lint_targets: false,
rust_doc_libraries: false,
rust_sv_tests: true,
rust_features: false,
rust_filter: false,
rust_libraries: false,
Expand Down Expand Up @@ -534,3 +541,48 @@ test("PR branches behind their base ignore unmerged base changes", (t) => {
{ ...none, docs: true, heliodor_arm64: false, release: false },
);
});


test("test and consumer PRs skip sv-tests; implementation and full runs retain it", () => {
for (const path of [
"crates/celox/tests/flip_flop.rs",
"crates/celox/tests/test_utils/mod.rs",
"crates/celox/tests/snapshots/flip_flop__optimized.snap",
"crates/celox-test-suite/src/lib.rs",
"crates/celox-vpi/src/lib.rs",
"crates/celox-napi/src/lib.rs",
"crates/lydite/src/lib.rs",
]) {
assert.equal(rustScopeOutputs([path]).rust_sv_tests, false, path);
}
for (const files of [
null,
["Cargo.lock"],
["conformance/sv-tests/expected.tsv"],
["crates/celox/examples/sv_tests.rs"],
["crates/celox/src/lib.rs"],
["crates/celox-frontend-sv/src/lib.rs"],
["crates/celox-runtime/src/lib.rs"],
["crates/celox-backend-x86/src/lib.rs"],
["crates/celox/tests/flip_flop.rs", "crates/celox/src/lib.rs"],
]) {
assert.equal(rustScopeOutputs(files).rust_sv_tests, true, JSON.stringify(files));
}
const testOnly = rustScopeOutputs(["crates/celox/tests/flip_flop.rs"]);
assert.equal(testOnly.rust_targets, "flip_flop");
assert.equal(testOnly.rust_libraries, "");
assert.equal(rustScopeOutputs(null).rust_full, true);
});


test("Lydite lint and API documentation remain selected in CI", () => {
const scope = rustScopeOutputs(["crates/lydite-ir/src/lib.rs"]);
assert.equal(scope.rust_packages, "");
assert.ok(scope.rust_lint_packages.split(" ").includes("lydite-ir"));
assert.ok(scope.rust_doc_libraries.split(" ").includes("lydite-ir"));
const mixed = rustScopeOutputs([
"crates/celox/tests/flip_flop.rs", "crates/lydite-ir/src/lib.rs",
]);
assert.equal(mixed.rust_targets, "flip_flop");
assert.equal(mixed.rust_lint_targets, "");
});
31 changes: 29 additions & 2 deletions scripts/ci-rust-scope.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ export function rustTestScope(files, packages) {
const byName = new Map(packages.map((pkg) => [pkg.name, pkg]));
const owners = [...packages].sort((a, b) => b.dir.length - a.dir.length);
const dependents = new Map(packages.map((pkg) => [pkg.name, new Set()]));
const libraryDependents = new Map(packages.map((pkg) => [pkg.name, new Set()]));
for (const pkg of packages) {
for (const dep of pkg.dependencies) dependents.get(dep)?.add(pkg.name);
for (const dep of pkg.libraryDependencies ?? pkg.dependencies) {
libraryDependents.get(dep)?.add(pkg.name);
}
}

const sources = new Set();
Expand All @@ -110,6 +114,7 @@ export function rustTestScope(files, packages) {
for (const raw of files) {
const path = raw.replace(/^\.\//, "");
if (!classifyFiles([path]).rust) continue;
if (/(?:^|\/)Cargo\.(?:toml|lock)$/.test(path)) return { full: true };
// lydite's tests read its examples and audits from the top-level folder.
if (path.startsWith("lydite/")) {
for (const pkg of packages) {
Expand All @@ -121,8 +126,12 @@ export function rustTestScope(files, packages) {
if (!owner) return { full: true };
const inner = path.slice(owner.dir.length + 1);
const test = /^tests\/([^/]+)\.rs$/.exec(inner);
// Insta prefixes snapshots with their integration-test binary name.
const snapshot = /^tests\/snapshots\/([^/]+?)__[^/]+\.snap(?:\.new)?$/.exec(inner);
if (test && owner.tests.includes(test[1])) {
addBinary(owner.name, test[1]);
} else if (snapshot && owner.tests.includes(snapshot[1])) {
addBinary(owner.name, snapshot[1]);
} else if (
owner.name === "celox" &&
inner.startsWith("tests/frontends/systemverilog/")
Expand All @@ -136,6 +145,19 @@ export function rustTestScope(files, packages) {
}

// Everything each changed library reaches through its dependents.
const libraries = new Set();
for (const seed of sources) {
const queue = [seed];
libraries.add(seed);
while (queue.length > 0) {
for (const next of libraryDependents.get(queue.pop()) ?? []) {
if (!libraries.has(next)) {
libraries.add(next);
queue.push(next);
}
}
}
}
const affected = new Set();
const celoxSeeds = [];
for (const seed of sources) {
Expand Down Expand Up @@ -201,8 +223,13 @@ export function rustTestScope(files, packages) {
packages: [...selected].sort(),
features: features(selected),
filter: terms.join(" | "),
libraries: [...affected].sort(),
libraryFeatures: features(affected),
// A nextest filter controls execution, not Cargo compilation. When only
// specific binaries of one package changed, avoid building all its tests.
targets: affected.size === 0 && wholeTests.size === 0 && selected.size === 1
? [...binaries.get([...selected][0])].sort()
: [],
Comment on lines +228 to +230

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Enable required features for narrowed test targets

When an ordinary PR changes crates/celox/tests/sv_dpi.rs, this branch emits targets: ["sv_dpi"], while features(selected) only returns entries from CI_FEATURES and therefore enables celox/systemverilog, not the target's required sv-dpi feature (crates/celox/Cargo.toml:119-122). The scoped Rust-test and clippy steps then pass --test sv_dpi; cargo test --help describes this as “Test only the specified test target,” and Cargo rejects this explicitly selected target with status 101 unless sv-dpi is enabled. Such PRs therefore fail both scoped commands instead of validating the changed test, so the scope needs to include target-required features or avoid narrowing this target.

Useful? React with 👍 / 👎.

libraries: [...libraries].sort(),
libraryFeatures: features(libraries),
};
}

Expand Down
39 changes: 39 additions & 0 deletions scripts/ci-rust-scope.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ test("a test file change runs only that binary and nothing downstream", () => {
packages: ["celox"],
features: ["celox/systemverilog"],
filter: "binary_id(celox::flip_flop)",
targets: ["flip_flop"],
libraries: [],
libraryFeatures: [],
});
Expand Down Expand Up @@ -127,6 +128,8 @@ test("lydite's shared folder runs every lydite package", () => {
test("changes outside the workspace graph run every test", () => {
for (const path of [
"Cargo.lock",
"crates/celox/Cargo.toml",
"crates/celox/tests/fixtures/custom/Cargo.lock",
"Cargo.toml",
"testdata/verilator/adder.sv",
"rust-toolchain.toml",
Expand Down Expand Up @@ -181,3 +184,39 @@ test("variant crates reach celox only through crates of the same variant", () =>
}
}
});


test("test-only changes narrow Cargo compilation as well as nextest execution", () => {
const scope = rustTestScope([
"crates/celox/tests/flip_flop.rs",
"crates/celox/tests/snapshots/flip_flop__optimized.snap",
"crates/celox/tests/frontends/systemverilog/operators.rs",
], workspace);
assert.deepEqual(scope.targets, ["flip_flop", "systemverilog"]);
assert.deepEqual(scope.libraries, []);
assert.deepEqual(rustTestScope([
"crates/celox/tests/flip_flop.rs", "crates/lib/src/lib.rs",
], workspace).targets, []);
assert.deepEqual(rustTestScope([
"crates/celox/tests/flip_flop.rs", "crates/consumer/tests/e2e.rs",
], workspace).targets, []);
for (const path of [
"crates/celox/tests/test_utils/mod.rs",
"crates/celox/tests/snapshots/unknown__result.snap",
"crates/celox/tests/fixtures/design.veryl",
]) {
const shared = rustTestScope([path], workspace);
assert.deepEqual(shared.targets, [], path);
assert.equal(shared.filter, "package(celox)", path);
}
});

test("a dev dependency affects consumer tests but not consumer documentation", () => {
const packages = workspace.map((pkg) => ({
...pkg,
libraryDependencies: pkg.dependencies.filter((name) => name !== "lib"),
}));
const scope = rustTestScope(["crates/lib/src/lib.rs"], packages);
assert.ok(scope.packages.includes("celox"));
assert.deepEqual(scope.libraries, ["lib"]);
});
Loading
Loading