Suppose I write some utility for dev env provisioning. I need to setup external binary on a developer machine. So how can I package random file into rust program to copy it on the dev machine when the utility is run?
Can you just copy the compiled executable across to the dev machine? Another alternative, if you have cargo
and rustc
installed, is to install the program from source with cargo
using something like this:
$ cargo install --git git@github.com/Michael-F-Bryan/some-utility
Otherwise you can generate proper installers using cargo-deb (for debian/ubuntu) or cargo-pkgbuild for Arch linux. I also know of cargo-bundle which attempts to make installers in a bunch of other formats (e.g. .app
, .rpm
, or .deb
), but I've never used it so wouldn't be able to say much about it.
Suppose I have Tolstoy's War and Peace poem (large thing), how can I pack it into Rust program so when it runs it creates a file with this poem?
If you want to embed a particular asset in your binary you probably want to look into the include_bytes!() and include_str!() macros. Once the asset is embedded in your executable you just need to copy that around and it can use the normal std::fs
module for writing it to a file whenever you run the program.
include_bytes! macros is what I was looking for. Thank you so much!