Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rust cargo: how to use different features for a dep when a particular feature is enabled?

For example I define 2 features without dependencies:

[features]
default = []
py2 = []
py3 = []

Based on selected feature (--features py3) I want to enable different features for a dependency (cpython):

[dependencies.cpython]
default-features = false
# features = ["python27-sys"]      I want to select this if py2 is enabled
features = ["python3-sys"]
optional = true

Can I do this? Or simply can I select features for a dependency from command line as well?

like image 490
Sergey Avatar asked Jan 03 '17 09:01

Sergey


People also ask

How do you use unstable features in Rust?

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.

What is features in Cargo TOML?

Cargo "features" provide a mechanism to express conditional compilation and optional dependencies. A package defines a set of named features in the [features] table of Cargo. toml , and each feature can either be enabled or disabled.


1 Answers

It was discussed here. One can do it with /.

[features]
default = []
py2 = ["cpython", "cpython/python27-sys"]
py3 = ["cpython", "cpython/python3-sys"]
unstable = []

[dependencies.cpython]
# git = "https://github.com/dgrunwald/rust-cpython.git"
default-features = false
optional = true

I've seen nothing about it in documentation or official pages.

like image 63
Sergey Avatar answered Nov 15 '22 08:11

Sergey