18

There may not be a good answer for this question, but I have code that I would like to share between two different Rust projects WITHOUT publishing the crate to crates.io.

The code is proprietary and I don't want to put it out into the wild.

Cœur
  • 37,241
  • 25
  • 195
  • 267
mattforni
  • 855
  • 5
  • 11
  • 1
    FYI, it appears this is a nice case of the [X-Y Problem](http://meta.stackexchange.com/q/66377/281829). It seems you *really* want to know "how do I share code without publicly publishing the common code", but the question is about a solution; one that technically precludes my answer from being acceptable. I took a gamble that it actually solves your root problem. ^_^ – Shepmaster Jun 02 '16 at 03:25
  • I may make sense to review the question, to make it match its intent more closely. – Matthieu M. Jun 02 '16 at 06:21
  • Not entirely sure what you mean @MatthieuM. This is definitely one way to do it. I suppose it won't work on **any** box since it is dependent on having the local crate, but it works in the local sense. – mattforni Jun 02 '16 at 06:29
  • 1
    @mattforni: I mean that the question is more about "not publishing to crates.io" than "not creating a crate" so it would be better to focus it on the "not publishing to crates.io" bit; then answers can focus on how to distribute a crate internally within a company, which is really what you want to solve, rather than launch themselves in some kind of remote-syncing of copy/pasted files or such silliness :) – Matthieu M. Jun 02 '16 at 06:32
  • 1
    Check out the rewording I applied to your question, I think that's what @MatthieuM. and I are suggesting. Feel free to roll it back if you think it no longer matches your original intent. – Shepmaster Jun 02 '16 at 14:23
  • 1
    @Shepmaster: That's indeed what I was thinking of too; now the question will probably be of interest to a much wider audience as I imagine that many organizations would rather not expose their code on Internet. – Matthieu M. Jun 02 '16 at 14:26
  • I like. Thanks guys. Much appreciated. – mattforni Jun 02 '16 at 19:03

1 Answers1

18

but it's proprietary code and I don't want to put it out into the wild.

You don't have to publish a crate. Specifically, just create the crate (cargo new shared_stuff) then specify the path to the common crate(s) in the dependent project's Cargo.toml:

[dependency.shared_stuff]
path = "path/to/shared/crate"

The Cargo documentation has an entire section on types of dependencies:

I believe that Cargo will allow you to fetch from a private git repository (such as on Github or another privately hosted service, such as GitLab), but I haven't tried that personally. Based on my searching, you will need to have previously authenticated or otherwise configured git to not require an interactive password entry.


It's theoretically possible to create your own crate registry. I've not even attempted to do this, but the machinery is present in Cargo to handle it.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366