The deployment "holy trinity"


#1

Is there a novice’s guide on how to package up a rust binary or library for deployment?

If it’s a C program, I can use autotools to build a tar file that a would-be user downloads and installs with ‘./configure; make; sudo make install’. What’s the rust equivalent? Is there a sequence of ‘cargo’ commands or the like?

Thanks


#2

For distribution as source code the Rust’s way is to publish the package to https://crates.io

http://doc.crates.io/crates-io.html

So then users don’t need to download or build the code themselves, but can tell Cargo to do it (if it’s a library, user can add the dependency by name to Cargo.toml, if it’s a tool, then users can do cargo install your_tool_name).


#3

This is true for libraries, and for binaries for Rust programmers, but not binaries in general. For non-Rust-programmer end-users, using the native packages or whatever on your target platforms is ideal. Tooling for this is all over the place, from “Just works” to “looks like you’ll have to implement it yourself”.


#4

Thanks, but I think I have to take that as a “no”; dependence on a centralized mechanism is something I would prefer to avoid, or have the option of avoiding.

If I write a C program for my great-aunt, I can provide it to her without publishing it to the world. Or inside some enterprise, I can provide it on an internal server or even an internal deb or rpm archive. Perhaps there is some defined way to do the equivalent for a rust program?


#5

using the native packages or whatever on your target platforms is ideal

Yes, I was hoping for some pointers towards that…

Tooling for this is all over the place, from “Just works” to “looks like you’ll have to implement it yourself”.

Oh well…
Thanks for clarifying.


#6

If your aunt uses git, then publishing any git URL to a repository that contains Cargo.toml also works (http://doc.crates.io/specifying-dependencies.html#specifying-dependencies-from-git-repositories).

There’s no autotools ./configure equivalent. Even a zip/tarball with Rust source code and Cargo.toml is buildable.

All that is assuming that you’re distributing as source code and your recipient is OK having Rust and Cargo installed (you might recommend https://www.rustup.rs/ for getting Rust installed)

If you want to distribute as binary, then cargo build --release and your binary will be in target/release/your_bin_name. AFAIK by default Cargo links everything statically, so the executable will be big, but it will work without needing Rust installed.


#8

Is there an automated way to bundle all dependencies, so that the whole thing can be compiled from source without (full) network access?


#9

Yes: https://github.com/alexcrichton/cargo-vendor


#10

Am I missing something here?

I keep rereading the OP’s posts, and I fail to see how the following command does not meet his requirements:

cargo install

It is a single command that, when run inside a crate directory, will perform a release build of it and install it to ~/.cargo/bin (which should already have been added to PATH by rustup).


#11

That’s not a system solution on par with C libraries. OP is rather looking for something like make install destdir=foobar && package up a package in deb / rpm / whichever.


#12

Here’s how I do it. Not too complicated, and certainly nowhere near as complicated as a “simple” autotools solution.