Compiling crate for Heroku


Hey there,

How can I compile a binary crate to be executed, as a command (i.e bin/hello_world) , in Heroku which uses an Ubuntu distribution? I imagine that is setting a value for the flag --target maybe, but I am helpless as I don’t know which name should I use.

I tried to use emk’s buildpack among others, but my existing buildpacks are incompatible (the main app is a Rails one) with these ones.


1 Like


Rust binaries are statically linked by default and can usually be compiled on one Linux machine and run on a different one without much difficulty. There are a couple of caveats, however:

  1. The default Linux toolchain links Rust binaries dynamically to glibc (because glibc doesn’t support static linking). This may cause problems if the host machine uses a newer glibc than the target machine. You can solve this by compiling on a distro whose glibc version is equal to or lower than your target environment, or by using the musl target which links statically to the MUSL libc.

  2. If you have dependencies that link to system libraries (for example the openssl-sys crate), these might also use dynamic linking. You’ll need to make sure any dynamically-linked C libraries are installed on your target machine, just as they are on your host machine. Or in some cases you can configure these dependencies to link statically. See the openssl docs for example.

1 Like


In what way is emk’s buildpack incompatible with your existing buildpacks? What happens when you try? deploys on heroku with emk’s buildpack and a few others by using the multi buildpack.

1 Like


Hey Carol,

It basically said something along the lines that the app was not compatible with the app (which again, it was a Rails one).

Just for the record, the way I sorted this out was by compiling inside of Docker and copying from the container to the host the compiled executable.

Thanks everybody for the help though! :star_struck: