-
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
Allow specifying a set of supported target platforms in Cargo.toml #6179
Comments
This seems plausible to me! Cargo has to execute rustc to learn about cfg information for targets, so that may be one roadblock to getting this working but otherwise I think it in theory shouldn't be too too hard to plumb through what we've got today |
Similarly, it seems like you could also plumb through the set of features with which each library will be built, so that there's no need to pull in optional dependencies. |
I poked around that a bit and that already seems to work. If you have a dependency on crate |
cc @Eh2406, we were just talking about this! We talked a bit in person about this and envisioned something like:
We've already basically got the support for all of this, it'd just need some wiring up and stabilization! |
I had another use-case for this #8645
@alexcrichton I don't understand why this should be bound to workspaces though? Wouldn't this make sense for any crate? |
Another idea is to declare something like |
This would help a problem we have in Firefox, where some of the dependencies may have WASM-specific dependencies (https://github.com/grovesNL/glow), which are dragged into the 3rd party sources by |
I've just recently hit on a circumstance where this functionality would be very useful: preventing cargo (and vendoring by extension) from pulling in crates that will never be built on the intended target. Or at least that would be my hope. An example is that I build and maintain a particular project, and this project has many dependencies. Various of these dependencies have However! My hope for this issue is that by specifying a a target that the crate is for it would prevent the above scenario by never resolving the windows target. With a default of no target specified defaulting back to current behaviour. |
Just came here from #5220, which was closed in favor of this issue. Do the supported targets need to be workspace-wide (as suggested by the initial comment here), or could they apply crate-by-crate? Currently e.g. https://github.com/sportsball-ai/av-rs has one workspace with some crates that are portable, some that are macOS-only, and some that are Linux-only. I was following #5220 because I was hoping to be able to just have |
My expectation is we'd have something like [package]
name = "cargo-credential-macos-keychain"
# ...
required-targets = [
"aarch64-apple-darwin",
"aarch64-apple-ios",
"aarch64-apple-ios-sim",
"x86_64-apple-darwin",
"x86_64-apple-ios",
]
|
btw there is #9208 for doing this on the build-target / crate level |
We open sourced a tool that allows you to specify the supported targets of a crate in the |
Ergonomically specifying that a crate is Wasm-incompatible would require both this and That feature would be most welcome since Wasm-incompatible crates often build but fail at runtime in ways that aren't obviously a platform incompatibility — in the case of |
I'm looking forward to <rust-lang/cargo#6179>; making an entire crate empty or not based on platform is an awkward workaround.
* test and fix logging callback * `cstr` import * test `xcoder-*-sys` crates on CI * satisfy clippy * gate xcoder tests behind target_os linux I'm looking forward to <rust-lang/cargo#6179>; making an entire crate empty or not based on platform is an awkward workaround.
As this is an issue I regularly run into while maintaining a Linux-only application built for a specific embedded device, and vendoring its dependencies - what's the current state of this issue? I've recently started contributing to clippy, and would be willing to contribute on this issue as well. Would someone in the cargo team be interested in being a little bit of a mentor, so I can move this issue forward? |
The next step for this is likely be shopping around a Pre-RFC for getting some in-the-small feedback before posting an RFC. While I know a lot of people are interested in this for Some considerations that build off of my previous comment at #6179 (comment) In just having the field,
Risks:
In using the field during resolution
Risks:
|
Spun off from the specific proposal in #4544 (comment)
"A random solution which may help solve this though is to perhaps list the valid targets for a project in a workspace root Cargo.toml. That way Cargo could be smarter and just vendor dependencies for those targets (and alter resolution so it won't include winapi in the lock file)"
This would help projects like Firefox and Fuchsia that vendor their dependencies by allowing them to avoid vendoring crates that are only necessary for platforms that the project does not support (see also #7058).
cc @cramertj
See also
The text was updated successfully, but these errors were encountered: