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

Example app in console-subscriber doesn't build #252

Closed
hardliner66 opened this issue Jan 7, 2022 · 7 comments
Closed

Example app in console-subscriber doesn't build #252

hardliner66 opened this issue Jan 7, 2022 · 7 comments

Comments

@hardliner66
Copy link

The app example in console-subscriber fails because it's trying to use task::Builder which is non existent.

@hawkw
Copy link
Member

hawkw commented Jan 7, 2022

tokio::task::Builder is an unstable tokio API. This means you need to build with the environment variable RUSTFLAGS="--cfg tokio_unstable".

In general, the console relies on unstable features in Tokio (the tracing support that powers the console is also unstable). So, to use the console, you will need to enable --cfg tokio_unstable. See here for details.

There's a .cargo/config file in this repository that should automatically enable this flag when building inside the console repo (such as building the examples). I'm surprised that didn't work for you --- did you move the example app to another directory before trying to build it?

@iulianR
Copy link

iulianR commented Jan 7, 2022

I also hit this problem just now. While looking for the solution I came across this other issue: rust-lang/cargo#5376 (comment). In my case, I have this in my ~/.cargo/config.toml:

[target.x86_64-unknown-linux-gnu]
linker = "/usr/bin/clang"
rustflags = ["-Clink-arg=-fuse-ld=lld"]

Commenting the rustflags in there solves the problem.

@hawkw
Copy link
Member

hawkw commented Jan 7, 2022

Oh, that makes sense; the working directory's .cargo/config rustflags setting isn't combined with the global .cargo/config's. That seems mildly surprising...

@hardliner66
Copy link
Author

hardliner66 commented Jan 10, 2022

I have the same settings set in my ~/.cargo/config.

Currently it seems that the more specific [target.x86_64-unknown-linux-gnu] in ~/.cargo/config overrides the more generic [build] in the current project. If you change the local .cargo/config to [target.x86_64-unknown-linux-gnu] instead of [build] it properly combines with the settings from ~/.cargo/config.

So in order for it to work properly for all targets you can set rustflags for each triple where you or a teammate uses a custom rustflags setting.

e.g.:

[build]
rustflags = ["--cfg", "tokio_unstable"]

[target.x86_64-unknown-linux-gnu]
rustflags = ["--cfg", "tokio_unstable"]

This isn't ideal, but can be worked around. Depending on your use case, it might make sense to just add the tokio settings to the global config file instead and enable it everywhere.

@hawkw
Copy link
Member

hawkw commented Jan 10, 2022

@hardliner66 oh, that's interesting! Perhaps we should add [target.<TARGET>] settings to the .cargo/config in this repo so that the examples works. We should probably do this for all common targets, so that it also works if, for example, people are building on MacOS and have per-target rustflags overrides...

@hardliner66
Copy link
Author

It should at least be documented as a gotcha, but having a copy-paste ready example for the most common targets sounds reasonable.

@hawkw
Copy link
Member

hawkw commented Apr 14, 2022

The documentation has been updated to warn about this, so I'm going to close this issue now.

@hawkw hawkw closed this as completed Apr 14, 2022
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

3 participants