Uuid::new_v4() compiles and then panics for wasm32-unknown-unknown target #350
Labels
No labels
breaking
bug
dependencies
good first issue
help wanted
unstable
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-uuid-rs/uuid#350
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Is your feature request related to a problem? Please describe.
I do use
uuidcrate in my crate, which can be used as a pure Rust library or as an isomorphic NPM package (node & browser). The only feature I do use is random UUID (v4) generation.It panics:
Example of what we do is in this issue. Our
uuidv4()function source code.Describe the solution you'd like
Generate UUID v4 even when compiled for the
wasm32-unknown-unknowntarget.Is it blocking?
Kind of. Not a high priority.
Describe alternatives you've considered
Thinking about using
Math.randomin my function if the target iswasm32-....Other
Not sure if this is the
uuidcrate problem or it lies somehwere deeper inside this whole bleeding edge stuff.Hi. Thanks for reporting this.
Rand added wasm support to 0.6, while we are still using 0.5. (We have a PR to upgrade it to 0.6 but haven't merged it yet).
You can test it by depending on the
dependabot/cargo/rand-0.6branch instead of master.@Dylan-DPC thanks, just tried ...
Browser
Node
Testing with:
Not sure if this comment is related to my issue somehow:
Will check tomorrow if it's gated behind this feature.
@Dylan-DPC it's not enough to update to 0.6. One has to use
stdweborwasm-bindgenfeature withwasm32-unknown-unknowntarget. Even the error message says it:Just checked the
randsource code. It works (node & browser) if I changeuuidcrate dependency to:One can use
stdweborwasm-bindgen.Hmm, this doesn't seem ideal to me... We'd either have to pick one of the
wasm-bindgenorstdwebfeatures in theranddependency unconditionally. I haven't been keeping up with the wasm space so am not sure which of these features would be the better one.We don't currently claim any
wasmsupport inuuid(although it might be nice to figure out) so a workaround until we have some idea of what that should look could be to depend onrandyourself with one of the features you want.@zrzka Do you have any thoughts?
@KodrAus there's one way.
uuidcrate can have same features (stdweb,wasm-bindgen) asrandand these features can be passed touuidcrate dependencies.uuidcrate Cargo.toml:My crate Cargo.toml:
This works for me. And anyone can still use
uuidas it is or with eitherstdweborwasm-bindgenfeature, which just enables this feature in therandcrate.I also tried to add ...
... to enable these features for
wasm32only, but it seems that it doesn't work with...features, just...dependencies.Maybe @alexcrichton can sched a light on this, I mean, what's the recommended approach. IIRC I saw Alex in all these
wasm32commits in therandcrate.Another option, just for me, is to disable
v4feature on the UUID, copy & pastenew_v4()to my crate, addranddependency and generate / crate UUID v4 by myself.It is a good idea to add wasm support for UUID. @zrzka since you have already started digging into this, are you open to sending a PR that adds the feature? we will mentor you. If you don't have time, I'll look into adding it later. Thanks
@Dylan-DPC yup, going to do it now.
Did the PR, but not sure if it's the right thing to do. It works for me and I have a temporary fix for my issue. No need to hurry.
What bothers me is this
wasm-bindgenfeature. There's a crate with the same name and you can't have a feature and a dependency with the same name. If, and if, you'll want to createwasm-bindgenbased NPM package from theuuidcrate, it will fail because of thewasm-bindgenfeature = name conflict. Not sure if it applies torandcrate as well, becausewasm-bindgenfeature is not in theCargo.toml, it's in the code only. Just thinking aloud, hypothetical example ...For now we don't have a great way to solve this, but the recommended approach would be to have an feature name like
wasm-bindgenand such which is enabled by consumers (and transitively enables the feature in required dependencies). Which is to say I think you're already on the right track!@alexcrichton Hm, this isn't going to play particularly nicely with dependencies that are optional to begin with though, right? So with a
wasm-bindgenfeature we can't not depend onrand, because we have to enable it along with itswasm-bindgenfeature.But if this is the way we're recommending folks do this then we should follow it here, so at least
uuidis in the same boat as everyone else if we try come up with a more scalable solution later.@KodrAus there's another, hypothetical, but still, issue with this approach. Imagine that
uuidcrate will follow this path, so, ...wasm-bindgen&stdwebfeatures will be addedrandcrate here)... and here's the hypothetical issue. What if
uuidcrate devs will decide to publish this crate as an NPM package as well (viawasm-pack&wasm-bindgen). Then they need to addwasm-bindgendependency and there will be a conflict. Because dependencies & features must not have same name. @alexcrichton I wonder if this was discussed even for therandcrate?An example in opposite direction. In our crate, we're depending on
wasm-bindgencrate. And here, we're unable to addwasm-bindgen/stdwebfeatures, because of the name conflict (feature vs dependency). It's hypothetical example as well, because we don't need it, but I can imagine it can happen sooner or later.@zrzka That's a good spot. Though having feature names that are named differently from their purpose might mislead some users. We don't need wasm-bindgen, so adding a dependency just for wasm-support feels like overkill. The current approach seems fine to me and we have no plans for npm support right now, so we can go the original way or you can rename them to something that relates to them.
@Dylan-DPC I agree, that's the reason why I wrote that this is a hypothetical example, because there're lot of UUID NPM packages and there's no need for another one :) It's just something to be aware of.
Yeah thanks.
Also on the PR, you should get a "Restore branch" option and I can reopen the PR after that.
@KodrAus yeah it's not a great situation unfortunately :(. It's currently a local optimum we've figured out, but if there's better ideas I'm all ears!
Fixed in the #351 PR. Pending Dependency Update, see #352.
@alexcrichton Yeh, I guess something along the same lines could involve some fancier way to link up enabled cargo features on-the-fly:
Actually, that might be nice for a bunch of other cases too, but is probably not quite like using
[target.'cfg(...)'].@KodrAus ah yes indeed! I think that's this old RFC perhaps?