Hello
My console application runs some programs into new processes with:
let result = std::process::Command::new(command).args(arg).output();
I am also the developer of these other programs and they have the same life cycle as the main console application but they are developed with other languages than Rust. My first plan, which I thought of, was to distribute all of this in a zip archive:
But I am afraid that the users will break the application by doing for instance:
the move of myconsoleapplication.exeonly to /usr/bin
unset executable permissions of executables/program* files.
I would like to know it there is a smarter way to distribute my application?
In particular I found the possibility to embed binaries in a rust application with something like that:
const PROGRAM: &[u8] = include_bytes!("program2.exe");
let program = {
let mut p = std::env::current_dir()?;
p.push("program2.exe");
p
};
std::fs::write(&program, PROGRAM)?;
let child = std::process::Command::new(program).spawn()?;
What should I pay attention to when doing this? Is this the best thing to do? Do you know of any code samples from open source projects that do this?
Please, definitely do NOT start writing out and running executables at random locations. That will easily come across as doing something shady or outright malicious, and power users who find out about this will be very upset.
The problem you are trying to solve is OS-level package management. You should just compile each executable separately and use the packaging facilities of whatever platform you're on. For example, Linux distributions offer APT, pacman or yum; macOS offers homebrew; Windows has MSI installers.
Unfortunately there's nothing Rust-specific that can help with this. You'll need to use OS-specific solution, like a proper installer for Windows, perhaps an .app bundle for macOS, and packages for Linux various distros.
I'd expect antivirus programs to be quite suspicious about executables being dynamically written and executed from temporary writeable locations.
Yes, setting up a predictable and reproducible environment is pretty much the goal of Docker, so if you expect your users to be able to handle Docker, then it can specifically be a good option.