Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no_std support for the url crate #831

Merged
merged 1 commit into from
Oct 17, 2024
Merged

no_std support for the url crate #831

merged 1 commit into from
Oct 17, 2024

Conversation

domenukk
Copy link
Contributor

@domenukk domenukk commented Apr 8, 2023

This extends/rebases/fixes #717.
All checks seem to pass.
For no_std support, however, as mentioned in #717, this still needs a bunch of fixes. Specifically, It looks like we'll have to use the ip_in_core nightly feature, or use this crate: https://docs.rs/no-std-net. I'd personally opt for nightly, as it looks like it will be merged eventually, but I could do both.

/edit: For future reference, in the meantime, net and the Error trait have made their way into core

@domenukk
Copy link
Contributor Author

domenukk commented Apr 8, 2023

Went for ip_in_core now, so it needs nightly, but seems to work.

@domenukk domenukk marked this pull request as ready for review April 8, 2023 16:09
url/src/lib.rs Outdated Show resolved Hide resolved
@domenukk
Copy link
Contributor Author

I spent some time trying to get serde no_std support working, but it doesn't play nicely with the ip_in_core nightly feature - it throws errors like

the trait `Serialize` is not implemented for `Ipv6Addr`

@valenting
Copy link
Collaborator

Went for ip_in_core now, so it needs nightly, but seems to work.

If it breaks stable, that's obviously a no-go.
Also, our msrv is 1.56.0, so preferably the no_std changes would also work on that version.

@codecov
Copy link

codecov bot commented Apr 10, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@7eccac9). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #831   +/-   ##
=======================================
  Coverage        ?   82.25%           
=======================================
  Files           ?       22           
  Lines           ?     3562           
  Branches        ?        0           
=======================================
  Hits            ?     2930           
  Misses          ?      632           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@domenukk
Copy link
Contributor Author

It should not break stable, it should only "break" no_std (which never worked in the first place).
Switching to no-std-net also doesn't fix the problem with serde - the project seems stale/would need this to be merged:
dunmatt/no-std-net#16

@domenukk
Copy link
Contributor Author

Moving to no-std-net anyway, since it seems to fit your msrv better

@domenukk
Copy link
Contributor Author

Since I do need the nightly version, but I can see why some people wouldn't, I added two features:

  • no_std_net uses the no_std_net crate, no nightly needed (but the extra dependency)
  • unstable enabled unstable net_in_core feature, and also the error_in_core feature. Due to its opt-in nature, I would assume this is an okay solution (?)

Else we can wait until the features get stabilised.
Feedback welcome.

@@ -453,7 +453,7 @@ impl Idna {
return Errors::default();
}
let mut errors = processing(domain, self.config, &mut self.normalized, out);
self.output = std::mem::replace(out, String::with_capacity(out.len()));
self.output = core::mem::replace(out, String::with_capacity(out.len()));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI, this fixes a bug in the current idna no_std support. Why is it not caught in CI, and should I open an extra PR for it?

Choose a reason for hiding this comment

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

I recently dabbled with no_std stuff as well and I think the sure-fire way to test no_std compatibility is to:

  • target a platform that does not have std (certain ARM platforms) OR
  • have a really simple no_std binary crate which uses the libraries

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I'm trying it with cargo +nightly build -Zbuild-std=core,alloc --target aarch64-unknown-none -v --release --no-default-features

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you split this off into a separate PR?

@domenukk
Copy link
Contributor Author

Any news on this? :)

@bors-servo
Copy link
Contributor

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

@domenukk domenukk requested a review from OverOrion June 6, 2023 13:07
@domenukk
Copy link
Contributor Author

domenukk commented Jun 6, 2023

Updated to latest master

@OverOrion
Copy link

I am not a maintainer, so I think @valenting should be requested for a review, rather than me.

@domenukk
Copy link
Contributor Author

I'm not sure if the codecov failure is an issue - it's not caused by the PR as far as I can tell? Will I still need to add a new (unrelated?) testcase somewhere?

@@ -453,7 +453,7 @@ impl Idna {
return Errors::default();
}
let mut errors = processing(domain, self.config, &mut self.normalized, out);
self.output = std::mem::replace(out, String::with_capacity(out.len()));
self.output = core::mem::replace(out, String::with_capacity(out.len()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you split this off into a separate PR?

url/Cargo.toml Outdated Show resolved Hide resolved
@domenukk
Copy link
Contributor Author

domenukk commented Jun 14, 2023

Opened #843 to fix the idna no_std bug.

@lucacasonato lucacasonato mentioned this pull request Jul 11, 2023
4 tasks
@bors-servo
Copy link
Contributor

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

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably beb2cde) made this pull request unmergeable. Please resolve the merge conflicts.

if: |
matrix.os == 'ubuntu-latest' &&
matrix.rust == 'nightly'
run: rustup target add aarch64-unknown-none && rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu && cargo +nightly build -Zbuild-std=core,alloc --target aarch64-unknown-none -v --release --no-default-features --features=alloc,unstable
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lucacasonato you could take over this check to the idna create

@domenukk
Copy link
Contributor Author

Apparently building --no-default-features workspace-wide didn't work, moved that check to the url create only -> CI might turn green

@domenukk
Copy link
Contributor Author

It's green 🎉

@domenukk
Copy link
Contributor Author

Any news on this? @valenting

@domenukk
Copy link
Contributor Author

Opened the PRs mentioned in #831 (comment)

domenukk added a commit to domenukk/wasmCloud that referenced this pull request Sep 20, 2024
In order to make the rust-url compatible with no_std, the crate needs to introduce a `std` feature and make it default.
See servo/rust-url#831.

In order to reduce impact, downstream libraries should leave url's default features enabled (no other features are currently `default`).

Signed-off-by: Dominik Maier <[email protected]>
tjtelan pushed a commit to tjtelan/git-url-parse-rs that referenced this pull request Sep 20, 2024
In order to make the rust-url compatible with no_std, the crate needs to introduce a `std` feature and make it default.
See servo/rust-url#831.

In order to reduce impact, downstream libraries should leave url's default features enabled (no other features are currently `default`).
@domenukk
Copy link
Contributor Author

domenukk commented Sep 20, 2024

git-url-parse and release_plz_core seems like the ones that the ecosystem would benefit the most from not breaking

The PRs in both crates have since been merged :)

github-merge-queue bot pushed a commit to bytecodealliance/wrpc that referenced this pull request Sep 23, 2024
In order to make the rust-url compatible with no_std, the crate needs to introduce a `std` feature and make it default. See servo/rust-url#831.

To reduce impact, downstream libraries should leave url's default features enabled (no other features are currently `default`).
@domenukk
Copy link
Contributor Author

Any news on this?

@Manishearth
Copy link
Member

@valenting What do you think?

@valenting
Copy link
Collaborator

I think this looks good. @domenukk could you rebase commits on main?

@Manishearth
Copy link
Member

@domenukk please rebase instead of merging in

@domenukk
Copy link
Contributor Author

Don't you guys just squash this anyway? Do you really want the full history of me trying to fix CI?

@domenukk
Copy link
Contributor Author

(Happy to squash this and force push, or rebase and remove the last commit, or whatever y'all want, but GitHub has a handy squash button when you merge)

@Manishearth
Copy link
Member

@domenukk Yeah, please squash and force push with a rebase.

The squash button isn't available on merge queue repos.

@domenukk
Copy link
Contributor Author

TIL :)

@Manishearth Manishearth added this pull request to the merge queue Oct 17, 2024
Merged via the queue into servo:main with commit ebd5cfb Oct 17, 2024
14 checks passed
@valenting
Copy link
Collaborator

Thank you for all the great work @domenukk !

@hsivonen
Copy link
Collaborator

hsivonen commented Nov 4, 2024

See also #992

@hsivonen
Copy link
Collaborator

hsivonen commented Nov 4, 2024

Are core::error::Error and std::error::Error same enough that what this PR did is correct about implementing one or the other still works when the crate graph has something that depends on url with default-features = false and expects core::error::Error to be implemented and the crate graph also has something else that depends on url with the std feature and expects std::error::Error to be implemented?

@domenukk
Copy link
Contributor Author

domenukk commented Nov 4, 2024

They are the same type. std::error::Error is a re-export of core::error::Error, see:
https://doc.rust-lang.org/src/std/error.rs.html#8

kodiakhq bot pushed a commit to pdylanross/fatigue that referenced this pull request Nov 5, 2024
Bumps url from 2.5.2 to 2.5.3.

Release notes
Sourced from url's releases.

v2.5.3
What's Changed

fix: enable wasip2 feature for wasm32-wasip2 target by @​brooksmtownsend in servo/rust-url#960
Fix idna tests with no_std by @​cjwatson in servo/rust-url#963
Fix debugger_visualizer test failures. by @​valenting in servo/rust-url#967
Add AsciiSet::EMPTY and boolean operators by @​joshka in servo/rust-url#969
mention why we pin unicode-width by @​Manishearth in servo/rust-url#972
refactor and add tests for percent encoding by @​joshka in servo/rust-url#977
Add a test for and fix issue #974 by @​hansl in servo/rust-url#975
no_std support for the url crate by @​domenukk in servo/rust-url#831
Normalize URL paths: convert /.//p, /..//p, and //p to p by @​theskim in servo/rust-url#943
support Hermit by @​m-mueller678 in servo/rust-url#985
fix: support wasm32-wasip2 on the stable channel by @​brooksmtownsend in servo/rust-url#983
Improve serde error output by @​konstin in servo/rust-url#982
OSS-Fuzz: Add more fuzzer by @​arthurscchan in servo/rust-url#988
Merge idna-v1x to main by @​hsivonen in servo/rust-url#990

New Contributors

@​brooksmtownsend made their first contribution in servo/rust-url#960
@​cjwatson made their first contribution in servo/rust-url#963
@​joshka made their first contribution in servo/rust-url#969
@​hansl made their first contribution in servo/rust-url#975
@​theskim made their first contribution in servo/rust-url#943
@​m-mueller678 made their first contribution in servo/rust-url#985
@​konstin made their first contribution in servo/rust-url#982
@​arthurscchan made their first contribution in servo/rust-url#988

Full Changelog: servo/[email protected]



Commits

8a683ff Merge idna-v1x to main (#990)
08a3268 OSS-Fuzz: Add more fuzzers (#988)
5d363cc Improve serde error output (#982)
30e6258 fix: support wasm32-wasip2 on stable channel (#983)
bf089c4 support hermit (#985)
b08a655 Normalize URL paths: convert /.//p, /..//p, and //p to p (#943)
ebd5cfb no_stdsupport for the url crate (#831)
7eccac9 Add a test for and fix issue #974 (#975)
710e1e7 refactor and add tests for percent encoding (#977)
6050a6e mention why we pin unicode-width (#972)
Additional commits viewable in compare view




Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options

You can trigger Dependabot actions by commenting on this PR:

@dependabot rebase will rebase this PR
@dependabot recreate will recreate this PR, overwriting any edits that have been made to it
@dependabot merge will merge this PR after your CI passes on it
@dependabot squash and merge will squash and merge this PR after your CI passes on it
@dependabot cancel merge will cancel a previously requested merge and block automerging
@dependabot reopen will reopen this PR if it is closed
@dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
@dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
@dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
mxinden added a commit to mxinden/neqo that referenced this pull request Nov 5, 2024
`url` `v0.5.3` and `idna` `v1.0.3` added no-std support:
servo/rust-url#831

Since Neqo sets `default-features = false`, the above would break Neqo.

Related: servo/rust-url#831
github-merge-queue bot pushed a commit to mozilla/neqo that referenced this pull request Nov 6, 2024
`url` `v0.5.3` and `idna` `v1.0.3` added no-std support:
servo/rust-url#831

Since Neqo sets `default-features = false`, the above would break Neqo.

Related: servo/rust-url#831
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants