我正在编写一个具有特定于平台的依赖项的跨平台库,一个用于类似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 = "*"