Skip to content

Rust example app and tutorial cross-compiled from x86 to ARM

License

Notifications You must be signed in to change notification settings

erickrenz/cross-compile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust - cross compiling with Cargo

Usage

This is an example of cross-compiling from x86 (x86_64) to ARM (armv7).

  1. Install the GCC cross-compilation toolchain with your default package manager (apt-get, dnf, pacman, brew, ...)
$ sudo apt-get install gcc-arm-linux-gnueabihf
  1. Install the target platform with rustup
$ rustup target add armv7-unknown-linux-gnueabihf
  1. Within your project, create cargo config.toml file
$ mkdir .cargo
$ touch config.toml
  1. Update config.toml with cross compilation details
[build]
target = "armv7-unknown-linux-gnueabihf"

[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
  1. Build and test your excecutable on the target system
# build normally on host
$ cargo build

# copy to target
$ scp target/armv7-unknown-linux-gnueabihf/debug/cross-compile user@arm:~

# run on target
$ ssh user@arm:~ ./cross-compile
Rust cross compiled from x86_64 -> aarch64

Alternatives

You can choose to manually select your compiler of choice each build of the project.

# Test locally on x86
cargo build --target=x86_64-unknown-linux-gnu

# Test remotely on ARM
cargo build --target=armv7-unknown-linux-gnueabihf

If you find yourself doing a lot of local testing, you can comment out the targets in the config.toml file. Then you can test locally as you normally would:

# Test locally on x86 - after commenting out config.toml
cargo build

Resources

License

This repository is distributed under the terms of the MIT license. See terms and conditions here.

About

Rust example app and tutorial cross-compiled from x86 to ARM

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages