Ubuntu 22.04下加快rust的编译速度
在学习Rust的时候,相信不少人和我一样一直受Rust编译慢的问题困扰。最近阅读一篇写得相当不错的英文博客《Tips for Faster Rust Compile Times》,加上最近刚刚入手一台华为云服务器,于是决定尝试一下效果如何(主要介绍mold,sccache)。
运行环境:
操作系统:Ubuntu 22.04
CPU与内存:1核2G
mold版本:v1.3.1
编译、安装mold
按照mold官方的教程,使用源代码进行编译、安装。
git clone https://github.com/rui314/mold.git
cd mold
git checkout v1.3.1
make -j$(nproc) CXX=clang++
sudo make install
在执行编译时,系统报错,是因为mold使用C++20编写,需要相应的编译器进行编译器(g++-10
),而操作系统默认的编译器gcc版本较低(gcc 9.4.0)。接下来则先安装相应的编译器。
apt install g++-10
g++-10 --version
apt install gcc-10
gcc-10 --version
再次编译,报如下错误;
root@hecs-131857:/home/rust/mold# make -j$(nproc) CXX=clang++
clang++ -DMOLD_VERSION=\"1.0.0\" -DLIBDIR="\"/usr/local/lib\"" -DGIT_HASH=\"ed9924895d9b9584106791247596677db8113528\" -Ithird-party/mimalloc/include -Ithird-party/tbb/include -O2 -pthread -fPIE -fno-unwind-tables -fno-asynchronous-unwind-tables -std=c++20 -fno-exceptions -c -o out/main.o main.cc
In file included from main.cc:1:
./elf/mold.h:30:10: fatal error: 'xxh3.h' file not found
于是使用apt-file查询xxh3.h所在的库并进行安装。
apt-get install apt-file
apt-file update
apt-file search xxh3.h
apt install libxxhash-dev
再次编译,还是报错,继续安装cmake,编译......。
(cd out/mimalloc; CFLAGS=-DMI_USE_ENVIRON=0 cmake -G'Unix Makefiles' ../../third-party/mimalloc)
/bin/sh: 1: cmake: not found
make: *** [Makefile:115: out/mimalloc/libmimalloc.a] Error 127apt install cmake
最后进行安装。
root@hecs-131857:/home/rust/mold# make install
install -m 755 -d /usr/local/bin
install -m 755 mold /usr/local/bin
strip /usr/local/bin/mold
install -m 755 -d /usr/local/lib/mold
install -m 644 mold-wrapper.so /usr/local/lib/mold
strip /usr/local/lib/mold/mold-wrapper.so
install -m 755 -d /usr/local/share/man/man1
install -m 644 docs/mold.1 /usr/local/share/man/man1
ln -sf mold /usr/local/bin/ld.mold
ln -sf mold /usr/local/bin/ld64.mold
测试mold
接下来测试未使用mold和使用mold两种情况的编译速度。
测试1:未使用mold
root@hecs-131857:/home/rust/mp-share-it# cargo clean
root@hecs-131857:/home/rust/mp-share-it# cargo build
-------省略-------Compiling tower v0.4.11Compiling hyper v0.14.15Compiling hyper-tls v0.5.0Compiling axum v0.3.4Compiling reqwest v0.11.7Compiling mp-share-it v0.1.0 (/home/rust/mp-share-it)Finished dev [unoptimized + debuginfo] target(s) in 3m 20s
测试2:使用mold,(修改 ~/.cargo/config
)
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/mold"]
root@hecs-131857:/home/rust/mp-share-it# cargo clean
root@hecs-131857:/home/rust/mp-share-it# cargo build
-------省略-------Compiling tower v0.4.11Compiling hyper v0.14.15Compiling hyper-tls v0.5.0Compiling axum v0.3.4Compiling reqwest v0.11.7Compiling mp-share-it v0.1.0 (/home/rust/mp-share-it)Finished dev [unoptimized + debuginfo] target(s) in 3m 04s
经过一番操作折腾(走了不少弯路,踩了一些坑),通过测试的结果来看,mold对于加快Rust的编译速度还是有一定作用的(还有很大的优化空间)。
编译、安装sccache
cargo install sccache# 修改配置
vim ~/.cargo/config## 添加如下配置
[build]
rustc-wrapper = "/root/.cargo/bin/sccache"
测试sccache
测试1:未使用sccache
root@hecs-131857:/home/rust/leetcode-rust# cargo build --release
-------省略-------Compiling criterion-plot v0.4.4Compiling criterion v0.3.5Compiling leetcode-rust v0.1.0 (/home/rust/leetcode-rust)Finished release [optimized] target(s) in 2m 43s
root@hecs-131857:/home/rust/leetcode-rust#
测试2:使用sccache
root@hecs-131857:/home/rust/leetcode-rust# cargo clean
root@hecs-131857:/home/rust/leetcode-rust# cargo build --release
-------省略-------Compiling criterion-plot v0.4.4Compiling criterion v0.3.5Compiling leetcode-rust v0.1.0 (/home/rust/leetcode-rust)Finished release [optimized] target(s) in 26.76s
root@hecs-131857:/home/rust/leetcode-rust#
经过测试,使用sccache能大幅加快rust编译速度,节约了不少编译时间。
Ubuntu 22.04下加快rust的编译速度相关推荐
- Ubuntu 18.04 下搭建 C/C++编译开发环境及GCC多版本切换
关注公众号 风色年代(itfantasycc) 领 500G Java 微服务 开发资料 Ubuntu 18.04 下搭建 C/C++编译开发环境及GCC多版本切换_Linux教程_Linux公社-L ...
- WSL Ubuntu 20.04下Android源码编译与导入Android Studio
源码下载见前文:WSL Ubuntu 20.04下Android源码下载 idegen 模块编译 在development/tools/idegen/README下可以看到关于 idegen 工具的相 ...
- Ubuntu 22.04操作系统下常用软件备忘
时间过得真快,不知不觉间Ubuntu的桌面版本已经到了22.04.本文记录我在Ubuntu 22.04下使用的部分软件,一方面供刚开始使用Ubuntu系统的朋友们参考,另外就是方便自己以后重装系统.下 ...
- [2014.3.4]天嵌TQ210在Ubuntu 11.04下编译 OpenCV2.0.0(PC)
(一)先安装cmake (1)网上通用 apt-get install cmake 但我安装后有问题,cmake-gui出现段错误. (2)参考<CMake安装和使用> 解压cmake-2 ...
- Ubuntu 12.04 下编译Android 4.0.3
在Ubuntu 12.04 下编译了Android 4.0.3发现了一大堆错误,网上找了一堆的更改源码啊,Android.mk的解决方法,虽然可以编译成功,但都有点坑爹的成分,为了不误人子弟就分享出来 ...
- ubuntu 环境下调试mysql源码_【转】Ubuntu 16.04下 Mysql 5.7.17源码编译与安装
Ubuntu 16.04下 Mysql5.7.17源码编译与安装 系统环境 一. 系统安装条件 1.cmake MySQL使用cmake跨平台工具预编译源码,用于设置mysql的编译参数. sudo ...
- Ubuntu 14.04下编译WebRTC
阿里云 > 教程中心 > python教程 > Ubuntu 14.04下编译WebRTC Ubuntu 14.04下编译WebRTC 发布时间:2018-02-28 ...
- Ubuntu 11.04下编译kernel
Ubuntu 11.04下编译kernel 1. 下载并解压Linux内核源代码, 内核源码下载地址为www.kernel.org,查看当前内核版本命令为uname -r.下载后解压至目录/usr/s ...
- Ubuntu 22.04 LTS下安装1030 GPU 的驱动(图文详解)
文章目录 Ubuntu 22.04 LTS下安装1030 GPU 的驱动 法一:命令获取推荐驱动直接安装(简单有效) 1.检查你的操作系统,如下图: 2.查看是否有[GPU](https://so.c ...
最新文章
- 青少年编程竞赛交流群周报(第040周)
- 用Visio制作周行事历
- 用C#2.0实现网络蜘蛛(WebSpider)
- MFC的静态库.lib、动态库.dll(包含引入库.lib)以及Unicode库示例
- android 禁用dlsym_Android 7.0 dlopen 函数分析
- 机器学习之基于A*搜索解决八数码问题15数码问题
- 博客园修改页面显示样式
- 【恋上数据结构】计数排序
- 热门好用的邮编查询API
- java每日一练(19_03_18)
- php 获取京东商品详情,用正则表达式,抓取京东的商品列表
- A Linux Environment Zero Overhead
- 泰山OFFICE技术讲座:字体属性的上标研究1:上标是什么
- JAVA学习笔记(三十一)-电影系统案例
- Android 带你玩转实现游戏2048 其实2048只是个普通的控件(转)
- Python下载小说遮天
- C++中public:的意思
- 云原生监控报警可视化
- 实时日志监控系统-全览
- 新型海上风电机组及压缩空气储能系统的建模与控制(Matlab代码实现)