git - 如何在 Cargo 中使用相对的 git 子模块路径?

标签 git rust git-submodules rust-cargo

我已经为 Rust 完成了一个 MuPDF 绑定(bind),我想将它作为一个 crate 从它的 git 存储库中导入。

我的 Cargo.toml 文件是这样的:

[package]
name = "package_name"
version = "0.1.0"
authors = ["me"]

[dependencies]
mupdf-sys = {git = "https://github.com/bruno-sm/mupdf-sys.git"}

问题在于 MuPDF 将其第三方库存储为具有相对路径的 git 子模块。这是 .gitmodules 文件的摘录:

[submodule "thirdparty/jbig2dec"]
    path = thirdparty/jbig2dec
    url = ../jbig2dec.git
[submodule "thirdparty/mujs"]
    path = thirdparty/mujs
    url = ../mujs.git

当我运行 cargo build 时,出现以下错误

Updating git repository `https://github.com/bruno-sm/mupdf-sys`
error: failed to load source for a dependency on `mupdf-sys`                     

Caused by:
  Unable to update https://github.com/bruno-sm/mupdf-sys

Caused by:
  failed to update submodule `mupdf`

Caused by:
  failed to update submodule `thirdparty/curl`

Caused by:
  invalid url `../thirdparty-curl.git`: relative URL without a base

这表明未指定 MuPDF 存储库的基本 URL,但它位于文件 .git/modules/mupdf/config

[remote "origin"]
url = git://git.ghostscript.com/mupdf.git
fetch = +refs/heads/*:refs/remotes/origin/*

git clone --recursive https://github.com/bruno-sm/mupdf-sys克隆仓库没有问题,所以不知道问题出在哪里.

要重现错误,您必须使用 cargo new project_name 创建一个新项目,添加

[dependencies]
mupdf-sys = {git = "https://github.com/bruno-sm/mupdf-sys.git"}

到 Cargo.toml 文件并运行 cargo build

要查看 MuPDF 存储库的内容,您可以使用 git clone --recursive git://git.ghostscript.com/mupdf.git

最佳答案

这远非解决方案,但我建议也将此类依赖项添加为子模块,并将依赖项添加到 Cargo 中作为 path。 因此,您自己的项目将需要递归更新子模块才能工作。但其他一切都应该按预期工作。

我希望他们能尽快在 cargo 中添加这样的功能。

关于git - 如何在 Cargo 中使用相对的 git 子模块路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51290136/

相关文章:

rust - 为什么即使在本地安装后,rust 也无法为 openssl-sys v0.9.60 构建命令?

Xcode 机器人 : git submodules not initialized

Python + 子模块 : ImportError: attempted relative import with no known parent package

git - 名为 'Icon' 的神秘 git 分支

rust - 如何获取 objcopy 生成的二进制镜像文件中的入口点地址?

混帐 : how to specify a default remote push-to branch?

generics - 根据rust函数中的泛型选择常量

git - 在 Visual Studio 中使用 git 子模块的工作流程

git - 撤消 git update-index --skip-worktree

git - 无法使用 IPv6 通过 SSH 推/pull 到 bitbucket