Unable to get a Rust binary to run on Alpine, Tiny Core or Yocto Linux


#1

Hi folks,

I’m a Rust noob but competent with Linux and Python.

My goal is to build a Rust static binary and get it to run on Alpine Linux (or second preference Tiny Core Linux or Yocto Linux)

This is what I am trying to make work:
https://rocket.rs/guide/getting-started/#hello-world

But whenever I copy the binary file to the target OS and run it, I get:
‘No such file or directory’

I build on a clean Ubuntu 16 setup with these commands:

apt update
apt install rust
wget https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init
chmod +x rustup-init
./rustup-init
source $HOME/.cargo/env
rustup default nightly
rustup update
cargo update
cargo new hello-rocket --bin
cd hello-rocket
vi Cargo.toml
apt-get install build-essential
cargo run
ROCKET_ENV=production
rustup target add x86_64-unknown-linux-musl
apt install musl-tools
cargo build --release  --target x86_64-unknown-linux-musl

I’ve spent all day on this and tried everything I can think of but nothing works.

Is there anyone who has managed to get Rust code to run on Alpine Linux?

If yes, can you help me find what I am doing wrong?

thanks


#2

Have you tried to install rustc from aports?


#3

You may also want to double check you’re using the right target architecture. I once accidentally compiled for 32-bit when I wanted 64-bit (or vice versa, I forget) and kept getting that rather useless “no such file or directory” error message.

It may also be that you don’t have a necessary *.so installed. Even though you are compiling for *-musl, there’s a good chance that you’ll be trying to dynamically link to OpenSSL for crypto. Dependencies are still free to dynamically link against system libraries.

What does ldd say?