cargo 解決git依賴私庫辦法

Rust實際場景,不僅需要依賴https://crates.io/的公共mod,自己依賴的git私庫服務(wù)也是常見現(xiàn)象。
cargo正好也解決了私庫依賴的問題。詳細(xì)說明見鏈接:
https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories

image.png

cargo git私庫解決辦法

    1. 添加.ssh/config配置
Host *
   UseKeychain yes
   AddKeysToAgent yes
   IdentityFile ~/.ssh/id_rsa
    1. 指定私鑰文件
ssh-add -K ~/.ssh/id_rsa
    1. cargo 的toml文件添加依賴,如下
[package]
name = "demo_rust"
version = "0.1.0"
authors = ["baoyachi <baoyachi>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
json               = "0.4"
pretty_env_logger = "0.3"
serde             = "1.0"
common-utils = { git = "ssh://git@xxx.com/common/common-utils.git", tag = "v0.0.1" }
common-log = { git = "ssh://git@xxx.com/common/common-log.git", branch = "master" }

這里的 common-utils common-log 就是私庫的具體依賴。

common-utils = { git = "ssh://git@xxx.com/common/common-utils.git", tag = "v0.0.1" }
common-log = { git = "ssh://git@xxx.com/common/common-log.git", branch = "master" }
  • 這里的git使用ssh方式訪問

  • tag :表示當(dāng)前git上的tag

  • branch :表示當(dāng)前git的 分支號
    通常,我們會采用tag對依賴的git代碼管理;branch的缺點無法lock代碼。

    1. 執(zhí)行cargo build
      正常情況下,cargo build可以正常下載crates.io和git私庫代碼
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容