Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upNeed ability to add dependencies based on `#[cfg()]` #1007
Comments
jmesmon
referenced this issue
Dec 3, 2014
Closed
Missmatch between usage and dependence on openssl-sys breaks non-blessed triples #33
This comment has been minimized.
This comment has been minimized.
|
To clarify, one may wish to say |
This was referenced Jan 3, 2015
alexcrichton
referenced this issue
Feb 28, 2015
Closed
Replace target dependencies by a free-form target_filter field #1364
This comment has been minimized.
This comment has been minimized.
|
|
alexcrichton
added
the
P-high
label
May 18, 2015
This was referenced May 26, 2015
This comment has been minimized.
This comment has been minimized.
|
Another alternative mentioned by @larsbergstrom would be: [target."x86_64-*".dependencies]
# ...
[target."*-linux-*".dependencies]
# ... |
larsbergstrom
referenced this issue
May 26, 2015
Closed
Tracking issue for Rust high-pri or blocking issues for Servo & Gecko #2853
This comment has been minimized.
This comment has been minimized.
|
I'd like to caution against trying to assume anything about targets from their triples. Trying to extract meaning about targets out of the triple will be fairly error prone & in some cases will completely fail (or be impossible). Possibly: rustc would expose a way of determining the attributes of a given target (looking at it's builtin targets & the requested json target) and cargo would query that. Alternately: we could remove all the builtin target knowledge and push it into json files installed in rustlib, and cargo could read them directly. |
alexcrichton
referenced this issue
Jun 27, 2015
Closed
Simplified Target-Specific Dependencies #1758
chris-morgan
added a commit
to chris-morgan/term
that referenced
this issue
Jul 30, 2015
chris-morgan
referenced this issue
Jul 30, 2015
Closed
Only depend on kernel32 and winapi on Windows #37
This comment has been minimized.
This comment has been minimized.
metajack
commented
Jul 31, 2015
|
I'd like to push on this feature a little bit. After dealing with this in Servo and living with having to specify the same dependency multiple times (2x for linux and 2x for arm!), we now have a dependency on rand, which would have to have 4 target triples listed for windows. The upstream author is unwilling to do this, so we're back to conditional compilation of win32api on Linux and OS X. If this doesn't get fixed soon, the community norm is going to be do make builds inefficient by using conditional compilation, and it's going to be confusing to people who are watching platform specific deps scroll by the build window. |
This comment has been minimized.
This comment has been minimized.
|
@metajack I agree. I am already depending on the windows crate unconditionally in mio because of this. It has confused people but I really don't want to manage huge lists of repeated deps |
This comment has been minimized.
This comment has been minimized.
|
I agree this is a problem that needs to be fixed, but I don't understand your concerns about unconditionally including crates. The compile time for a crate which is entirely I agree that the ergonomics of target-specific dependencies aren't great today and that including Windows crates on a Unix build "feels wrong", but from a technical perspective I don't think there are many downsides of just unconditionally depending on the Windows crates on Unix. |
This comment has been minimized.
This comment has been minimized.
metajack
commented
Aug 3, 2015
|
My concern is that when you are debugging the Servo build and trying to isolate problems, having 30 extra dependencies to sort through makes your life harder. Switching this later could potentially leave a slew of crates which #[cfg] out the whole crate all the time and mean adoption of target dependencies will never take off. And for many of Servo's crates, this added a lot of annoying things since every lang item in lib.rs needs to be cfged out; you can't just have a crate level one (or at least you couldn't back when I originally did this for Servo). See servo/io-surface-rs@fba38ef for an example cleanup. Also, everyone keeps telling me that this free, and yet everyone seems to ignore that Servo has probably the largest dependency graph and surfaces a lot of performance problems that other projects don't see. This will not always be the case; I assume there will be lots of large Rust projects. The fact that people still write build systems to eke out better build times in C and C++ gives some reason to believe that there will be demand to shave these wasted cycles. |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton the main issue is that it confuses people who are new as it is pretty unexpected behavior. |
This comment has been minimized.
This comment has been minimized.
Isn't this just inherent problems in a project of Servo's size? If you take out all non-relevant dependencies, aren't you still working with ~100 dependencies?
By "lang item" do you mean just normal item? This has actually since been fixed in the compiler so you can just place
Right I don't mean to say that it's literally free, just that in the time it takes to compile the script crate I think that hundreds of empty crates could possibly be compiled. I don't think that have a few extra leaf dependencies (even up to 30) would add much to a build time. That being said I want to clarify if you've measured something to the contrary in this regard. Overall I don't mind putting more effort into solving this, but I just want to make sure that it's not being prioritized because it's a "nice to have" and instead has some solid technical motivation. If Servo does indeed see an noticeable improvement in build times or general "Cargo is doing things" times then that's a pretty solid reason.
Sure, I can totally understand that, just wanted to clarify if there was a technical reason for wanting to fast-track this. |
This comment has been minimized.
This comment has been minimized.
metajack
commented
Aug 3, 2015
|
Fair points. The reasons are clearly mostly social ones. Platform deps are too difficult now, and I feel that if we don't make them usable soon (especially for Windows) then we risk them not getting community buy in. I'm glad to hear that you can use |
This comment has been minimized.
This comment has been minimized.
|
Yeah I'm also worried about community buy in, but thanks for the clarifications! |
This comment has been minimized.
This comment has been minimized.
|
This should be easy to implement using rustc_back::target::Target, but I guess using unstable features in Cargo is a no-go? #![feature(rustc_private)]
extern crate rustc_back;
use rustc_back::target::Target;
fn main() {
println!("{:?}",Target::search("x86_64-unknown-linux-musl"));
} |
This comment has been minimized.
This comment has been minimized.
|
I think we can solve this by adding a
Then in Cargo, something like [target.cfg.unix.dependencies]
# ...will trigger a call to |
lfairy
added a commit
to lfairy/rust-errno
that referenced
this issue
Sep 1, 2015
This comment has been minimized.
This comment has been minimized.
jpernst
commented
Sep 9, 2015
|
I'd also like to voice support for this feature as it pertains to private production deployments. Even if a dependency happens to compile away to nothing, we still become responsible for including it in our build environment and are exposed to transitive breakage if it ever fails to build for any reason. While Rust itself may be providing strong stability guarantees, libraries on crates.io are under no such obligation. I'm concerned that the status quo is becoming the blanket inclusion of dependencies that aren't really necessary for the core functioning of the libraries that include them. This adds noise to the dependency graph and complicates the evaluation of a library for use in production. |
This comment has been minimized.
This comment has been minimized.
|
I would also like a feature like this. If the cfg or "-linux-" matching is not desirable, maybe we could also let the target be specified in the dependency, rather than the other way around: [dependencies.winapi]
target = ['i686-pc-windows-gnu', 'i686-pc-windows-msvc', 'x86_64-pc-windows-gnu', 'x86_64-pc-windows-msvc']This way the version and path and other data would only have to be specified once. In some cases this would seem to make more sense than the other way around. |
This comment has been minimized.
This comment has been minimized.
|
@mvdnes That still suffers the issue where if a new windows target triple is working, all the libraries using that form won't work on the new triple until they're updated. |
alexcrichton
referenced this issue
Oct 9, 2015
Closed
Custom x86 target breaks openssl_sys crate #2043
alexcrichton
referenced this issue
Oct 29, 2015
Closed
Disable windows dependencies on other platforms #124
This comment has been minimized.
This comment has been minimized.
|
I've now opened an RFC to help close this issue. |
This comment has been minimized.
This comment has been minimized.
|
Here is an example where we’d like to reduce duplication somehow: |
This comment has been minimized.
This comment has been minimized.
|
Oh, right! Implemented in #2328 |
jmesmon commentedDec 3, 2014
For example, in curl-rust:
Usage: https://github.com/carllerche/curl-rust/blob/5d0f5c8848e3cf1e12480a1923ae888e24d58f63/src/lib.rs#L10
Dependence: https://github.com/carllerche/curl-rust/blob/5d0f5c8848e3cf1e12480a1923ae888e24d58f63/curl-sys/Cargo.toml#L18-L30
Also see alexcrichton/curl-rust#30
In summary: without this, we end up with ad-hoc lists of triples in various
Cargo.tomlfiles, which breaks the build for targets with a non-matching triple that do match#[cfg(...)].