-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add cfg for crate_type? #45182
Comments
It is possible to set multiple crate types at once and get artifacts for all of them in one compilation session. That makes it kind of difficult to provide a single |
Yeah, I think that'd work. Something like In my particular use case, I'd probably need to ensure that only a single artifact was generated at a time by doing something like: #[cfg(all(crate_type = "cdylib", any(crate_type = "staticlib", ...)))]
compile_fail!(...); But yeah that'd work for me. |
Interestingly, that would not be useful in some use cases. Specifically, I was looking at building a crate as both a cdylib and staticlib today, and needed both to export a function under a different name... I tried |
Why don't we just allow a cargo package to have multiple |
My concern would be that it'd require publishing the common crate which
would need to expose internal functionality in order to be used by the
cdylib and staticlib crates. You might not want to actually publish that
stuff.
…On Thu, Mar 1, 2018 at 4:06 PM, Peter Atashian ***@***.***> wrote:
Why don't we just allow a cargo package to have multiple cdylib and
staticlib crates distinct from the primary library crate? Then you could
just put all the common stuff in the library crate and the cdylib/
staticlib crates would have the stuff specific to them, so you wouldn't
have to cfg based on how the crate is being built.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#45182 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA_2L_NeXfnIEpdugDA0fMuBJG3XAdo0ks5taIzqgaJpZM4P0Yyz>
.
|
Ah, but you could have a shared module. Two separate crates can both include the same module, and that could define the common private functionality. |
How can two separate crates share a module? |
Ah! |
I'm going to loosely say this is probably RFC-worthy territory and close this issue (it's definitely not a rustbuild bug). |
I have some code that needs to be conditionally compiled only when the artifact that's being produced is a dynamic library, and the target platform is Mac (here's the code). Right now, I'm accomplishing that by providing a
dylib
feature that the crate's user is responsible for enabling if they're compiling a dynamic library.This is ugly from a UX perspective, and introduces the possibility of bugs if the user fails to enable the feature when they should. It'd be better if there were a
cfg
setting that indicated the value of thecrate_type
so I could do this automatically without user help.The text was updated successfully, but these errors were encountered: