Skip to content
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

Tokio 0.2 #[tokio::main] regression #1833

Closed
SvetlinZarev opened this issue Nov 27, 2019 · 5 comments
Closed

Tokio 0.2 #[tokio::main] regression #1833

SvetlinZarev opened this issue Nov 27, 2019 · 5 comments

Comments

@SvetlinZarev
Copy link

Version

Both tokio 0.2.0 and 0.2.1

`--> cargo tree | grep tokio
└── tokio v0.2.1

Platform

Darwin C02XC3DFJGH6 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64

Description

When I try to compile the most basic example:

use tokio::prelude::*;
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    Ok(())
}

cargo toml:


[package]
name = "mcve"
version = "0.1.0"
authors = ["Svetlin Zarev <xxxxx>"]
edition = "2018"

[profile.release]
lto = "thin"
opt-level = 3
codegen-units = 1

[dependencies]
tokio = "0.2.1"

I get the following error:

error[E0433]: failed to resolve: could not find `main` in `tokio`
 --> src/main.rs:4:10
  |
4 | #[tokio::main]
  |          ^^^^ could not find `main` in `tokio`

If I revert to 0.2.0-alpha.6 it builds successfully. This is slimmed-down version of the example in the README: https://github.com/tokio-rs/tokio

@SvetlinZarev
Copy link
Author

I was too. quick to open the issue :( It seems that everything in the new version is behind feature flags. In order fo rthe #[tokio::main] macro to work, one needs:

[dependencies]
tokio = {version = "0.2.1", features = ["macros"]}

it would be nice if this is mentioned in the readme

@carllerche
Copy link
Member

Can you point where in the readme? I believe it mentions the “full” feature flag, which includes macros but it is likely we missed somewhere.

@SvetlinZarev
Copy link
Author

The feature flags are not mentioned at all: https://github.com/tokio-rs/tokio/blob/master/README.md I've just seen them mentioned in your blogpost in reddit :)

What about appending part of the tour of tokio section content to the existing content in the "overview" section ?

[... existing content...]
These components provide the runtime components necessary for building an asynchronous application.

[... here comes the relevant parts from docs.rs]

Note that Tokio uses Cargo feature flags to allow users to control what features are present, so that unused code can be eliminated. This documentation also lists what feature flags are necessary to enable each API.

The easiest way to get started is to enable all features. Do this by enabling the full feature flag:
tokio = { version = "0.2", features = ["full"] }

mre added a commit to mre/github-star-counter that referenced this issue Nov 28, 2019
As of tokio 0.2, features are hidden behind flags.
For example, macros require the `macro` feature.
See tokio-rs/tokio#1833
for a more detailed description.

The easiest way to stay up-to-date is by enabling
the `full` feature flag, which is analog to the
previous behavior. This fixes `cargo install`.

Also, the `async_await` feature can be removed
as it is stable since rustc 1.39.
mre added a commit to mre/github-star-counter that referenced this issue Nov 28, 2019
As of tokio 0.2, features are hidden behind flags.
For example, macros require the `macro` feature.
See tokio-rs/tokio#1833
for a more detailed description.

The easiest way to stay up-to-date is by enabling
the `full` feature flag, which is analog to the
previous behavior. This fixes `cargo install`.

Also, the `async_await` feature can be removed
as it is stable since rustc 1.39.
mre added a commit to mre/github-star-counter that referenced this issue Nov 28, 2019
As of tokio 0.2, features are hidden behind flags.
For example, macros require the `macro` feature.
See tokio-rs/tokio#1833
for a more detailed description.

The easiest way to stay up-to-date is by enabling
the `full` feature flag, which is analog to the
previous behavior. This fixes `cargo install`.
@Menschenkindlein
Copy link

Hi,
It makes sense to mention feature flags in README, as they are a crucial part of the API of the library. Just copying the part of the docs and a link to them would help a lot.

@Darksonn
Copy link
Contributor

Closing in favor of #2626.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants