-
Notifications
You must be signed in to change notification settings - Fork 31
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
Supply web-time::SystemTime
for wasm32
#32
Conversation
be2f071
to
ac83e3b
Compare
Thanks! Can you add a CI job that targets a wasm32 target so that we know that this compiles and doesn't regress? |
Added I think this is what you were asking for, but also made the job run tests on another branch in case that was your preference . |
Not sure about this. First, it seems quite odd to have to poly-fill bits of std like this. It feels like you actually want to disable the Second, it seems |
So maybe web-time is a good alternative? @daxpedda do you think it would be a good fit? |
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.
So maybe web-time is a good alternative? @daxpedda do you think it would be a good fit?
AFAICS the goal here is to find a working replacement for std::time::SystemTime
on the Web platform. In that case web-time
would be a good fit.
Keep in mind that wasm32-unknown-unknown
doesn't necessarily mean Web, so if you want to support this target for non-Web platforms, you might want to guard this behind a feature. Obviously this would mean users who target wasm32-unknown-unknown
without the feature will get a panic when they hit this part of the code.
Thanks so much for the quick response. The most recent force-push should address the concerns raised here. It uses |
Could/should we make this a compile time error? |
Cargo doesn't seem to support I've also feature gated
|
For more context: currently |
@daxpedda I took your advice and updated the table above. a wasm32-unknown-unknown target with |
instant::SystemTime
for wasm32web-time::SystemTime
for wasm32
How will this interact with the continuation of the no-std work staged in the Rustls repo. Does the introduction of the |
I'm not familiar with the In context for this PR: |
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 pull request description could use an update (it still refers to using instant
as opposed to web-time
).
Given the complexity of the matrix in this comment it also feels like there should be some attempt at documenting the new feature, its scope of support, and its limitations somewhere. Maybe in the top-level lib.rs
rustdoc?
Updated the PR description, applied your ci.yml suggestion, and made an attempt to document the |
Are any further changes / approval required? |
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.
Within my limited knowledge of WASM and the wasm32-unknown-unknown
target this seems reasonable. I flagged one docs nit and a YAML issue that could use quick fixes.
I also I think it'd be nice if the commit adding documentation was folded into the commit adding the feature, but we could probably do that for you before merge if it's a hassle to fix.
`std::time::SystemTime` is unavailable in wasm32-unknown-unknown. `web-time` is a drop in replacement for web environments in wasm32.
adopted @cpu's recommendations and force pushed |
@ctz Does the revised iteration based on |
Regarding @ctz's first concern
This PR was opened so that I can target browsers, which this change alone would allow. It does seem possible to supply web-time by implementing |
I think it will be merged within a week or two ( 🤞 ). The main limiting factor is that I'll be out next week. |
@cpu rustls/rustls#1688 appears to be paused. Does the presence of that PR make this one obsolete? If that PR is paused and this one allows rustls to be embedded in browser environments, is it worth merging or does it create too much of a maintenance burden? |
If this PR means that web targets can use the default time provider, I think this is probably still a win? |
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 I'm a bit less concerned now compared to before, given the rather platform-specific nature of this change.
But in the future I think we should resist further polyfills of broken std functionality.
Thanks for sticking with this and iterating based on our feedback @DanGould 👍 |
Thanks for the feedback and your patience |
This should be the last piece of logic required for rustls to support WebAssembly.
UnixTime::now()
is called for certificate verification in rustls.std::time::SystemTime
is unavailable in wasm32-unknown-unknown, so callingUnixTime::now()
would panic before this change.web-time
appears to be a sufficientstd::time
replacement for browser environments.Regarding tests, I don't see any calls to
UnixTime::now()
in this crate, so It doesn't seem like testing against a wasm32 would prevent regressions that existing tests would. I'm still happy to set up wasm-bindgen-test if the maintainers would like to see those tests and run them and ci. Perhaps wasm32 tests make sense further up the stack inrustls
where certificate verification happens andUnixTime::now()
is called.I did manually test a rustls connection from wasm32 using this change, however.
I plan to use this to make an https tunnel through a websocket connection in the browser