我正在编写一个跨平台的库,它具有特定于平台的依赖关系,一个用于类似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 = "*"
Run Code Online (Sandbox Code Playgroud)
但是,这份清单远非详尽无遗.我不关心架构或ABI,只关心OS系列,因此,列表会变得很长,我是否匹配每个类似unix的目标三元组.
是否有任何方法可以使用特定的依赖关系,仅由平台货运的OS系列确定运行?就像是:
[target.family.unix.dependencies]
abc-sys = "*"
def = "*"
[target.family.windows.dependencies]
abc-win = "*"
Run Code Online (Sandbox Code Playgroud) 我尝试在Mac OS X 10.11.2上为Rust安装Iron框架,但是当我运行cargo build或cargo run编译时它失败了openssl:
failed to run custom build command for `openssl-sys-extras v0.7.4`
Process didn't exit successfully: `/xxx/rust/hello/target/debug/build/openssl-sys-extras-413d6c73b37a590d/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
TARGET = Some("x86_64-apple-darwin")
debug=true opt-level=0
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CC_x86_64-apple-darwin = None
CC_x86_64_apple_darwin = None
HOST_CC = None
CC = None
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CFLAGS_x86_64-apple-darwin = …Run Code Online (Sandbox Code Playgroud)