Skip to content

refactor(rust): derive cross test runners from qemuArch - #651

Open
rvolosatovs wants to merge 1 commit into
mainfrom
refactor/rust-test-runner-table
Open

refactor(rust): derive cross test runners from qemuArch#651
rvolosatovs wants to merge 1 commit into
mainfrom
refactor/rust-test-runner-table

Conversation

@rvolosatovs

Copy link
Copy Markdown
Owner

The per-target test-runner selection in buildPackageFor was a ~150-line if/else chain with one branch per target, each hardcoding CARGO_TARGET_<T>_RUNNER = "qemu-<arch>" and repeating the same "disable testing on a Darwin build host" guard.

Every qemu-<arch> value is exactly pkgsCross.stdenv.hostPlatform.qemuArch (verified for all previously-listed targets: aarch64, arm, mips/mips64(el), ppc64(le), riscv64, s390x, x86_64), so the whole chain collapses to:

  • an explicit noTestRunner list for targets with no usable emulator (android, wasm32-unknown-unknown, windows-under-sandbox),
  • wasmtime for wasm targets (works on every host, incl. Darwin),
  • qemu-${qemuArch} for everything else, with the Darwin guard applied once, and the original "unknown runner" warning kept as a fallback for targets whose qemuArch is null.

Net: 139 lines removed, 22 added. Behaviour is preserved for the targets in the examples/CI matrix; emulatable Linux targets that previously fell through to the warning now get a qemu runner automatically, so adding such a target no longer requires editing this function.

Verified by cross-building rust-complex for x86_64-unknown-linux-gnu on an aarch64-linux host: its test suite runs under qemu-x86_64.

The per-target test-runner selection in `buildPackageFor` was a ~150-line
`if/else` chain with one branch per target, each hardcoding
`CARGO_TARGET_<T>_RUNNER = "qemu-<arch>"` and repeating the same
"disable testing on a Darwin build host" guard.

Every `qemu-<arch>` value is exactly `pkgsCross.stdenv.hostPlatform.qemuArch`
(verified for all previously-listed targets: aarch64, arm, mips/mips64(el),
ppc64(le), riscv64, s390x, x86_64), so the whole chain collapses to:

  - an explicit `noTestRunner` list for targets with no usable emulator
    (android, wasm32-unknown-unknown, windows-under-sandbox),
  - `wasmtime` for wasm targets (works on every host, incl. Darwin),
  - `qemu-${qemuArch}` for everything else, with the Darwin guard applied
    once, and the original "unknown runner" warning kept as a fallback for
    targets whose `qemuArch` is null.

Net: 139 lines removed, 22 added. Behaviour is preserved for the targets
in the examples/CI matrix; emulatable Linux targets that previously fell
through to the warning now get a qemu runner automatically, so adding such
a target no longer requires editing this function.

Verified by cross-building `rust-complex` for `x86_64-unknown-linux-gnu`
on an aarch64-linux host: its test suite runs under `qemu-x86_64`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Refactors cross-compilation test-runner selection by deriving the Cargo runner from pkgsCross.stdenv.hostPlatform.qemuArch, replacing a long per-target conditional chain while preserving previous behavior for known targets.

Changes:

  • Introduces a single computed runnerEnv and uses it to set CARGO_TARGET_<TRIPLE>_RUNNER dynamically.
  • Adds a small explicit “no test runner” list for targets that cannot be cross-tested in this environment.
  • Uses wasmtime for WASM targets and qemu-${qemuArch} for other emulatable targets, applying the Darwin guard once.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/rust/mkAttrs.nix
else
warn
"do not know which test runner to use for target `${target}`, set `CARGO_TARGET_${toUpper (kebab2snake target)}_RUNNER` to appropriate `qemu` binary name"
"do not know which test runner to use for target `${target}`, set `${runnerEnv}` to appropriate `qemu` binary name"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants