-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Provide optional features on tokio crate #808
Conversation
@carllerche what do you think of the end result? If it seems like a good idea, I'll fix up the remaining pieces. |
I'd rather only have separate crates for types that are expected to be in the public API of downstream libraries. Instead of a separate crate, what if we allow isolating tokio features in the main crate using feature flags? Then, to only pull in the runtime, you would depend on Alternatively, I was thinking of moving all of I would prefer the first option as it is fewer crates. |
@carllerche Ok, I've redone it to be a set of cargo features.
|
Thanks for doing this. In your opinion, once a breaking change happens, what features should be on by default vs. off by default? |
I'm not sure what you mean. What about a breaking change? I don't believe this PR is breaking. Do you mean for tokio 0.2, should we remove any of these from the |
Yes, in 0.2 should anything be removed from default? |
I don't have an opinion on if any should be removed by default... |
@seanmonstar could you elaborate on why the threadpool feature is not optional? Is it because |
I will try to summarize the discussion we had.
Features in Tokio will be used to limit the number of dependencies. As such, code in |
Tokio will only provide components as sub crates if those types are intended to be used in dependent crates' public API (i.e. crates not part of Tokio). All code that is intended to remain implementation details for Tokio users are provided as part of the main The logic being that sub crates are useful for limiting breaking changes for downstream dependencies. |
For bonus points, it would be super awesome for |
I like the levels of feature flags noted by Carl in #808 (comment). As for:
I am a fan of this. I'm guessing it'll prevent bugs like hyperium/hyper#1736 in the future? |
I've tried making everything optional besides |
This seems like a legit warning. Fix here #822. |
@carllerche I like the plan for adding features as outlined. 👍 And I especially love how Tokio can be tuned for single-threaded or multithreaded use through a simple Cargo feature flag without having to figure out how to set up the Tokio runtime. Choose features you need and launch with |
Latest commit adds CI failure is due to a broken master, waiting on #825. I've updated the main comment with a task list, I believe that's everything. |
And all green! |
Besides the couple of thoughts I commented on above, this looks good to me. Now, how do we make sure we didn't accidentally break anything.... |
AppVeyor had a spurious error. |
To summarize the discussion in Gitter:
At a future time, we can add additional feature flags in a backwards compatible way. |
Done. |
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.
LGTM 👍 Thanks for doing this.
I missed this over the winter break. Overall, it looks good, though I'm a bit worried about this:
Cargo features are supposed to be additive, otherwise all sorts of weird and unpredictable errors start happening. In particular, a crate that depends on See in particular all the pain around |
@jonhoo I’m not following the problem vector. Afaik, the features should be additive. Keep in mind that FutureExt has Future as a super trait and it includes a blanket impl. This prevents any implementations outside of the crate. |
Ah, I see, that was the missing piece! As long as it's effectively sealed, I don't think it raises an issue! |
Based on new feature flags added in (github) tokio-rs/tokio#808, released in tokio 0.1.14, we can avoid the following dependencies: mio-uds, tokio-codec, tokio-fs, tokio-udp, tokio-uds. Also tokio-tcp is now only a testing dev dependency (with some renaming).
The main point of the top-level
tokio
crate is the runtime, many of the other parts of convenience imports. It would be useful to be able to disable any that are not needed, such ascodec
orudp
, for example.Motivation
I'd like to provide runtime features in other crates, like hyper, but don't need all the other dependencies of
tokio
(liketokio-udp
,tokio-fs
,tokio-uds
, etc). If I could just depend on this sub-crate, the number of dependencies would get a bit smaller.Tasks
tokio::run
usecurrent_thread::run
ifthreadpool
isn't enabled.