切换可选构建依赖项和使用功能构建依赖项
Toggle optional build dependencies and build dependencies using features
我知道 Rust 允许您在 Cargo.toml 清单中指定可选的依赖项,并且您可以使用功能触发这些依赖项。例如:
[dependencies]
foo = "1.0"
bar = "1.0"
[features]
myfeature = ["foo", "bar"]
我想知道是否有办法让我也将其应用于构建依赖项,因为我没有找到任何文档表明这是可能的。
我想做的是:
[dependencies]
foo = "1.0"
[build-dependencies]
bar = "1.0"
[features]
myfeature = ["foo", "bar"]
上下文是我想将 build-info and build-info-build crates 添加到我的项目中,但它大大增加了编译时间,所以我想要一个功能并且只在发布时启用它构建。
事实证明这行得通,我的错误是使功能名称与其中一个板条箱相同,例如:如果您有
[dependencies]
foo = "1.0"
[build-dependencies]
bar = "1.0"
[features]
foo = ["foo", "bar"]
这似乎不起作用。使用不同的名称它工作正常。
我知道 Rust 允许您在 Cargo.toml 清单中指定可选的依赖项,并且您可以使用功能触发这些依赖项。例如:
[dependencies]
foo = "1.0"
bar = "1.0"
[features]
myfeature = ["foo", "bar"]
我想知道是否有办法让我也将其应用于构建依赖项,因为我没有找到任何文档表明这是可能的。
我想做的是:
[dependencies]
foo = "1.0"
[build-dependencies]
bar = "1.0"
[features]
myfeature = ["foo", "bar"]
上下文是我想将 build-info and build-info-build crates 添加到我的项目中,但它大大增加了编译时间,所以我想要一个功能并且只在发布时启用它构建。
事实证明这行得通,我的错误是使功能名称与其中一个板条箱相同,例如:如果您有
[dependencies]
foo = "1.0"
[build-dependencies]
bar = "1.0"
[features]
foo = ["foo", "bar"]
这似乎不起作用。使用不同的名称它工作正常。