-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add tokio feature and make tokio optional #1054
Conversation
Not quite sure how but maybe we should add a step to CI that somehow verifies that tokio isn't pulled in when this feature isn't enabled. Otherwise I imagine its the kind of thing we could easily break by accident. The feature should also be mentioned here. |
That's a really good idea. Maybe a combination of And I'll add the feature to the docs. Are we good with naming it |
0466105
to
c413265
Compare
Yeah something like that could probably work.
How about just calling the feature |
436ae4a
to
1b4d13d
Compare
@fisherdarling whats the status of this? I remember we talked a bunch in Discord but don't remember if we reached any conclusions. |
@davidpdrsn I'm currently blocked on trying to figure out CI. Maybe an example needs to be created that uses axum just for its router, so that mio won't be compiled? Checking that example with the wasm target might work as a CI check. I'm going to be traveling the next two weeks, but I might have time tonight or this weekend to finish it up. |
40ff234
to
3a2dd86
Compare
42774ad
to
b353b27
Compare
@fisherdarling You mentioned on discord that you had run into issues with having to run |
b353b27
to
df3e787
Compare
df3e787
to
ff545b7
Compare
@davidpdrsn I was actually able to get it to work! I've actually switched almost all of my worker code to use the router, which has been extremely nice to have. I just needed a Axum regularly has breaking changes, so I think removing the Honestly, I'm happy to just maintain my own fork for now if you don't want to merge it in or are hesitant to do so. The "true" fix would be to separate the router into an |
So do you need the |
@jplatte I do need the |
Then what did you mean by
|
Sorry, that was definitely a little confusing and needs some context. Just to be clear, my overall goal is to use an Everything that axum provides that requires an underlying runtime or server is not necessary for my use case and generally leads to compilation issues for wasm targets. That's why this PR adds a feature flag for that code. All of the code that I do want, is all of the awesome code that makes it easy to work with What I meant by this:
Is that I think it would be beneficial to have the
With those crates split out, I could just pull in I think this is something that would be beneficial, but I also think that the number of people that would directly benefit from this is rather low (just me right now). Most people (everyone so far?) are running axum on a server with tokio and don't care about nor need fine-grained crate imports. Overall, the current PR lets me use the parts of the crate I love for a wasm target. Sorry if this is kind of a ramble. |
The idea of putting the router in its own crate has come up before but I'm a bit hesitant towards that. I'm worried we'll end up with too many So I'm in favor of keeping I'm gonna try and take a look at this this week but since its a breaking change it wont be released for a while. We don't have any concrete plans for 0.6 and there are some things in the pipeline I wanna work on first (such as matchit/routing changes) |
I completely agree and understand. I remember when tokio had so many
Sounds good, I'll try to keep the branch updated to main. |
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.
Really awesome work! Sorry for taking so long to review it. I think it looks good but I'm curios if tokio-rs/tokio#4716 is relevant here.
@@ -0,0 +1,11 @@ | |||
[package] | |||
name = "simple-router-wasm" |
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.
name = "simple-router-wasm" | |
name = "example-simple-router-wasm" |
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.
All our other examples are named like this.
Could consider that since they're now in their own workspace but we should change that in a stand alone PR.
//! Run with | ||
//! | ||
//! ```not_rust | ||
//! cd examples && cargo run -p simple-router-wasm |
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.
//! cd examples && cargo run -p simple-router-wasm | |
//! cd examples && cargo run -p example-simple-router-wasm |
publish = false | ||
|
||
[dependencies] | ||
axum = { path = "../../axum", default-features = false } |
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.
Maybe call this out specifically so users see it.
axum = { path = "../../axum", default-features = false } | |
# `default-features = false` to not depend on tokio which doesn't support compiling to wasm | |
axum = { path = "../../axum", default-features = false } |
I'm very interested in this and seeing this PR made my day! I was able to get a web app running in a CF worker using a fork of Tide. However, my PR for WASM support is stagnant. I'd be interested in helping out in any way to help move this PR along. I was also able to "run" the Tide web app as an SPA, I imagine this PR would allow for the same. I'm going to pull this PR down and give it a try when I have time this weekend. |
This PR works well running in the browser. I made a simple example repo with a demo. @davidpdrsn - thanks for your help on Discord! |
On the other hand, this PR doesn't build for me. As you mentioned above, it still pulls tokio because of tower and hyper, as shown in this reverse dependency tree:
Which wouldn't be horrible, because some tokio features do work on wasm32-unknown-unknown. edit: Removing the "make" feature in Cargo.toml (l. 44) makes it build 🎉 It seems to be used in 1 test utility, so don't just remove that in this PR |
Hey all, sorry for being MIA! I just started a new job and have been pretty busy these past couple of months. @logankeenan I'm glad the PR worked for you and that it benefits you! I would love some help moving this PR along if you can. I won't have the time to work on it for a while. I think next steps are to evaluate if the wasm-wasi change can be used and is helpful. If you want to start from scratch in another PR feel free to. I'll close this one and link to the new one. @kpietraszko It has to pull in tokio right now because of |
@logankeenan feel free to ping me |
@fisherdarling WASI support is a great addition, but the use-case is a bit different. For example Cloudflare Workers don't support WASI modules out of the box, only WASM. One would need to create their own JS shim I believe. That said there are some services that allow hosting WASI, such as Fastly. |
I haven't worked with WASI before, but that doesn't mean I couldn't learn more about it. Could that work potentially be done in another PR? PS, congratulations on the new job! |
@fisherdarling - I created a new PR based on your branch. cc @kpietraszko |
Let's continue the in #1382 @fisherdarling thanks for your work on this. |
Motivation
I'm trying to use axum's routing and request extraction hardware for a Cloudflare Worker. Workers run in a WASM context (v8 isolate) and therefore tokio cannot be used.
Solution
This PR adds a
tokio
feature that enables tokio as well ashyper/tcp
andhyper/server
. The tokio feature also enables SSE andextract::connect_info
.This is a breaking change since this breaks usages of
default_features = false
.