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
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... |
I disagree, it is in line with the target specific dependency declaration so imho it's consistent.
Good catch! Couldn't this be solved by an impl detail to check if a feature exists at all before checking if it exists for the current target, and show a sufficiently detailed error message? Iiuc that would be equal to an explicit buildable flag. Could you reference where this is outlined? Thanks! |
I dont think that is true. We can already request optional dependencies (which are features) form another platform to be included, and this works on stable. I think my implementation also has a similar behaviour to these dependencies. On targets where the features dont exist, they are just ignored/are empty.
That would require the users to select the features, I want to give the user one stable API on diferent platforms without the users having to ask for a diferent feature on each platform. |
Requesting conditionally is perfectly fine. It's providing features optionally to downstream creates conditionally that's suspicious.
That is what the conditional default features do. Isn't that what you want?
That somewhat works, but i don't think is as clean. What we want to express is "Foo depends on macOS or Linux", not "If mac or linux exists there is a Foo". I think the framing really matters as to what users end up writing and how they feel about it.
https://cabal.readthedocs.io/en/3.4/cabal-package.html?highlight=buildable%3A#pkg-field-buildable. The docs mention it in conjunction with an autoconf-ish setup, but it is more commonly used these days just with regular conditional deps, such as in https://github.com/reflex-frp/reflex-dom/blob/master/reflex-dom/reflex-dom.cabal (which incidentally I think is pretty close to @JAicewizard's use-case). |
I dont think you understand what I mean. Currently we can already provide features that are target specific.
|
@JAicewizard can a downstream create refer to I agree in that this is no good, but if it doesn't like into the crate's public (cargo-side) interface, then it is at least local and could be fixed with an edition. |
@Ericson2314 Yes, if you are on a target with no explicitly listed dependency with that name it will just ignore it. At least from my testing. |
@JAicewizard say that again? In downstream crates I would expect trying to refer to any dependency in an upstream crate (that doesn't share a name with a feature in which case we are referring to the feature) to be an error, not silently ignored. I take it you mean within the same crate declaring the target-specific dependency? |
I believe I have a use-case for this. I am working on a cross-platform tool that needs to interact with a USB device. I use libusb via rusb to achieve the majority of the abstraction. On Windows, I need a special, patched version of libusb to get around a limitation. I therefore enable the My dependencies are as follows: [workspace]
[package]
# ...
edition = "2018"
[dependencies]
rusb = "0.8.1"
# ...
[target.'cfg(windows)'.dependencies]
libc = "0.2"
windows = "0.17.2"
win32_bindings = { path = "src/backend/windows/win32_bindings" }
libusb_internals = { path = "src/backend/windows/libusb_internals" where [dependencies]
libusb1-sys = { version = "0.5.0", features = ["vendored"] }
win32_bindings = { path = "../win32_bindings" }
[build-dependencies]
cc = "1.0" On other platforms, I would rather dynamically link libusb, however, the "vendored" feature appears to be picked up and libusb is being built. I also see This leaves me at an impasse where it seems impossible to configure my project correctly for multiple target platforms. |
Somewhat related: Here's an example: I have an codebase I build for WebAssembly and as a native binary. In the latter case I use the |
@kaimast Are you using Rust 2021 and / or resolver 2? This should not be happening if either of those are the case. (Unless of course a crate legitimately pulled in by WASM does indeed activate that feature) Although wait, what do you even mean? getrandom does support WASM, you actually need to activate a feature for it to work, not vice versa. |
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: