How to use relative git submodule paths in Cargo?
Asked Answered
I

3

9

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

Inseminate answered 11/7, 2018 at 16:17 Comment(4)
Welcome to Stack Overflow! Please review how to create a minimal reproducible example and then edit your question to include it. Right now, it's unclear what exactly is the setup of files, repositories, what links where, what is a submodule, etc. Ideally, provide a listing of command line invocations that recreates your setup and the error.Hughett
Bruno, Did you find a solution to this problem? I am facing the same issue.Twitter
Nope sorry, I gave up.Inseminate
I wondered if this is still the case 1,5 years after? I'm facing the same problem and can imagine other people using cargo and having relative submodules (e.g. when using GitLab).Agog
F
1

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.

Felicefelicia answered 3/9, 2021 at 13:34 Comment(0)
S
1

The problem is now fixed in Cargo.

Spa answered 22/9, 2022 at 15:59 Comment(0)
H
-1

The problem is that MuPDF stores its third party libraries as git submodules with relative paths

So you would need to provide those repositories in the relative paths. Clone the jbig2dec and mujs repos in the relative location as listed under the .gitmodules file. Now when you do the --recurse-submodules it should work okay.

Haskel answered 11/7, 2018 at 18:16 Comment(1)
Yes, if I use git clone --recurse-submodules works, cloning jbi2dec and the other repositories automatically. The problem is when Cargo clones the repo, it seems like it's not able to solve the relative paths.Inseminate

© 2022 - 2024 — McMap. All rights reserved.