-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Make explicit opt-out of target discovery neccessary for Rust 2018 #5330
Comments
coming back to this, from @alexcrichton's comment in my #5335 proposal:
(the other PR is #5333) is the desired behaviour, under the condition that you specified a target, like
does that sound right? |
@dwijnand I believe so yeah! We'll still want some way to say "I've exhaustively listed all targets here, please do not continue to infer", but other than that your description sounds accurate. |
part of the reason for my brainstorming is I was wondering if we could avoid the repetition of a key for each target in |
Oh I'd be fine as well with something like |
so that would work well for your "I've exhaustively listed all targets here, please do not continue to infer". but I wonder: what do Rust 2015 users do to silence the warning? if they don't want to infer they too can add their target |
@dwijnand oh for 2015 users I think it's the same as 2018, you'd specify In general we can't really do much for the 2018 edition that we couldn't already do through slow deprecation, so it's mostly just serving as a good banner time to get things done by and send out messaging. |
Introduce autoXXX keys for target auto-discovery In Rust 2015 absence of the configuration makes it default to not include auto-discovered targets (i.e false), with a warnings message. In Rust 2018 absence makes it default to include auto-discovered targets (i.e true). Fixes #5330 --- _original_ Fixes #5330 submitted for early review. feedback very welcome, I'm happy to iterate (and learn). in particular I require assistance with the borrowing of `warnings` in `clean_benches`.
Since we explicit add a test section to specify the `tests.rs` file, there is no need for auto tests inferece. This commit is to disable the annoying warning: warning: An explicit [[test]] section is specified in Cargo.toml which currently disables Cargo from automatically inferring other test targets. This inference behavior will change in the Rust 2018 edition and the following files will be included as a test target: * util.rs * macros.rs This is likely to break cargo build or cargo test as these files may not be ready to be compiled as a test target today. You can future-proof yourself and disable this warning by adding `autotests = false` to your [package] section. You may also move the files to a location where Cargo would not automatically infer them to be a target, such as in subfolders. For more information on this warning you can consult rust-lang/cargo#5330
`cargo build` warns: warning: An explicit [[bin]] section is specified in Cargo.toml which currently disables Cargo from automatically inferring other binary targets. This inference behavior will change in the Rust 2018 edition and the following files will be included as a binary target: * /Users/kivikakk/Code/Nicoretti/xxd-rs/src/bin/main.rs * /Users/kivikakk/Code/Nicoretti/xxd-rs/src/bin/cli.rs This is likely to break cargo build or cargo test as these files may not be ready to be compiled as a binary target today. You can future-proof yourself and disable this warning by adding `autobins = false` to your [package] section. You may also move the files to a location where Cargo would not automatically infer them to be a target, such as in subfolders. For more information on this warning you can consult rust-lang/cargo#5330
I'm getting this warning. i'm trying to enable a feature in the crate for one of my examples. (currently just added |
PR rust-lang#5335 added `autobins`, etc for rust-lang#5330. Nowhere in there is discussion of `autolib`. Cargo script disables support for additional build-targets by disabling discovery. Except we don't have a way to disable discovery of `autolib`, leading to rust-lang#14476. By adding `autolib`, we can continue in that direction. This also allows us to bypass inferring of libs on published packages, like all other build-targets which were handled in rust-lang#13849. As this seems fairly low controversy, this insta-stabilizes the field. In prior versions of Cargo, users will get an "unused manifest key" warning. For packags where this is set by `cargo publish`, the warning will be suppressed and things will work as normal. For `cargo vendor`, the same except there will be some churn in the vendored source as this field will now be set. For local development, it should be rare to set `autolib` so the lack of error by discovering a file when this is set shouldn't be a problem. Fixes rust-lang#14476
PR rust-lang#5335 added `autobins`, etc for rust-lang#5330. Nowhere in there is discussion of `autolib`. Cargo script disables support for additional build-targets by disabling discovery. Except we don't have a way to disable discovery of `autolib`, leading to rust-lang#14476. By adding `autolib`, we can continue in that direction. This also allows us to bypass inferring of libs on published packages, like all other build-targets which were handled in rust-lang#13849. As this seems fairly low controversy, this insta-stabilizes the field. In prior versions of Cargo, users will get an "unused manifest key" warning. For packags where this is set by `cargo publish`, the warning will be suppressed and things will work as normal. For `cargo vendor`, the same except there will be some churn in the vendored source as this field will now be set. For local development, it should be rare to set `autolib` so the lack of error by discovering a file when this is set shouldn't be a problem. Fixes rust-lang#14476
PR rust-lang#5335 added `autobins`, etc for rust-lang#5330. Nowhere in there is discussion of `autolib`. Cargo script disables support for additional build-targets by disabling discovery. Except we don't have a way to disable discovery of `autolib`, leading to rust-lang#14476. By adding `autolib`, we can continue in that direction. This also allows us to bypass inferring of libs on published packages, like all other build-targets which were handled in rust-lang#13849. As this seems fairly low controversy, this insta-stabilizes the field. In prior versions of Cargo, users will get an "unused manifest key" warning. For packags where this is set by `cargo publish`, the warning will be suppressed and things will work as normal. For `cargo vendor`, the same except there will be some churn in the vendored source as this field will now be set. For local development, it should be rare to set `autolib` so the lack of error by discovering a file when this is set shouldn't be a problem. Fixes rust-lang#14476
PR rust-lang#5335 added `autobins`, etc for rust-lang#5330. Nowhere in there is discussion of `autolib`. Cargo script disables support for additional build-targets by disabling discovery. Except we don't have a way to disable discovery of `autolib`, leading to rust-lang#14476. By adding `autolib`, we can continue in that direction. This also allows us to bypass inferring of libs on published packages, like all other build-targets which were handled in rust-lang#13849. As this seems fairly low controversy, this insta-stabilizes the field. In prior versions of Cargo, users will get an "unused manifest key" warning. For packags where this is set by `cargo publish`, the warning will be suppressed and things will work as normal. For `cargo vendor`, the same except there will be some churn in the vendored source as this field will now be set. For local development, it should be rare to set `autolib` so the lack of error by discovering a file when this is set shouldn't be a problem. Fixes rust-lang#14476
PR rust-lang#5335 added `autobins`, etc for rust-lang#5330. Nowhere in there is discussion of `autolib`. Cargo script disables support for additional build-targets by disabling discovery. Except we don't have a way to disable discovery of `autolib`, leading to rust-lang#14476. By adding `autolib`, we can continue in that direction. This also allows us to bypass inferring of libs on published packages, like all other build-targets which were handled in rust-lang#13849. As this seems fairly low controversy, this insta-stabilizes the field. In prior versions of Cargo, users will get an "unused manifest key" warning. For packags where this is set by `cargo publish`, the warning will be suppressed and things will work as normal. For `cargo vendor`, the same except there will be some churn in the vendored source as this field will now be set. For local development, it should be rare to set `autolib` so the lack of error by discovering a file when this is set shouldn't be a problem. Fixes rust-lang#14476
feat(toml): Add `autolib` ### What does this PR try to resolve? PR #5335 added `autobins`, etc for #5330. Nowhere in there is discussion of `autolib`. Cargo script disables support for additional build-targets by disabling discovery. Except we don't have a way to disable discovery of `autolib`, leading to #14476. By adding `autolib`, we can continue in that direction. This also allows us to bypass inferring of libs on published packages, like all other build-targets which were handled in #13849. Fixes #14476 ### How should we test and review this PR? ### Additional information As this seems fairly low controversy, this insta-stabilizes the field. In prior versions of Cargo, users will get an "unused manifest key" warning. For packages where this is set by `cargo publish`, the warning will be suppressed and things will work as normal. For `cargo vendor`, the same except there will be some churn in the vendored source as this field will now be set. For local development, it should be rare to set `autolib` so the lack of error by discovering a file when this is set shouldn't be a problem.
Currently, Cargo automatically discovers tests, examples and binaries form the files on the file system. One can also add an explicit
[[example]]
section to Cargo.toml, to add non-discoverable examples, or to tweak an existing example (for example, by specifying required features).However, adding explicit
[[target]]
disables automatic discovery for other targets of similar type, and this behavior is highly surprising.Current Proposal
New keys will be available under the
[package]
section ofCargo.toml
:The value of each of these keys indicates whether or not Cargo's automatic inference logic is in effect for discovering targets. Turning these keys to
false
will completely disable inference and Cargo will not attempt to find more targets. For example settingautobins = false
will disable Cargo probingsrc/bin
looking for binaries.If these keys are turned to
true
then Cargo will probe the standard set of directories for targets. Any explicitly named targets in the manifest will be merged with the automatically found targets. For example ifautotests = true
is enabled and you've gottests/foo.rs
andtests/bar.rs
, you could disable the test harness oftests/foo.rs
with:and you'll still be able to use
cargo test --test bar
as Cargo will automatically find thetests/bar.rs
test.In the 2015 edition (today in Cargo) these keys are set with the following rules:
false
. For example writing[[bin]]
will setautobins = false
automatically.true
.In the 2018 edition these keys will be unconditionally set to
true
by default.Impact on Users Today
Unconditionally turning these keys to
true
is a breaking change as it can cause files that weren't previously compiled as a test, for example, to get compiled as a test. As a result projects will need to reorganize their files or otherwise setautotests = true
, for example.If you receive a command-line warning though and don't know what to do with that, please leave a comment here!
Original Proposal
We would like to change this behavior eventually and for that in Rust 2018 we should:
autodiscover
for each target type, with values true and false (precise flag name and syntax are subject to bike shedding).autodiscover
is not specified, at least a single[[target]]
is listed, and some other target would be discovered ifautodiscover
was set totrue
.autodiscover
default totrue
.The relevant code is here: https://github.com/rust-lang/cargo/blob/d8b20310217e5e2bc515c13111ab9a7789709e42/src/cargo/util/toml/targets.rs. Note that the logic there is pretty subtle, because we already carry a significant backwards compatibility baggage :(
It might be a good idea to flip some of those warnings to errors in 2018 as well!
The text was updated successfully, but these errors were encountered: