I recently acquired a Raspberry PI 2 and I want to run a Rust program on it.
Is there a guide/instructions how to cross compile Rust programs on Raspberry PI 2? I've heard about running Rust on RPi or Arduino, although not recently.
I want a Hello World
equivalent Rust program running on Raspberry Pi 2. It doesn't have to be a literal Hello World program, just something that is of similar low complexity.
Installing Rust on Raspberry Pi Step 1: Open the terminal of Raspberry Pi Os, then write the following command to download Rust. Step 2: You have to wait till the process is completed. Then enter option 1 to proceed with the installation process. Step 3: You have to wait till the installation is completed.
rust_gpizero uses the Rust programming language to do physical computing on the Raspberry Pi. If you own a Raspberry Pi, chances are you may already have experimented with physical computing—writing code to interact with the real, physical world, like blinking some LEDs or controlling a servo motor.
For compiling C programs, we use a compiler called gcc because it comes installed on the Raspberry Pi. It has many complicated options which allow us to tailor its output to our needs, however to compile a simple program like the Hello Pi above, it is nicely simple.
Rust supports a great number of platforms. For many of these platforms The Rust Project publishes binary releases of the standard library, and for some the full compiler. rustup gives easy access to all of them.
We have rustup now.
$ rustup target add arm-unknown-linux-gnueabihf $ sudo apt-get install gcc-arm-linux-gnueabihf $ echo '[target.arm-unknown-linux-gnueabihf]' >> ~/.cargo/config $ echo 'linker = "arm-linux-gnueabihf-gcc"' >> ~/.cargo/config $ cd <project dir> $ cargo build --target=arm-unknown-linux-gnueabihf
The Rust compiler is not distributed as a cross-compiler for the Raspberry Pi, so it needs to be compiled as a cross compiler with rpi dev tools.
Get rpi dev tools - git clone https://github.com/raspberrypi/tools.git ~/pi-tools
get rust compiler from mozilla git repo and add rpi tools to the path export PATH=~/pi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin:$PATH
Look for rusty-pi dir on your home ./configure --target=arm-unknown-linux-gnueabihf --prefix=$HOME/rusty-pi && make && make install
Considering helloworld.rs -> % ~/pi-rust/bin/rustc --target=arm-unknown-linux-gnueabihf -C linker=arm-linux-gnueabihf-g++ helloworld.rs
It will produce an executable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With