我想使用Cargo的cfg
进行条件编译我的源代码,
在谷歌上搜索了一段时间后,
似乎解决方法是使用cargo --features
。
http://doc.crates.io/manifest.html
我尝试添加了几个
#[cfg(feature = "foo")]
在源代码中。cargo build --features foo
但是它说
Package `xxx v0.0.1 (file:///C:/yyy/xxx)` does not have these features: `foo`
我该如何让Cargo识别这些特性呢?我需要在Cargo.toml
文件中添加什么吗?
这是我正在使用的rustc
和cargo
版本:
C:\>rustc --version
rustc 0.13.0-nightly (42deaa5e4 2014-12-16 17:51:23 +0000)
C:\>cargo --version
cargo 0.0.1-pre-nightly (5af754d 2014-12-18 01:50:48 +0000)
if cfg!(feature = "customfeature") { ... }
。 - Pauan