Feature/wasm #351
No reviewers
Labels
No labels
breaking
bug
dependencies
good first issue
help wanted
unstable
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-uuid-rs/uuid!351
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/wasm"
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?
Description
This PR adds two new features:
stdwebwasm-bindgenThese features are kind of passthrough features, because they do nothing in the
uuidcrate itself. They're just passed to therandcrate to make theuuidcrate working for thewasm32-unknown-unknowntarget.Motivation
I'm unable to generate random UUID (v4) when this crate is compiled for the
wasm32-unknown-unknowntarget.Tests
I just added these features ...
... for all
v3&v4&v5(randcrate is used in all these features) to thescriptsection in the.travis.yml.Not sure if it makes sense, but it can demonstrate that it's buildable at least.
I don't think that more tests are required unless you'd like to bring the whole
wasm-bindgen,wasm-pack, ... machinery here. And it has no sense to do it, because goal of this PR is not to publishuuid-rsNPM package, just add the ability to compile & use it from thewasm32-unknown-unknowntarget.Related Issue(s)
Manual tests
My Cargo.toml:
My
index.js:uuidv4() implementation.
Output:
Thanks. But I don't think it is a good idea to depend on docs for messages that it is supported only on certain targets with a feature gate. I'm looking for a better way of doing this.
Agreed, I don't like it too. Maybe hide
new_v4()& friends ...... , remove
# Panicsdocstring and add some note to thelib.rswhat to do with thewasm32?Did update this PR and gated all v3, v4, v5 modules behind features. If you target
wasm32-...and you forget to enable eitherstdweborwasm-bindgenfeature, it fails to compile:do we need both features to be mutually exclusive? what will happen if this condition doesn't exist and both features exist?
this file should be added to
.gitignoreOuch, that's my fault, this file and
binfolder should not have been commited. I was just playing with thewasm-pack, will remove them.According to this and this I assume that the compilation will fail, because of two
impmodules. And we should probably addnot(target_os = "emscripten")as well, to mimickrandbehavior.Sounds good to me 👍
Not 100% sure if
not(target_os = "emscripten")should be added, because at the top level onlywasm32&stdweb|wasm-bindgenis used.Currently this doesn't test the crate on wasm-* but just the features. We need to add another build to the CI so that it will run all the tests (or just the feature-gated ones) on wasm.
My assumption was wrong.
cargo build --target wasm32-unknown-unknown --features "stdweb wasm-bindgen"works andstdwebis picked.Rand contains ...
... which works when
stdwebis enabled. And it also contains ...... which utilizes
wasm-bindgenonly ifstdwebis disabled.stdweb&wasm-bindgendoes not need to be mutually exclusive.randcan handle thisnot(target_os = "emscripten")should be addedI don't think RNGs are supported on emscripten which means if we don't bother about it, then compilation will fail and if we include it in the feature gate, it will compile to nothing.
@Dylan-DPC can you elaborate on tests pls? There're two options:
a) make a crate buildable for
wasm32-...and that's it, test the features only,b) make a crate buildable for
wasm32-...and provide "NPM package" (JS wrapper) and test it with thewasm-pack test ..., something like thisIf a) is the right answer then I don't understand what do you mean with tests. Because you can't do things like
cargo test --target wasm32-unknown-unknown --features "v5 stdweb"for example.Also I don't think b) needs to be added.
randis doing this for WASM, it takes quite a long time and the output is:Did add builds for the
wasm32arch with features as a minimum.Thanks for the PR @zrzka. Personally I'm not a fan of adding transitive
stdweborwasm-bindgenfeatures touuidfor the sake ofrand. It just passes the problem of figuring out feature gates upstream to the next consumer ofuuid.Right now, I think depending on
randalongsideuuidin your project with one of these features set is a better way to go.If we're going to support random uuids in wasm then I think we should do it without needing any special feature gates.
This will test only the features, it won't test whether uuid works on the wasm architectures or not, which could lead to false truths.
@KodrAus not sure if you can do it without feature gates now, because there's
stdwebandwasm-bindgen, which are different things / approaches. That doesn't mean I like it, because it's weird and it looks like that it's fixing an issue which lies elsewhere.Anyway, I'm fine with adding
randas a dependency and copy & pastingnew_v4.I'm going to close this PR, trash branch. Decide if you'd like to keep #350 open and if not, feel free to close it.
@KodrAus I don't think you can do it without the feature gates, and since the rand features are different depending on whether they want stdweb or bindgen. I don't see another way of doing this at this point.
@Dylan-DPC is right :)
Anyway, I have fixed my issue with this commit, works for me. Ugly as well, but at least it works.
@zrzka So it looks like this is actually the way we're recommending doing this right now, so if you'd like to re-open this PR as-is then I'm on board with the approach.
Sorry about the misdirection here :) I can live with a solution that has drawbacks if it's consistent with what other libraries are doing.
@KodrAus np, next week.
Restored & reopened as requested. Summary:
randversion bumpedstdweb&wasm-bindgenfeatures added, they just transitively enables same features in therandcratev3,v4,v5onwasm32arch,stdweband/orwasm-bindgenfeature(s) must be enabled otherwise these modules wont be availablewasm32-unknown-unknownlib.rsabout this behaviorThis fails on stable & beta with an issue on stdweb:
Yep,
stdwebrequires nightly. I reschuffled .travis.yml little bit. Also 1.22 doesn't have support formwasm32-unknown-unknown, so, I removed it from the main script.Yeah they fixed the issue in this commit (
github.com/koute/stdweb@f1fc5e3206) and it will work on stable once it is released.bors: r+
Build succeeded