Skip to content

fix: pass -Zjson-target-spec for .json target specs#22435

Closed
MavenRain wants to merge 1 commit into
rust-lang:masterfrom
MavenRain:fix-json-target-spec
Closed

fix: pass -Zjson-target-spec for .json target specs#22435
MavenRain wants to merge 1 commit into
rust-lang:masterfrom
MavenRain:fix-json-target-spec

Conversation

@MavenRain
Copy link
Copy Markdown
Contributor

@MavenRain MavenRain commented May 23, 2026

Since rust-lang/cargo#16557, cargo metadata and cargo check reject --filter-platform path/to/foo.json and --target path/to/foo.json unless -Zjson-target-spec is also passed (which itself requires -Zunstable-options). rust-analyzer hits this whenever a user configures a JSON target spec via rust-analyzer.cargo.target or via .cargo/config.toml's [build] target = "...json", surfacing as a metadata failure on workspace load.

Detect when the configured target ends in .json and push the flag in both code paths (cargo_workspace.rs for cargo metadata, build_dependencies.rs for cargo check). The existing -Z detection in each function then handles -Zunstable-options and the __CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS env var.

Matches the existing target.ends_with(".json") idiom already used in workspace.rs and toolchain_info/target_tuple.rs.

Closes #21821.

    Since rust-lang/cargo#16557, cargo metadata and cargo check reject
    `--filter-platform path/to/foo.json` and `--target path/to/foo.json`
    unless `-Zjson-target-spec` is also passed (which itself requires
    `-Zunstable-options`).  rust-analyzer hits this whenever a user
    configures a JSON target spec via `rust-analyzer.cargo.target` or
    via `.cargo/config.toml`'s `[build] target = "...json"`, surfacing
    as a metadata failure on workspace load.

    Detect when the configured target ends in `.json` and push the
    flag in both code paths (cargo_workspace.rs for cargo metadata,
    build_dependencies.rs for cargo check).  The existing `-Z`
    detection in each function then handles `-Zunstable-options` and
    the `__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS` env var.

    Matches the existing `target.ends_with(".json")` idiom already
    used in workspace.rs and toolchain_info/target_tuple.rs.

    Closes rust-lang#21821.

Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 23, 2026
@ChayimFriedman2
Copy link
Copy Markdown
Contributor

See #21846 for why this simple approach doesn't work.

@MavenRain
Copy link
Copy Markdown
Contributor Author

See #21846 for why this simple approach doesn't work.

OK, I'm looking

@MavenRain
Copy link
Copy Markdown
Contributor Author

See #21846 for why this simple approach doesn't work.

I appreciate the heads-up. I'll close this in favour of #21846 and move the metadata-site coverage (cargo_workspace.rs:698, which #21846 doesn't touch) plus the toolchain-version gate over there.

@MavenRain MavenRain closed this May 23, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 23, 2026
@MavenRain MavenRain deleted the fix-json-target-spec branch May 23, 2026 19:52
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.

Custom targets triplets loaded from json now require "-Z json-target-spec"

3 participants