Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use relative git submodule paths in Cargo?

I've done a MuPDF binding for Rust and I want to import it as a crate from its git repository.

My Cargo.toml file is something like this:

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

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

The problem is that MuPDF stores its third party libraries as git submodules with relative paths. Here is an extract of the .gitmodules file:

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

When I run cargo build I get the following error

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

This suggests that the base URL for the MuPDF repository is not specified, however it is in the file .git/modules/mupdf/config

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

There is no problem cloning the repository with git clone --recursive https://github.com/bruno-sm/mupdf-sys, so I don't know where the problem can be.

To reproduce the error you have to create a new project with cargo new project_name, add

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

to the Cargo.toml file and run cargo build.

To see the contents of the MuPDF repository you can use git clone --recursive git://git.ghostscript.com/mupdf.git

like image 797
Bruno Santidrian Avatar asked Jul 11 '18 16:07

Bruno Santidrian


1 Answers

That's far from a solution, but I would recommend to add such dependency as a submodule as well, and add the dependency in Cargo as path. With that your own project will need to have a submodule update recursive to work. But everything else should work as expected.

I hope that they add such feature soon in cargo.

like image 121
Patrick José Pereira Avatar answered Oct 20 '22 07:10

Patrick José Pereira