首页 > 其他分享 >Rust 交叉编译环境搭建

Rust 交叉编译环境搭建

时间:2024-06-19 20:11:00浏览次数:13  
标签:cargo target -- 编译 https linux arm Rust 搭建

一、安装Rust

1. 官方安装

$ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh

安装时可能存在流量不稳定导致安装失败,可以更换源,使用国内的crates.io镜像。

2. 更换Rust镜像源进行安装

(1) 更换Rustup镜像源

         修改~/.bashrc, 追加如下内容

export RUSTUP_DIST_SERVER="https://rsproxy.cn"
export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"

(2) 更换crates.io镜像源

        在~/.cargo/目录下新建 config.toml  (cargo 1.38及以前的版本使用文件名config),

[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = "ustc" #或rustcc、sjtu、tuna

#根据replace-with配置的镜像源,以下只需配置一个对应的源即可
# 中国科大 [source.ustc] registry = "git://mirrors.ustc.edu.cn/crates.io-index"

# rustcc社区
[source.rustcc]
registry = "https://code.aliyun.com/rustcc/crates.io-index.git"

  # 上海交通大学
  [source.sjtu]
  registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

  # 清华大学
  [source.tuna]
  registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

(3)重新执行安装脚本

$ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh

 

二、交叉编译ARM目标

1. 将ARM添加为Rust目标平台

$ rustup target list #可以查看所有可添加的目标平台
$ rustup target add arm-unknown-linux-gnueabihf #本例添加 arm-unknown-linux-gnueabihf

2. 在 ~/.cargo/config.toml 中指定ARM目标的链接器

[build]
target = "arm-unknown-linux-gnueabihf"

[target.arm-unknown-linux-gnueabihf]
linker = "arm-none-linux-gnueabihf-gcc"

 

三、HelloWorld示例

1. 使用cargo创建项目

$ cargo new rust_helloworld --bin

   cargo将创建项目目录rust_helloworld, 其下包含Cargo.toml和src/main.rs

2. 交叉编译ARM目标文件

$ cargo build --release  #因在config.toml中配置了target为arm-unknonw-linux-guneabihf,所以默认生成arm目标
#或者
$ cargo build --release  --target=arm-unknown-linux-gnueabihf

 cargo 将生成目标目录target,bin文件存放在 target/arm-unknown-linux-gnueabihf/release/

3. 编译本地架构的目标文件

$ cargo build --release  --target=x86_64-unknown-linux-gnu  #本例PC为x64架构

 

标签:cargo,target,--,编译,https,linux,arm,Rust,搭建
From: https://www.cnblogs.com/rtthread/p/18257260

相关文章

  • Gitlab搭建
    目录Gitlab1.使用docker部署gitlab2.登录gitlab2.1修改语言为中文2.3修改密码3.用户管理3.1创建用户4.配置ssh拉取代码4.1添加ssh密钥4.2测试拉取Gitlab1.使用docker部署gitlab[root@master~]#mkdir-p/data/gitlab/{config,logs,data}编写docker-compose.yaml......
  • ensp通过云连接VMware中Windows Server 2012 中搭建的DHCP服务器实现不同VLAN自动获取
    实验描述通过在ensp中搭建拓扑图实现在VLAN10获取192.168.1.0网段地址,VLAN10获取192.168.1.0网段地址,VLAN20获取192.168.2.0网段地址,VLAN30获取192.168.1.0网段地址,VLAN40获取192.168.4.0网段地址.WindowsServer2012搭建DHCP服务器开启VMware配置网卡信息选择为自定......
  • 小雅alist搭建教程
    先去服务器拉取小雅镜像可以利用github中的来拉取 拉取到本地后执行bash-c"$(curlhttp://docker.xiaoya.pro/update_new.sh)"然后本地就会出现小雅的docker容器获取阿里云token、opentoken、转存目录folderidtoken获取:获取网址: https://alist.nn.ci/zh/guide/drive......
  • 搭建服务端性能监控系统 Prometheus 详细指南
    前言在现代软件开发中,性能监控是确保系统稳定性和性能优化的重要环节。Prometheus是一个开源的系统监控和报警工具,广泛用于容器化环境和微服务架构。本指南将详细介绍如何在服务器上搭建Prometheus性能监控系统。安装Prometheus环境准备确保你的服务器上已经安装了以下......
  • 【云服务器介绍】选择指南 腾讯云 阿里云全配置对比 搭建web 个人开发 app 游戏服务器
    ​省流目录:适用于博客建站(2-4G)、个人开发/小型游戏[传奇/我的世界/饥荒](4-8G)、数据分析/大型游戏[幻兽帕鲁/雾锁王国]服务器(16-64G)1.京东云-618专属活动 官方采购季专属活动地址:京东云-618采购季服务器活动专区https://3.cn/20-J4jjX京东云又双叒降价了!活动页大改,增加两......
  • linux中搭建mysql服务
    下载mysql安装包wgethttps://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz解压压缩包tar-xvfmysql-5.7.27-linux-glibc2.12-x86_64.tar.gz#移动文件夹mvmysql-5.7.27-linux-glibc2.12-x86_64/usr/local/mysqlmysql用......
  • vue模板编译器
    vue模板编译器import{ASTElement,compile}from'vue-template-compiler';import{TableColumnDesc}from"@/components/table/base-table/type.ts";exportconstcodeAdapter=function(code:string):{tableCode:string;columns:TableC......
  • <编译器> 7. 中间代码 | 4. 主要语句的IR树
    1.调用output:=concat(output,s)2.数组,赋值a[i+1]:=0数组变量a[i]为a(基地址)+i*w(偏移量)3.while循环伪代码:whilecnddobodystart:ifnotcndgotodonebodygotostartdone两种实现:4.for循环:变量声明+while循......
  • docker(ubuntu18.04) + 宿主机(ubuntu20.04) + ROS + 乐视三合一体感摄像头LeTMC-520
    参考链接:https://blog.csdn.net/weixin_45225720/article/details/1144642441.准备docker环境dockerpullhyeonjaegil/vins-monodockerrun-it--privileged--networkhost--gpusall\-v/tmp/.X11-unix:/tmp/.X11-unix\-eDISPLAY-eNVIDIA_VISIBLE_DEVIC......
  • 从0到1使用vite搭建react项目保姆级教程(持续更新中)
    一、vite创建react项目要使用Vite创建一个React项目,你需要按照以下步骤操作:1、确保你已经安装了Node.js(建议使用最新的稳定版本)。2、使用npm命令安装ViteCLI工具,再来创建项目npmcreatevite@latestmy-vite-app 3、运行上述命令后,按照提示选择“create-react-app”......