Skip to content

fix: Add -Zjson-target-spec on Cargo calls where needed#21846

Draft
ChayimFriedman2 wants to merge 1 commit into
rust-lang:masterfrom
ChayimFriedman2:json-target-spec
Draft

fix: Add -Zjson-target-spec on Cargo calls where needed#21846
ChayimFriedman2 wants to merge 1 commit into
rust-lang:masterfrom
ChayimFriedman2:json-target-spec

Conversation

@ChayimFriedman2
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 commented Mar 19, 2026

Fixes #21821.

CC @ShoyuVanilla assuming you know - do we need to gate this only for affected Cargo versions? If so, how?

@ShoyuVanilla
Copy link
Copy Markdown
Member

Yeah, the older versions without that flag will error with it. For the later, I guess we could just do it based on the toolchain version. Would that be hard because of some quirks in our codebase? (I can't check whether it's hard or not since I'm outside rn. Sry 😅 )

@Veykril
Copy link
Copy Markdown
Member

Veykril commented Mar 20, 2026

We already have the sysroot here so we should have the toolchain version queried already somewhere

@ShoyuVanilla
Copy link
Copy Markdown
Member

As Lukas said we should the toolchain version available there, I guess you could compare the toolchain version like the following lines:

let usage = if *toolchain_version >= MINIMUM_TOOLCHAIN_VERSION_SUPPORTING_LOCKFILE_PATH_ENV {
LockfileUsage::WithEnvVar
} else if *toolchain_version >= MINIMUM_TOOLCHAIN_VERSION_SUPPORTING_LOCKFILE_PATH_FLAG {

@MavenRain
Copy link
Copy Markdown
Contributor

MavenRain commented May 23, 2026

Hi @ChayimFriedman2, I've dropped #22435 in favour of this PR. Two notes that may help unstick it:

  1. The cargo metadata invocation in crates/project-model/src/cargo_workspace.rs:698-702 also passes .json target specs (via --filter-platform) and needs the same fix. It's not covered in this PR. The user-reported error in Custom targets triplets loaded from json now require "-Z json-target-spec" #21821 surfaces from that path.

  2. For the version gate, -Zjson-target-spec was added in Add -Z json-target-spec cargo#16557, milestoned 1.95.0 (merged 2026-01-25). The existing pattern at build_dependencies.rs:521-530 (COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION) works as precedent: toolchain.is_some_and(|v| *v >= MIN_VERSION_FOR_JSON_TARGET_SPEC).

I'd be happy to push a commit to this branch that adds the metadata site and version gating if you'd like, or leave it for you. Either is fine.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 23, 2026

☔ The latest upstream changes (possibly #22432) made this pull request unmergeable. Please resolve the merge conflicts.

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"

5 participants