-
Prepare the environment: Install the source package and xargo.
rustup add component rust-src
cargo install xargo
-
Specify the OpenWRT gcc environment: Copy the toolchain to the designated directory, or leave it in the source directory, and edit the specified toolchain’s bin directory in the bash script ~/.bashrc
for xargo to use. -
Edit build.rs to specify the lib libraries needed during linking, as follows:
use std::env;
fn main() {
let staging_dir = env::var("STAGING_DIR").unwrap();
println!(
r"cargo:rustc-link-search={}/target-mipsel_24kec+dsp_uClibc-0.9.33.2/usr/lib",
staging_dir
);
}
-
Specify the target in .cargo/config
[build]
target = "mipsel-unknown-linux-gnu"
[target.mipsel-unknown-linux-gnu]
linker = "mipsel-openwrt-linux-uclibc-gcc"
rustflags = ["-C", "embed-bitcode"]
#rustflags = ["-C", "embed-bitcode", "-C", "prefer-dynamic"]
-
Download the GitHub code and place it in a directory under OpenWRT’s package.
https://github.com/likon/hello-rust
Leave a Comment
Your email address will not be published. Required fields are marked *