Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable crate features per-platform in Cargo.toml?

How do I enable crate features per-platform in a Cargo.toml configuration? I've tried two methods, neither of which work.

Method 1:

[target.'cfg(windows)'.dependencies.rusqlite]
version = "0.19.0"
features = ["bundled"]

[target.'cfg(unix)'.dependencies.rusqlite] # same behavior with cfg(not(windows))
version = "0.19.0"

Method 2:

[target.'cfg(windows)'.dependencies]
rusqlite = { version = "0.19.0", features = ["bundled"] }

[target.'cfg(unix)'.dependencies]
rusqlite = { version = "0.19.0" }

I'm trying to use the 'bundled' feature only on Windows platforms, but regardless of which way I try to configure cargo it always adds the 'bundled' feature when building on an Ubuntu system.

Is it possible to enable features only on one platform?

like image 631
Nick Avatar asked Jul 05 '19 19:07

Nick


People also ask

How do you use unstable Rust features?

These features are enabled by passing a command-line flag to Rustdoc, but the flags in question are themselves marked as unstable. To use any of these options, pass -Z unstable-options as well as the flag in question to Rustdoc on the command-line.

Where do you put cargo in toml?

Cargo. toml and Cargo. lock are stored in the root of your project (package root). Source code goes in the src directory.


1 Answers

Is it possible to enable features only on one platform?

No, it is not possible, due to Cargo issue #1197.

See also:

  • How can I optionally pass rustc flags depending on a Cargo feature?
like image 75
Shepmaster Avatar answered Nov 15 '22 09:11

Shepmaster