-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Allow limiting required crate-types of dependencies #11232
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
Comments
Artifiact dependencies might not help if you just want to limit dependency to only build If I were you, I may contact the author of my dependency crate. Tell them there is a newly stabilized flag |
cc @BurntSushi I suppose, as I noticed this when trying to link It seems odd to have a crate like that which is only intended to provide a c api not marked as |
Yeah I'm not sure what to make of this. I don't get many complaints about rure compile time, so this particular problem isn't really on my radar. |
…ts, r=#xpcom-reviewers CLOSED TREE Cargo will attempt to build all targets for dependencies, and there appears to be no option to turn that functionality off (see rust-lang/cargo#11232). If we try to build the `rure` crate as a cdylib during a PGO build, it causes linker issues, which make the build fail. As this artifact isn't necessary for our build, we can patch the crate to remove the cdylib and staticlib crate-type definitions, making the build pass as only the artifact we need is built. Differential Revision: https://phabricator.services.mozilla.com/D159332
…ts, r=#xpcom-reviewers CLOSED TREE Cargo will attempt to build all targets for dependencies, and there appears to be no option to turn that functionality off (see rust-lang/cargo#11232). If we try to build the `rure` crate as a cdylib during a PGO build, it causes linker issues, which make the build fail. As this artifact isn't necessary for our build, we can patch the crate to remove the cdylib and staticlib crate-type definitions, making the build pass as only the artifact we need is built. Differential Revision: https://phabricator.services.mozilla.com/D159332
To me, the core problem is that if crate A depends on crate B, the only thing that cargo can handle is B being a rlib and using it to build A. If B is a cdylib or a staticlib, cargo won't handle the situation. So really, the only thing cargo can handle is B being a rlib. Now, if you're building A, why does cargo care to build something else than the rlib? would be the issue IMO. |
Problem
When depending on a crate which declares it supports multiple crate types in its
[lib]
section, cargo will always build all of the specified crate types when building the dependency. This means that a crate which specifies something like the following in itsCargo.toml
will always build a cdylib and staticlib when built as a dependency, even if we're only going to be using the normal lib dependency.This leads to wasted effort building unnecessary artifacts for dependencies, and can also lead to issues when the configuration used to build the lib would cause building the cdylib or staticlib to fail to link for whatever reason (e.g. due to linker flags).
Proposed Solution
It would be nice if there was a way to specify which crate types you are depending on from your dependencies when declaring a dependency in Cargo.toml, similar to how you can specify required feature flags.
I imagine this acting in a similar way to features, where when a dependency is declared without a
crate-type
specification, it implicitly requires the crate types from the dependency'sCargo.toml
, and a dependency withcrate-type
only requires the specified crate types.This might look something like the following:
Notes
There may be some overlap between this and other work for artifact dependencies (#9096), although I am not familiar enough with the work in that area to know if it already covers this use-case.
The text was updated successfully, but these errors were encountered: