-
Notifications
You must be signed in to change notification settings - Fork 431
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
Put stdweb dependency behind a target feature #336
Conversation
0a3a2a0
to
e3be669
Compare
Cargo.toml
Outdated
@@ -23,6 +23,7 @@ alloc = ["rand_core/alloc"] # enables Vec and Box support without std | |||
i128_support = [] # enables i128 and u128 support | |||
|
|||
serde-1 = ["serde", "serde_derive"] | |||
wasm-stdweb = ["stdweb"] |
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.
Shouldn't we just call it stdweb
, or rather just use cfg(feature="stdweb")
since that is already an optional dependency?
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.
That would be my choice, but cargo does not support features that have the same name as dependencies. We have the same problem with serde
, which has serde-1
as feature flag.
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 didn't know using the name of an optional dependency was possible, much better!
.travis.yml
Outdated
@@ -47,7 +47,7 @@ matrix: | |||
# Cargo has errors with sub-commands so ignore updating for now: | |||
- cargo --list | egrep "^\s*web$" -q || cargo install cargo-web | |||
script: | |||
- cargo web test --target wasm32-unknown-unknown --nodejs | |||
- cargo web test --target wasm32-unknown-unknown --nodejs --features=wasm-stdweb |
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.
Don't forget the feature name here
This is also theoretically the wrong fix unfortunately. What the stdlib does when the feature flag is enabled is assume that an FFI function exists, and calls it. In other words, something like: #[cfg(feature = "foo")]
extern "C" {
fn rand() -> usize;
} |
I don't completely follow what you mean, @tomaka. Can you say a bit more about what is exactly wrong? |
1cc55e6
to
5b5a9a4
Compare
He means that |
I don't understand. |
The general problem is assuming that With this PR, if you use a library A that depends on |
But then are we not ok now? With this PR |
So do we want optional Then I'll answer that: no. We are planning on letting users replace |
Here is the whole background of the discussion if you are motivated for some lecture: rust-lang/rust#47102 |
If and only if library A depends on the The status (after merging this PR) is thus that any attempt to use Rand when targetting |
The problem is that it's not A's job to decide whether to enable the |
That seems like a good, although theoretical concern. If somewhere in the dependency chain A decides But when things are worked out a bit more around WebAssembly, and we have a solution for #313, I think we can revisit this and move more in the direction you have in mind. But for now this simply solves a practical problem. |
There are two solutions to that:
Oh, I see @pitdicker got here before I did 👍 |
BTW rebase and merge? |
5b5a9a4
to
157bf70
Compare
Put stdweb dependency behind a target feature
See #272 (comment), cc @tomaka, @quininer