Deploying Rust applications / UNIX filesystem standards

I'm in the process of porting a forensics tool from C++ to Rust. (The codebase is mature, but an upstream vendor is necessitating some big changes, and I'm taking advantage of the opportunity to do a rewrite.) The C++ codebase uses CMake as a build environment, and takes advantage of the standard UNIX filesystem layout. On doing a make install the binary gets dropped to $PREFIX/bin, data files to $PREFIX/share/nsrlsvr, configuration files into /etc/nsrlsvr, and so on.

I've been perusing the Cargo docs, but I'm not seeing an obvious way to do this with the Cargo system. Am I just looking in the wrong place?

If the Rust ecosystem prefers a different approach to data and configuration files, I'm amenable to hearing that, too. I'd much prefer to do this the right way rather than just make a clumsy port. :slight_smile:

1 Like

You can call the cargo from your Makefile, just like how you did with cmake.

They want to know if there's some Cargo command that installs a Rust program in the right places, something analogous to make install. I don't think they have a Makefile.

IMO, the big-picture way to understand this is: Cargo is not a deployment or packaging tool. Cargo builds binaries (and libraries), and does the things necessary to make that happen. Everything past β€œthe binary exists in target/” is a problem that Cargo does not address, and it's up to you to choose or write a tool to handle that.

Cargo does have cargo install, but that only installs binaries, defaults to installing them to ~/.cargo/bin, and does not integrate with system package management or provide much of an update mechanism.)

6 Likes

You may be looking for cargo-native-install β€” Rust/Cargo add-on // Lib.rs

Like any cargo-* bin, you should be able to install it with cargo install cargo-native-install, and use it as cargo native-install.

1 Like

Thank you for this clear answer. Looks like I'll continue to use Autotools to provide the deployment and packaging, and have it call out to cargo for compilation. It seems a little awkward to me but I suppose I understand the rationale.

I appreciate everyone who answered: thank you. I'm in the very early stages of this rewrite/port (however one wants to call it) right now, and it's nice to have clarity on what the Rustacean-preferred way is to deploy. :slight_smile: