Home > other >  How to publish a workspace crate with a submodule dependency?
How to publish a workspace crate with a submodule dependency?

Time:11-29

I have a project that consist in two crates in a workspace, one of them crate-sys generates some bindings. The other, crate consumes that crate-sys and builds a proper rust API on top of it. On the toplevel git project (workspace), I have configured a gitsubmole that downloads the original code to build the bindings (for crate-sys). It downloads the code to a vendor folder inside the crate-sys crate.

[Workspace]
    - crate-sys
        - vendor
    - crate

Now the problem comes on: How to publish crate-sys to crates.io so it will download the vendor code as well? Since the submodule information comes from the workspace git root not the crate itself?

CodePudding user response:

cargo publish won't check whether there is a submodule. It will just include all the files from below the current crate (package, actually?) folder except target/. Which is good, because crates should contain all the source necessary to be compiled and not require any additional downloads.

However, cargo does exclude subfolders in some situations (e.g. if they contain a Cargo.toml), so if in doubt, you can construct the .crate file and check its contents before publishing.

cargo package --allow-dirty # This won't publish, just create the .crate file
tar xvf ../target/package/*.crate
  • Related