Cross compiling Rust — Fixed
Set up build environment
rustup toolchain install nightly
rustup component add rust-src --toolchain nightly
apt install {binutils,gcc}-mips-linux-gnu
Create test project
cargo new foo
cd foo
Configure linker
mkdir .cargo
cat > .cargo/config.toml
[target.mips-unknown-linux-gnu]
linker = "mips-linux-gnu-gcc"
^D
Build
cargo +nightly build --release -Zbuild-std --target mips-unknown-linux-gnu
Change the “interpreter” to what the Ubiquiti system expects
cd target/mips-unknown-linux-gnu/release
patchelf --remove-needed ld.so.1 foo
patchelf --set-interpreter /lib/ld-musl-mips-sf.so.1 foo
Does it work?
$ ./foo
Hello, world!
Yay!
Links
- https://doc.rust-lang.org/rustc/targets/custom.html
- https://doc.rust-lang.org/cargo/reference/config.html


