首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >openwrt的rust支持

openwrt的rust支持

作者头像
MikeLoveRust
发布2021-06-16 10:46:55
发布2021-06-16 10:46:55
2K0
举报
  • 准备环境 安装source包和xargo
代码语言:javascript
复制
rustup add component rust-src
cargo install xargo
  • 指定openwrt的gcc环境 拷贝toolchain到指定目录,或者在源目录下不动,在bash脚本~/.bashrc下编辑指定toolchain的bin目录,供xargo工程使用。
  • 编辑build.rs 指定连接时需要使用到的lib库,内容如下:
代码语言:javascript
复制
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
    );
}
  • 在.cargo/config指定目标
代码语言:javascript
复制
[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"]
  • 下载github代码,放到openwrt的package某目录下
代码语言:javascript
复制
https://github.com/likon/hello-rust

然后make menuconfig应该会出现hello-rust了。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-06-09,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档