-
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
Features enabled through build scripts should have an effect on dependencies #5499
Comments
This is currently expected behavior in that Cargo doesn't allow activating features at build-script-time but rather they must be activated manually by the user (as they affect crate graph resolution). We may wish to provide a warning, here, however, or something like tha.t |
We can't enable features in build.rs, see rust-lang/cargo#5499, and cargo doesn't support target-specific default features, see rust-lang/cargo#1197. Essentially we build as we used to do before we added features for terminal emulators. Downsides are more dependencies than needed—you don’t need iterm2 on Linux after all—and Windows doesn't build with default features at all. This reverts commit 544943a.
I just learned from the Cargo IRC channel that this is the expected behavior. It'd definitely be nice to at least mention it in the docs. However, I'd agree with @glandium that it would be ideal if there was a build-script-time setting that could activate conditional dependencies. It doesn't have to be based on features, it could be based on other configs, such as |
I'm confused, did that get changed? winapi seems to be doing something like that. |
Oh, I just unconfused myself, they do have influence over the current crate being built, not the dependencies, disregard me. |
With Cargos current architecture, this is technically not possible. The build script is run (once) after the dependencies are built, so without time travel it can not add dependencies. |
Could you theoretically make a prebuild script, or a setting that enables it depending on what a function returns? |
something like [features.enable]
foo = "src/build::enable_foo"
bar = "src/build::enable_bar" fn enable_foo() -> bool{
true
}
fn enable_bar() -> bool{
false
} would this be possible? |
I've been using build scripts to enable features based on rust versions automatically, such that if you build with a version that added a new feature to the language or libstd, users of the crate can automatically get those without having to manually enable features.
But sometimes, the feature needs another crate as dependency. In that case, what you really want is an optional dependency, and for the feature to enable it. But the only way to enable a feature from a build script only enables the feature from rustc perspective, not cargo's.
So, say you have a
Cargo.toml
with something like:or
A build script that does:
won't make the optional dependency built in either case, which makes sense because it's all about rustc, but should, IMHO, be supported.
The text was updated successfully, but these errors were encountered: