-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
flag for cargo add
to add platform specific dependencies
#11720
Comments
--cfg
option for adding platform specific dependenciescargo add
to add platform specific dependencies
@rustbot claim |
@akabinds FYI this has not been marked as Accepted and there are likely things still left to resolve, like what the flag should be called. Starting on this now might lead to extra churn during review as we settle those kind of questions. |
I understand. I just wanted to claim it because I want to implement it if it is accepted. But, I had a quick question. I was looking around the code base for relevant code to help implement this. I found that this feature seems to already have tests in the test suite using the existing cargo/tests/testsuite/cargo_add/target_cfg/mod.rs Lines 8 to 25 in a66f123
But, when attempting to add platform-specific dependencies this way in my own project to test, it seems to not work. Has this been implemented already, but not present in a release? |
Huh, I thought we had this; I should have checked rather than assuming the issue author hadn't missed it.
Could you provide more details as to what didn't work? |
My shell was giving me an obscure error after running it. It seems like all I had to do was wrap the
If I did I'm not sure if this workaround is needed on other shells or if this is even an issue on other shells. |
I believe different shells have different ways to escape things. If that works for you, seems like this issue is not really an issue as cargo-add already supports that? |
Indeed. But should it not be at least documented that quotations might be needed based on the shell? |
That gets into an interesting line of how much do we document how to use each users system vs users knowing it being an expectation in using cargo. |
It helps. However, there may be more flags needing that hint. If we start doing so, does that imply we require all possible flags having that hint for consistency? Personally I would probably avoid that. We do have $ cargo build --bin *
error: unexpected argument 'CODE_OF_CONDUCT.md' found
Usage: cargo build [OPTIONS]
For more information, try '--help'.
$ cargo add tokio --target cfg(windows)
bash: syntax error near unexpected token `(' To me, even the hint in |
Problem
Currently, there is no support for adding platform specific dependencies (such as
[target.'cfg(windows)'.dependencies]
) usingcargo add
.Proposed Solution
Add a
--cfg
option that allows the user to specify the whole desiredcfg
predicate.Examples:
cargo add windows --cfg windows
cargo add raw_cpuid --cfg any(target_arch = "x86", target_arch = "x86_64")
Notes
cfg
dependency specifications only are supported using platform predicates, one might think that the option should be named differently. But, in case othercfg
pairs/options become supported in the future, the name of the flag allows for it to also include those without confusion for its name being named after the fact it specifies platform specific dependencies only.The text was updated successfully, but these errors were encountered: