How to distribute multiple executables

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:

--> .
--> myconsoleapplication.exe
------> executables
-----------> program1.jar
-----------> program2.exe
-----------> program3.exe

But I am afraid that the users will break the application by doing for instance:

  • the move of myconsoleapplication.exe only 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()?;
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?

Thank you


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.


Thank you, I will jump into os package manager tools.
It seems indeed the proper way to do it but not easy I would say:

  • I have to package my app for all these os specific format.
  • and to host the package on each package community repository or to set up my own public repository.

Does distributing a docker image could be an alternative solution?
With executables manually placed at the right location when building this image.

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.

1 Like

... so "rewrite it in Rust", as the meme went (RiiR) a few years back?

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.

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.