2015-04-24 111 views
11

我正在编写一个跨平台的库,它具有特定于平台的依赖关系,一个用于类Unix平台,另一个用于Windows。这些箱子只能在特定的平台上编译,因此我不能在通常的依赖下将它们全部添加。如何根据操作系统族具有不同的依赖关系

在实际生锈的代码,我用cfg属性,如#[cfg(unix)]编译某些代码的某些平台,我想要做的Cargo.toml相似,或在构建脚本什么的,为的依赖关系。目前,我正在使用如下所示的目标三元组:

[target.i686-unknown-linux-gnu.dependencies.crate1] 
git = repo1 
[target.x86-unknown-linux-gnu.dependencies.crate1] 
git = repo1 
[target.x86_64-unknown-linux-gnu.dependencies.crate1] 
git = repo1 

[target.i686-pc-windows-gnu.dependencies] 
crate2 = "*" 
[target.x86-pc-windows-gnu.dependencies] 
crate2 = "*" 
[target.x86_64-pc-windows-gnu.dependencies] 
crate2 = "*" 

但是,此列表并非详尽无遗。我不关心体系结构或ABI,也不关心OS系列,因此,这个列表会变得很长,我是否会为每一个类似unix的目标三元组进行匹配。

有没有什么方法可以使用特定的依赖关系,仅由运行平台的OS系列操作系统决定?例如:

[target.family.unix.dependencies] 
abc-sys = "*" 
def = "*" 

[target.family.windows.dependencies] 
abc-win = "*" 
+0

您可以更改下面的接受的答案?目前接受的答案的作者也同意 – hansaplast

回答

10

至于我阅读文档here,这应该现在的工作:

[target.'cfg(unix)'.dependencies] 
abc-sys = "*" 
def = "*" 

[target.'cfg(windows)'.dependencies] 
abc-win = "*" 
+2

是的,现在是这样。我的回答很老,现在不准确。 –

0

目前没有办法做到这一点。当然会很好。

+0

这个答案现在已经过时了。请参阅** @ Andrew Straw **的回答。 – Toothbrush

相关问题