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
base: main
Are you sure you want to change the base?
Conversation
Add default feature flag "std" that enables a `std::error::Error` impl for `Errors`.
Went for |
/// | ||
/// # fn run() -> Result<(), Box<dyn Error>> { | ||
/// # use url::ParseError; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not super pretty. If URL had a no_std
error type that also supports strings, it could be nicer. However, it's not visible in docs so should be fine
I spent some time trying to get the trait `Serialize` is not implemented for `Ipv6Addr` |
If it breaks stable, that's obviously a no-go. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #831 +/- ##
=======================================
Coverage 81.70% 81.70%
=======================================
Files 20 20
Lines 3547 3547
=======================================
Hits 2898 2898
Misses 649 649 ☔ View full report in Codecov by Sentry. |
It should not break stable, it should only "break" |
Moving to |
Since I do need the nightly version, but I can see why some people wouldn't, I added two features:
Else we can wait until the features get stabilised. |
idna/src/uts46.rs
Outdated
@@ -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())); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
Any news on this? :) |
idna/src/uts46.rs
Outdated
@@ -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())); |
There was a problem hiding this comment.
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?
Opened #843 to fix the idna |
☔ The latest upstream changes (presumably #853) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably beb2cde) made this pull request unmergeable. Please resolve the merge conflicts. |
.github/workflows/main.yml
Outdated
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 |
There was a problem hiding this comment.
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
Apparently building --no-default-features workspace-wide didn't work, moved that check to the |
It's green 🎉 |
Any news on this? @valenting |
Any hint on what to do with codecov CI? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the guiding principle for this feature should be: "Don't inconvenience people who don't care about no_std
", which is... All of url
's current users ;)
So, I really don't think we should bump MSRV for this feature - but a way to solve that would be to use rustc_version
in a build script to detect when the feature is available. (This does come with a slight compile-time cost, but hopefully that's acceptable, and it will go away once the functionality is in url
's MSRV).
|
||
[features] | ||
default = [] | ||
default = ["std"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fear this might be a fairly big breaking change?
When I added no_std
support for the other libraries in this crate, it was more trivial, since there was only three crates that disabled default features - but that is not the case for url
; there are many crates specifying default-features = false
, so even though there was no default features previously, this change will affect all of those crates.
Python script for finding crates using `default-features = false`.
import json
import requests
import sys
API_URL = "https://crates.io/api/v1/crates"
crate_name = sys.argv[1]
page = 1
while True:
# print(f"page {page}")
data = json.loads(requests.get(f"{API_URL}/{crate_name}/reverse_dependencies?per_page=100&page={page}").content)
page += 1
if len(data['versions']) == 0:
break
versions = {x['id']: x for x in data['versions']}
for dep in data['dependencies']:
if not dep['default_features']:
crate = versions[dep['version_id']]
print(f"{crate['crate']} had `default-features = false`")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any other way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... I see two:
- Bundling this in with other breaking changes, and releasing
url v0.3
- Calling the feature
unstable-no-std
instead, to signify that it may break other crates in the dependency chain, and that it is a bad way of doing it which will be rectified oncev0.3
is released.
no_std_net = ["no-std-net"] | ||
# UNSTABLE FEATURES (requires Rust nightly) | ||
# For no_std: Use errors_in_core and net_in_core | ||
unstable = ["idna/unstable"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rust-lang/rust#108443 is FCP-ing now, so it'll probably land in a few months - perhaps we should wait with this feature until then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now this PR also uses error_in_core
(rust-lang/rust#103765) but that part can be removed if we want to go for stable instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value in that feature is that this could become a non-breaking change (other than bumping MSRV, which is probably acceptable).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: core::net
has landed in Rust 1.77.0
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 theip_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.