Skip to content

Probe cargo for -Z json-target-spec support instead of guessing from the version - #12726

Open
athei wants to merge 1 commit into
masterfrom
at/fixtures-json-target-spec
Open

Probe cargo for -Z json-target-spec support instead of guessing from the version#12726
athei wants to merge 1 commit into
masterfrom
at/fixtures-json-target-spec

Conversation

@athei

@athei athei commented Jul 22, 2026

Copy link
Copy Markdown
Member

Both PolkaVM build paths compile against a .json target spec produced by polkavm-linker,
so both have to decide whether to pass cargo -Z json-target-spec: newer cargo requires the
flag for a JSON target, older cargo rejects it as unknown.

Both decided by comparing a version against 1.95. pallet-revive-fixtures compared the
rustc version to gate a cargo flag
— the wrong binary entirely. wasm-builder compared
the cargo version, which looks right but is not sufficient either: the flag landed partway
through the 1.95 cycle, so a nightly from early in that cycle reports 1.95 from both
binaries while its cargo does not know the flag yet:

rustc 1.95.0-nightly (474276961 2026-01-26)
cargo 1.95.0-nightly (efcd9f586 2026-01-23)   <- no json-target-spec

That is exactly the toolchain in our CI image (ci-unified:bullseye-1.93.0-2026-01-27), so
any job that builds the fixtures on nightly fails:

error: failed to run custom build command for `pallet-revive-fixtures`
  error: unknown `-Z` flag specified: json-target-spec

This is what breaks check-semver on PRs that touch pallet-revive-fixtures (it is one of
the few jobs running nightly rather than the pinned stable, because rustdoc JSON is
nightly-only). It was not hit before because no other PR makes parity-publish rebuild that
crate, and wasm-builder never hit it because its JSON-target path only runs for
SUBSTRATE_RUNTIME_TARGET=riscv.

Since no version comparison can express "does this cargo accept this flag", ask cargo:

fn supports_json_target_spec(&self) -> bool {
    self.command()
        .env("RUSTC_BOOTSTRAP", "1")
        .args(["-Z", "help"])
        .output()
        .is_ok_and(|out| String::from_utf8_lossy(&out.stdout).contains("json-target-spec"))
}

While here, the fixture builder had one more flag on the wrong oracle: a single rustc-version
bool drove both -Cpanic=immediate-abort (a rustc flag) and the
-Zbuild-std-features=panic_immediate_abort fallback (a cargo flag). Those are now separate,
each gated on the version of the binary that parses it. wasm-builder needed no such change:
its CargoCommand::version already comes from cargo --version, and the rustc version is
only used for the "Using rustc version:" printout.

Testing

  • Fixtures build clean on stable, contracts actually produced (not a cached skip).
  • Under nightly-2026-01-27 — the CI toolchain — the unknown -Z flag error is gone.
  • cargo test -p pallet-revive --lib tests::pvm: 137 passed, 0 failed.

@athei
athei requested a review from a team as a code owner July 22, 2026 18:14
@athei athei added T0-node This PR/Issue is related to the topic “node”. T7-smart_contracts This PR/Issue is related to smart contracts. labels Jul 22, 2026
@athei
athei requested a review from koute as a code owner July 22, 2026 18:14
@athei athei added T0-node This PR/Issue is related to the topic “node”. T7-smart_contracts This PR/Issue is related to smart contracts. labels Jul 22, 2026
…the version

Both PolkaVM build paths compile against a `.json` target spec produced by
polkavm-linker and have to decide whether to pass cargo `-Z json-target-spec`:
newer cargo requires the flag, older cargo rejects it as unknown.

Both decided by comparing a version against 1.95 -- the fixture builder against
the *rustc* version, wasm-builder against the cargo version. Neither works. The
flag landed partway through the 1.95 cycle, so a nightly from early in that cycle
reports 1.95 from both binaries while its cargo does not know the flag yet:

    rustc 1.95.0-nightly (474276961 2026-01-26)
    cargo 1.95.0-nightly (efcd9f586 2026-01-23)
    error: unknown `-Z` flag specified: json-target-spec

Ask cargo which unstable flags it accepts instead of inferring it from a version.
@athei
athei force-pushed the at/fixtures-json-target-spec branch from 41bde5a to 158f93f Compare July 22, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T0-node This PR/Issue is related to the topic “node”. T7-smart_contracts This PR/Issue is related to smart contracts.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant