Skip to content

fix(util-schemas): compile out the file-path hint where url can't build it - #17600

Open
UebelAndre wants to merge 1 commit into
rust-lang:masterfrom
UebelAndre:from_file_path
Open

UebelAndre wants to merge 1 commit into
rust-lang:masterfrom
UebelAndre:from_file_path

Conversation

@UebelAndre

@UebelAndre UebelAndre commented Oct 16, 2026 •

Copy link
Copy Markdown

Part of #17595.

What does this PR try to resolve?

cargo-util-schemas is consumed by third-party tools, some of which run on targets with no filesystem, environment, or network, such as wasm32-unknown-unknown. PackageIdSpec::parse probed the current directory to suggest a file:// URL for specs that look like paths, and that does not compile there: url only provides Url::from_file_path on unix, windows, redox, wasi, and hermit.

The hint is purely diagnostic, so it is now compiled out behind the same cfg that url uses. Behavior is unchanged on every target that built before.

How to test and review this PR?

A new CI job checks that cargo-util-schemas builds for wasm32-unknown-unknown; locally that is cargo check -p cargo-util-schemas --all-features --target wasm32-unknown-unknown. The existing pkgid tests cover the hint on supported targets.

@rustbot rustbot added the A-infrastructure Area: infrastructure around the cargo repo, ci, releases, etc. label Oct 16, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 16, 2026
@rustbot

rustbot commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @Muscraft (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @Muscraft, @epage, @weihanglo
  • @Muscraft, @epage, @weihanglo expanded to Muscraft, epage, weihanglo
  • Random selection from Muscraft, epage, weihanglo

Comment thread crates/cargo-util-schemas/src/core/package_id_spec.rs
@UebelAndre
UebelAndre requested a review from epage October 16, 2026 16:51
@epage

epage commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Note that our contrib guide asks for atomic commits.

Comment thread .github/workflows/main.yml Outdated
Comment on lines +273 to +282
# `cargo-util-schemas` is consumed by third-party tools, some of which run
# on targets with no filesystem, environment, clock, or network.
- run: rustup target add wasm32-unknown-unknown
- run: cargo check -p cargo-util-schemas --all-features --target wasm32-unknown-unknown --locked

@epage epage Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is unrelated to the job it is operating in

We also have a job for enforcing --locked

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated!

Comment on lines +87 to +91
// This is purely a diagnostic: if the spec names an existing
// path, suggest the `file://` URL that would be accepted instead.
// `Url::from_file_path` only exists on targets with a known path
// syntax, so the hint is compiled out elsewhere (e.g.
// `wasm32-unknown-unknown`), keeping this crate buildable there.

@epage epage Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This feels fairly verbose for what needs to be said

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated!

target_os = "redox",
target_os = "wasi",
target_os = "hermit"
))]

@epage epage Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a negative we could do? I wonder if that would be easier to maintain. Granted, we do have end-to-end tests, so for any platform we run the tests, we'd identify that a cfg was missing, so maybe not an issue.

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I can update the pattern but before I do, this matches what rust-url has so would you still prefer the updated pattern or to match the that crate: https://github.com/servo/rust-url/blob/v2.5.8/url/src/lib.rs#L2542-L2551

…uild it

`cargo-util-schemas` is consumed by third-party tools, some of which run
on targets like `wasm32-unknown-unknown` that have no filesystem. There
`Url::from_file_path` doesn't exist, so the crate failed to compile.
The hint that suggests a `file://` URL for a path-like spec is purely
diagnostic, so gate it on the same `cfg` `url` uses.
@UebelAndre UebelAndre changed the title fix(util-schemas): keep PackageIdSpec::parse free of host access fix(util-schemas): compile out the file-path hint where url can't build it Oct 17, 2026
@UebelAndre
UebelAndre requested a review from epage October 17, 2026 02:42
@UebelAndre

Copy link
Copy Markdown
Author

Updated the PR title, description, and commit.

@rustbot ready

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-infrastructure Area: infrastructure around the cargo repo, ci, releases, etc. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants