-
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
DEP_FOO_KEY-like system that can work without "links" #3544
Comments
Yeah I've often desired such a feature as well. I've had difficulty rationalizing in the past what Other than that though it seems like a reasonable feature to me! |
You can't depend directly on two versions of the same crate though, right? Are |
@sfackler not currently, no, but I could imagine adding that as a feature to Cargo at some point. I think we'd only want to expose immediate dependencies to build scripts, not transitive, as that'd make the problem much easier (and more practical I think) |
Well so we may be able to actually just go ahead and do this. So Cargo will pass a number of We'd probably want to spec that the name in the env var though is the name of the library, not the name of the package. That differs in a few rare cases but would future-proof us a bit. |
You currently can depend on two crates that have the same library name, yet different package names, even straight from crates.io. |
I fully expected I’ve ended up adding to a crate a |
As far as I can tell these |
I'll again refer to my previous comments:
@SimonSapin @retep998 if you'd like to send a PR for this it'd definitely be most welcome! |
If we do add |
We could just use a different namespace, such as |
I think it'd be a good idea in general to start migrating to a |
I have a pretty similar case as the initial reporter for indygreg/PyOxidizer. I have a crate with a build script that needs to generate a library containing a special build of Python. The build process also generates some files which are consumed by callers into that library from a different crate. I'd like for the crate doing all the heavy lifting to expose the paths to these build artifacts to dependent crates so they can pick them up and use them. I can kinda coerce the existing |
I probably need this functionality for a crate that doesn't depend on any native library. So I'm likely to go ahead and set This is almost surely not going to conflict with any native library. It's not great, but I'll put a comment back to this issue explaining the rationale. |
I need this, too. I think it can be helpful to just kind of expose |
My team and I could also use the functionality described in this issue. I just wanted to chime in on it too and voice support. For now, we're utilizing one of a couple possible workarounds, but we're all trying to learn the idioms and best practices of the Rust community. |
I'm another person with a similar use case (see: https://boringssl-review.googlesource.com/c/boringssl/+/63305). I'd be more than happy to do some of the leg work to make this happen, what would the next step be there? Does this require an RFC, or just a design + PR? |
From the BoringSSL side, lifting the constraint would improve things, but I think a better design would be something that depends less on In C, it is common and straightforward for packages to communicate to their users by exposing
This way a package can be compatible with a wider range of OpenSSL versions, which in turn makes consuming that package easier for its users. Rust, from what I can tell, has no good way to do this. Now, Rust is much better at multiple-linking than C, so there's a lot more breathing room when this is missing, but it's still better to avoid multiple-linking when you can. (Binary size, types that leak through the public API, general supply chain security issues around how many packages worth of security bugs you're exposed to.) And so it is useful to be able to adapt your code to what version of the package is ultimately resolved. Lifting this special-case on For example, perhaps a way for a Rust crate to export |
@davidben there is rust-lang/rust#64797 though I think I heard they are wanting to start it with just |
I use the same k8s-openapi supports multiple features like So k8s-openapi's build.rs emits The alternative is that each such library exports its own version features that map one-to-one with the corresponding k8s-openapi features. This is busywork, especially when the chain of such crates is multiple crates long, or when a crate wants to match on a range of versions (eg all versions below 1.25). The latter would require reimplementing
|
I wonder if https://internals.rust-lang.org/t/pre-rfc-mutually-excusive-global-features/19618 could help here.
Those sound like breaking changes which would imply controlling them with either system isn't a good fit. |
As it is specified, no. Since the global values are limited to enums, it still has the problem of reimplementing
I don't understand what you mean. |
Oh, interesting. I guess I would call that unrelated mechanism for addressing a very related problem. But as long as it solves the problem, I'm happy. 😄 Tying it to symbol accessibility is interesting, but would work. Crates could define random constants that don't do anything useful, but are meant to be used with I share @Arnavion's concern that But even booleans that don't require |
Oh, good point. This would also work k8s-openapi's case, eg enabling So the lack of integers would be the only problem. |
Integer support is in the future possibilities. |
I know. I understood "Future possibilities" to mean "not going to be in the RFC and initial implementation", so as it's currently specified it does not support integers. |
That is correct but the point more is that it has the potential for covering the case and it would be good to give feedback based on that possibility to see if it is going in the right direction or not. |
This is currently done by duplicating the list of constants. This was done for two reasons: 1) bindgen doesn't seem to do anything with bare-defines, 2) the list of defines appears to change incredibly rarely. The `links` key is required in `Cargo.toml` to work around rust-lang/cargo#3544 Change-Id: I11dca6e7eb62ab1b04053df654a4061cb5e25723 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/63305 Reviewed-by: David Benjamin <davidben@google.com> Commit-Queue: David Benjamin <davidben@google.com>
Would it make sense to allow usage of
DEP_<name>_<key
environment variables in abuild.rs
for dependencies that do not link to native libraries?Context: I would like to allow crates like this one to expose Cap'n Proto schema definitions, and in particular to allow Cap'n Proto's import mechanism to work across crate boundaries. (See capnproto/capnpc-rust#30.)
For example, say I write a
my_app
crate that depends on thesandstorm
crate, and I wantmy_app
to have some capnp schemas that import from thesandstorm
schemas. For this to work, themy_app
build.rs
needs to know where to find the source code of thesandstorm
schemas. One way to accomplish that would be for thesandstorm
crate'sbuild.rs
to write its current working directory to aDEP_SANDSTORM_IMPORT
environment variable, through the mechanism described here. However, that only works if thesandstorm
crate has a "links" field in itsCargo.toml
. Since thesandstorm
crate does not actually need to link to a native library, adding such a field feels superfluous and possibly prone to mysterious bugs.The text was updated successfully, but these errors were encountered: