-
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
Platform target-specific features #1197
Comments
cc @huonw |
Shouldn't this work? [target.'cfg(not(any(target_os = "android", target_os = "windows")))'.dependencies]
ipc-channel = {git = "https://github.com/servo/ipc-channel"}
[target.'cfg(any(target_os = "android", target_os = "windows"))'.dependencies]
ipc-channel = {git = "https://github.com/servo/ipc-channel", features = ["inprocess"]} |
@nox in theory yeah that seems like it should work, but today due to the structure of I think that's a fixable bug, however, although likely quite invasive as it would require deferring calculation of features to the compilation phase rather than the resolution phase. |
This reverts commit a1b6926. See rust-lang/cargo#1197 (comment)
Revert "Introduce an inprocess feature" This reverts commit a1b6926. See rust-lang/cargo#1197 (comment)
Ran into this extremely confusing bug today... |
Would this also allow specifying a target-specific [target.'cfg(not(target_os = "windows"))'.features]
default = ["general_feature"]
[target.'cfg(target_os = "windows")'.features]
default = ["winonly_replacement"] I suppose a workaround to get this would be an intermediate crate which depends on the actual crate with target-dependent features, but it doesn't sound very convenient. |
@gyscos that seems like a nifty and natural way to encode this information! I haven't though too much about the implications of target-specific features, but I don't particularly see any immediate reason to block anything. |
This isn't enough, I don't want my crate to stop working because someone used I guess one could use @retep998's trick of enabling a feature programatically from a |
@nox That enables features in code programmatically. It doesn't let me control dependencies, but for some people just controlling their code might be enough. The reason I even wrote that trick was due to the lack of support for cyclic features. https://github.com/retep998/winapi-rs/blob/dev/build.rs#L193 |
What's the status of this issue? It would be interesting to use target-specific features in gecko-media (enable pulseaudio only for linux for instance). |
@philn AFAIK no progress has been made |
Hope we can see progress on this issue... |
Unfortunately I'm not very familiar with all the different "defalt backend" use cases out there, but for the Wgpu use-case I described in #1197 (comment) "global, mutually exclusive" features wouldn't solve the problem (AFAIU). |
Why is that? Backends are a top-level concern so it seems like something that should be set using globals, rather than features which are for direct dependents and unified. |
This is true and would also be a good fit for Wgpu but addresses a different problem. Taking from #1197 (comment) Wgpu needs:
Specifically the proposal mentions but leaves out:
Maybe I didn't understand the proposal well enough or missed something? On second thought: maybe I misunderstood your earlier comment and you meant to say that this problem should rather be solved by "global, mutually exclusive features" because these use-cases should move away from crate features anyway? |
Are those for cases that should be controlled by the direct dependent or the final artifact?
|
They should be controlled by the final artifact. |
Haven't read the whole thread, but this is my use case: I am building a cross platform GUI library (nuit) and would like to provide both a smooth experience for library consumers that "just want sensible defaults" (e.g. SwiftUI on macOS, GTK+ on Linux, ...), while simultaneously offering the flexibility to select a custom backend. Since backends may be supported on multiple platforms (e.g. GTK+ runs on macOS too), I don't think this can cleanly be modeled with the What I would really like to write would be something along the lines of [target.'cfg(target_os = "macos")'.features]
default = ["swiftui"]
[target.'cfg(target_os = "linux")'.features]
default = ["gtk"] which is very close to the existing suggestions from this thread. The other workaround would be introducing wrapper crates for each backend and using the existing target-specific dependency mechanism, but that still feels like an artificial restriction over something that could be expressed a lot more cleanly and concisely. |
Twiddle our crates and Cargo configuration for activating jemalloc to achieve the following ideal developer experience: * --no-default-features unequivocally disables jemalloc, regardless of platform. * --features=jemalloc unequivocally enables jemalloc, regardless of platform. * --default-features chooses the best allocator for the platform: the system allocator on macOS and jemalloc on Linux. Since Cargo doesn't explicitly support target-specific features, the trick is to introduce a crate of indirection, as described in [0]. Here's how it works: * The `mz-prof`, `mz-prof-http`, and `mz-alloc` crates have a straightforward setup: they expose a `jemalloc` feature and conditionally enable or disable jemalloc features based on whether the `jemalloc` feature is provided or not. * The `mz-alloc-default` crate depends on the `mz-alloc` crate and enables the best features for the platform: `jemalloc` on Linux, and no additional features on macOS. You can think of this crate as unconditionally enabling the best allocator for the platform. * The `mz-environmentd` and `mz-clusterd` crates unlock the conditional behavior. Bothc crates: 1. depend on `mz-alloc-default` by default, and 2. expose a `jemalloc` feature that force enables the `mz-alloc/jemalloc` feature. The motivation for all of this is to allow macOS developers to enable jemalloc upon request, which is useful for certain kinds of testing. Alternative to MaterializeInc#27041. Closes MaterializeInc#27041. [0]: rust-lang/cargo#1197 (comment)
Twiddle our crates and Cargo configuration for activating jemalloc to achieve the following ideal developer experience: * --no-default-features unequivocally disables jemalloc, regardless of platform. * --features=jemalloc unequivocally enables jemalloc, regardless of platform. * --default-features chooses the best allocator for the platform: the system allocator on macOS and jemalloc on Linux. Since Cargo doesn't explicitly support target-specific features, the trick is to introduce a crate of indirection, as described in [0]. Here's how it works: * The `mz-prof`, `mz-prof-http`, and `mz-alloc` crates have a straightforward setup: they expose a `jemalloc` feature and conditionally enable or disable jemalloc features based on whether the `jemalloc` feature is provided or not. * The `mz-alloc-default` crate depends on the `mz-alloc` crate and enables the best features for the platform: `jemalloc` on Linux, and no additional features on macOS. You can think of this crate as unconditionally enabling the best allocator for the platform. * The `mz-environmentd` and `mz-clusterd` crates unlock the conditional behavior. Bothc crates: 1. depend on `mz-alloc-default` by default, and 2. expose a `jemalloc` feature that force enables the `mz-alloc/jemalloc` feature. The motivation for all of this is to allow macOS developers to enable jemalloc upon request, which is useful for certain kinds of testing. Alternative to MaterializeInc#27041. Closes MaterializeInc#27041. [0]: rust-lang/cargo#1197 (comment)
It would be nice to support target-specific features for cases such as when certain functionality is only available on one platform or the default set of functionality should vary per-platform.
The text was updated successfully, but these errors were encountered: