The deployment "holy trinity"

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

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).

1 Like

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".

2 Likes

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?

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.

If your aunt uses git, then publishing any git URL to a repository that contains Cargo.toml also works (Page Moved).

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.

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

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

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).

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.

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

https://github.com/kaj/chord3/blob/master/chord3.spec