我正在编写一个跨平台库,它具有特定于平台的依赖关系,一个用于类 UNIX 平台,一个用于 Windows。这些板条箱仅在特定平台上编译,因此我不能正常地将它们全部添加到依赖项下。
在我实际使用的 Rust 代码中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,只关心操作系统系列,因此,如果我要匹配每个类似 UNIX 的目标三元组,列表会变得很长。
有没有办法使用特定的依赖项,仅由运行货物的平台的操作系统系列决定?就像是:
[target.family.unix.dependencies]
abc-sys = "*"
def = "*"
[target.family.windows.dependencies]
abc-win = "*"
据我阅读文档here https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#platform-specific-dependencies,现在应该可以工作:
[target.'cfg(unix)'.dependencies]
abc-sys = "*"
def = "*"
[target.'cfg(windows)'.dependencies]
abc-win = "*"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)