You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A-featuresArea: features — conditional compilationE-hardExperience: HardS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
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.
Reacted by Kornel, Sunny Huang, Iban Eguia Moraza, arturo, LifeIsStrange, James Tucker, swsnr, Evgenii Pashkin, Dmitry Timofeev, konsti and 281 more
Reacted by Arve Knudsen, Brian Cook, Zicklag, Mathieu Tarral, Dmitry Patsura, Renato Caldas, Jonas, Felicitas Pojtinger, Dylan Perks, Pēteris Pakalns and 34 more
Reacted by Leslie Zhai, Leonz, Michael Kirk, musjj, Jay Sistar, Suraj, windseeker, xkeyC and Tianlan Zhou
@nox in theory yeah that seems like it should work, but today due to the structure of Resolve it doesn't. The entire target-independent resolution graph is created and then only later filtered down to the relevant set of packages. As an artifact of creating Resolve at the beginning it resolves all features, basically with a map from package to list of features. That means that all instances of ipc-channel in your example would have the inprocess feature enabled, regardless of what platform it was on.
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.
Reacted by Arve Knudsen, Michael K, Matthias Fauconneau, Georgios Konstantopoulos, Vlad Frolov, Stephen Chung, Jesus Guzman, Jr., Kirill Alexander Khalitov, Arne Christian Beer, Daira-Emma Hopwood and 6 more
Reacted by Arve Knudsen, Richard Whitehouse, Dabo, Erik, Jacob Halsey, Richard, ⭐️NINIKA⭐️, Florian Bruder, Stephen Chung, Jesus Guzman, Jr. and 10 more
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.
Reacted by Robert Wallis, Jiachen Yang, MOZGIII, Iohann Rabeson, Naja Melan, Drew Pirrone-Brusse, DzmitryFil, Roy Ivy III, Chris Vest, Anton Lazarev and 64 more
@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.
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).
Reacted by Arve Knudsen, Erik, Richard, Dmitry Savintsev, Florian Bruder, Jesus Guzman, Jr., Arne Christian Beer, Js2xxx, Kivimango, Karel Hrkal and 1 more
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.
Multi-valued globals, which Wgpu could probably live without, but would still introduce some complexity, having to play around with multiple globals that do the same thing depending on the target or if using the default.
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?
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 winit workaround of enabling all backends by default and making them a no-op on unsupported platforms, since that would e.g. always result in GTK+ libraries being pulled in on macOS.
What I would really like to write would be something along the lines of
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.
Reacted by Florian Bruder, Jonas, Ellen Emilia Anna Zscheile, widberg, Diana, ♫ Christian Krause ♫, José Luis Cruz, Abhi Pandya, n4n5, Ben Bass and 15 more
I just run into this with [build-dependencies].
tonic-build/transport is required for non-WASM but must not be enabled for WASM or it generates code that doesn't compile
The net feature on tokio is only being used when the terminal feature of the current crate is selected, and only on unix targets.
Reacted by MOZGIII, Ellen Emilia Anna Zscheile, Tobias Berger, Peter Atashian, ottergauze, Diana, cloudgazing, Chris, Dannii Willis, WhyAreAllTheseTaken and 2 more
My usecase (and it looks like the use case in several issues on various projects that link to this), is I would like to enable using jemalloc by default on platforms where it is easy to build, but optional on other platforms, so that it can still be compiled with jemalloc if the user has jemalloc set up, but won't try by default, when it is likely to fail.
The current options I see are:
Make the tikv-jemallocator dep always optional, and users must opt-in to using it, regardless of platform
Use target.cfg(...).dependencies to only add the dependency for some platforms. But then platforms that don't match can't use jemalloc, even if they want to. (this is what fd currently does, but see https://github.com/sharkdp/fd/issues/1822}.
Always include jemalloc in the default features, and on platforms where building jemalloc is more difficult, the user must opt out by not using the default features.
A-featuresArea: features — conditional compilationE-hardExperience: HardS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Activity
alexcrichton commentedon Jan 20, 2015
cc @huonw
nox commentedon Jul 10, 2016
Shouldn't this work?
alexcrichton commentedon Jul 11, 2016
@nox in theory yeah that seems like it should work, but today due to the structure of
Resolveit doesn't. The entire target-independent resolution graph is created and then only later filtered down to the relevant set of packages. As an artifact of creatingResolveat the beginning it resolves all features, basically with a map from package to list of features. That means that all instances ofipc-channelin your example would have theinprocessfeature enabled, regardless of what platform it was on.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.
Revert "Introduce an inprocess feature"
Auto merge of #87 - nox:dumb-down, r=Ms2ger
jethrogb commentedon Nov 5, 2016
Ran into this extremely confusing bug today...
gyscos commentedon Dec 20, 2016
Would this also allow specifying a target-specific
features.defaultarray?Something like:
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.
alexcrichton commentedon Dec 20, 2016
@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.
nox commentedon Mar 4, 2017
This isn't enough, I don't want my crate to stop working because someone used
no-default-features.I guess one could use @retep998's trick of enabling a feature programatically from a
build.rsscript.retep998 commentedon Mar 4, 2017
@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
philn commentedon Oct 18, 2017
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).
alexcrichton commentedon Oct 18, 2017
@philn AFAIK no progress has been made
praetp commentedon May 3, 2018
Hope we can see progress on this issue...
huangjj27 commentedon May 12, 2018
This will help a lot with rust-random/rand#442
105 remaining items
daxpedda commentedon Feb 14, 2024
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:
set-globals, which would have to play well with default as well.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?
epage commentedon Feb 14, 2024
Are those for cases that should be controlled by the direct dependent or the final artifact?
daxpedda commentedon Feb 14, 2024
They should be controlled by the final artifact.
I will make a post there, thanks!
fwcd commentedon Apr 23, 2024
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
winitworkaround of enabling all backends by default and making them a no-op on unsupported platforms, since that would e.g. always result in GTK+ libraries being pulled in on macOS.What I would really like to write would be something along the lines of
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.
Allow force enabling jemalloc on macOS
Allow force enabling jemalloc on macOS
Only reference udisks2 when udev + linux
zoechi commentedon Apr 30, 2025
I just run into this with [build-dependencies].
tonic-build/transport is required for non-WASM but must not be enabled for WASM or it generates code that doesn't compile
teohhanhui commentedon Jul 24, 2025
The workarounds mentioned so far don't cover the use case of:
Whew... What a mouthful.
Example (current):
Example (wanted):
The
netfeature ontokiois only being used when theterminalfeature of the current crate is selected, and only onunixtargets.tmccombs commentedon Nov 4, 2025
My usecase (and it looks like the use case in several issues on various projects that link to this), is I would like to enable using jemalloc by default on platforms where it is easy to build, but optional on other platforms, so that it can still be compiled with jemalloc if the user has jemalloc set up, but won't try by default, when it is likely to fail.
The current options I see are:
target.cfg(...).dependenciesto only add the dependency for some platforms. But then platforms that don't match can't use jemalloc, even if they want to. (this is what fd currently does, but see https://github.com/sharkdp/fd/issues/1822}.None of these options are very good.
epage commentedon Nov 4, 2025
I feel like features aren't quite the right solution to this problem and that it should likely be solved as part of https://internals.rust-lang.org/t/pre-rfc-mutually-excusive-global-features/19618 or as a follow up afterwards.
Revert "Introduce an inprocess feature"
Auto merge of #87 - nox:dumb-down, r=Ms2ger