我已经为 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/