-
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
Implement cfg-based target-specific dependencies #2328
Conversation
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
Note that this will require rust-lang/rust#31278 to land first to get the CI/tests to pass, but I figured I'd at least put this up for review? |
This will be great. Maybe we can knock |
This only supports a subset of Rust's attribute syntax. In particular, it doesn't support the 'list' meta item type, instead hardcoding 'all', 'not', and 'any'. ISTM that we should keep them at parity and support the same grammar in both places. |
Ah that's because right now Rust doesn't actually allow Would you prefer that the grammar itself is represented the same way, though, and then there's a pass afterwards to make sure it's a valid meta item by parsing but error'ing on strings like |
6284085
to
3b18097
Compare
a191553
to
af294cf
Compare
☔ The latest upstream changes (presumably #2370) made this pull request unmergeable. Please resolve the merge conflicts. |
e823157
to
5ec35c9
Compare
Two more notes I have since realized:
|
☔ The latest upstream changes (presumably #2387) made this pull request unmergeable. Please resolve the merge conflicts. |
This commit is an implementation of [RFC 1361][rfc] which is an extension of Cargo's `target` section in `Cargo.toml` to allow the use of `#[cfg]`-like expressions for target-specific dependencies. Now that the compiler has been extended with `--print cfg` each invocation of Cargo will scrape this output and learn about the relevant `#[cfg]` directives in play for the target being compiled. Cargo will then use these directives to decide whether a dependency should be activated or not. This should allow definition of dependencies along the lines of: [target.'cfg(unix)'.dependencies] [target.'cfg(target_os = "linux")'.dependencies] [target.'cfg(windows)'.dependencies] Which is much more ergonomic and robust than listing all the triples out!
5ec35c9
to
f5d786e
Compare
@bors r+ |
📌 Commit f5d786e has been approved by |
This commit is an implementation of [RFC 1361][rfc] which is an extension of Cargo's `target` section in `Cargo.toml` to allow the use of `#[cfg]`-like expressions for target-specific dependencies. Now that the compiler has been extended with `--print cfg` each invocation of Cargo will scrape this output and learn about the relevant `#[cfg]` directives in play for the target being compiled. Cargo will then use these directives to decide whether a dependency should be activated or not. This should allow definition of dependencies along the lines of: [target.'cfg(unix)'.dependencies] [target.'cfg(target_os = "linux")'.dependencies] [target.'cfg(windows)'.dependencies] Which is much more ergonomic and robust than listing all the triples out!
☀️ Test successful - cargo-linux-32, cargo-linux-64, cargo-mac-32, cargo-mac-64, cargo-win-gnu-32, cargo-win-gnu-64, cargo-win-msvc-32, cargo-win-msvc-64 |
* Sections like `[dependencies.foo]` can be entries in a `[dependencies]` section with the `{key = value}` syntax. * Per-target dependencies can be expressed with more general `cfg(…)` conditions instead of exact target triples: rust-lang/cargo#2328
* Sections like `[dependencies.foo]` can be entries in a `[dependencies]` section with the `{key = value}` syntax. * Per-target dependencies can be expressed with more general `cfg(…)` conditions instead of exact target triples: rust-lang/cargo#2328
Simplify TOML syntax * Sections like `[dependencies.foo]` can be entries in a `[dependencies]` section with the `{key = value}` syntax. * Per-target dependencies can be expressed with more general `cfg(…)` conditions instead of exact target triples: rust-lang/cargo#2328 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10857) <!-- Reviewable:end -->
Would of been nice if this syntax was supported on all of the options... [workspace.'cfg(target_os = "linux")']
#...
# Example for the Cargo.toml present in the Rust source "rust/src/Cargo.toml"
[profile.release.'cfg(windows)']
opt-level = 2
[dependencies.'cfg(windows)']
winapi = "0.2"
[dev-dependencies.'cfg(target_os = "linux")']
libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" } |
Clean up TargetInfo - The main motivation here is to provide a better error message when collecting information from rustc fails (it now shows the command and the output). - Remove `has_cfg_and_sysroot`. I think this dates back to when it was introduced in #2328, as a guard for older versions of rustc that did not know about `--print=cfg`. Unless I'm missing something, I don't think we need to retain this backwards compatibility. - Add some documentation. - Demote the rustc cache log messages to `debug` level. I haven't really seen any caching issues, so I don't think it needs to be info level. - Some other misc cleanup (remove unused function, etc.).
* Sections like `[dependencies.foo]` can be entries in a `[dependencies]` section with the `{key = value}` syntax. * Per-target dependencies can be expressed with more general `cfg(…)` conditions instead of exact target triples: rust-lang/cargo#2328 Source-Repo: https://github.com/servo/servo Source-Revision: 2729864af73d62719ea0fd55cef417c43bdd951e UltraBlame original commit: 6710bf1dbafec084574fd82064e1f7896091bacf
* Sections like `[dependencies.foo]` can be entries in a `[dependencies]` section with the `{key = value}` syntax. * Per-target dependencies can be expressed with more general `cfg(…)` conditions instead of exact target triples: rust-lang/cargo#2328 Source-Repo: https://github.com/servo/servo Source-Revision: 2729864af73d62719ea0fd55cef417c43bdd951e UltraBlame original commit: 6710bf1dbafec084574fd82064e1f7896091bacf
* Sections like `[dependencies.foo]` can be entries in a `[dependencies]` section with the `{key = value}` syntax. * Per-target dependencies can be expressed with more general `cfg(…)` conditions instead of exact target triples: rust-lang/cargo#2328 Source-Repo: https://github.com/servo/servo Source-Revision: 2729864af73d62719ea0fd55cef417c43bdd951e UltraBlame original commit: 6710bf1dbafec084574fd82064e1f7896091bacf
This commit is an implementation of [RFC 1361][rfc] which is an extension of
Cargo's
target
section inCargo.toml
to allow the use of#[cfg]
-likeexpressions for target-specific dependencies. Now that the compiler has been
extended with
--print cfg
each invocation of Cargo will scrape this output andlearn about the relevant
#[cfg]
directives in play for the target beingcompiled. Cargo will then use these directives to decide whether a dependency
should be activated or not.
This should allow definition of dependencies along the lines of:
Which is much more ergonomic and robust than listing all the triples out!