Including non-Rust asset in installation

Hello,

My Rust project includes a non-Rust file (in this case a Bash script I want to execute from my Rust code via std::process::Command, but shouldn't matter). I want that file to be copied unchanged to some place where the Rust code can find it and the Rust code needs to know where it is. How do I do this?

Thanks!

Best, Oliver

cargo install is only able to install self-contained binaries. For more complex packages, you'll need to use some other packaging and installation method. For example, on Linux, cargo-deb and cargo-rpm might be useful.

1 Like

Thanks, I'll look into cargo-deb.

Now I have the problem, how does the code know where the file is. Is there a way to do conditional compilation based on whether or not the code has been deployed using cargo-deb or not? Thanks!

If it is just a small file have you considered including it in the binary using std::include_str!() or std::include_bytes!() and just writing it to disk at a place of your choosing at runtime?

Having just a single binary for deployment is hard to beat for easy-of-use.

2 Likes

If it is a bash script, does it even need to be turned into a file? Maybe bash can be sent the string as a command directly?
From the bash manpage
"If the -c option is present, then commands are read from the first non-option argument command_string."

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.