我正在編寫一個跨平臺的庫,它具有特定於平臺的依賴關係,一個用於類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 = "*"
您可以更改下面的接受的答案?目前接受的答案的作者也同意 – hansaplast