Setup rust build env for kernel

rust current on linux kernel only support x86_64 or um.
1 install libclang-17-dev
$ sudo vim /etc/apt/sources.list
add
deb http://apt.llvm.org/focal/ llvm-toolchain-focal-17 main
deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-17 main
$ sudo apt update
错误:7 https://apt.llvm.org/focal llvm-toolchain-focal-17 InRelease
  由于没有公钥,无法验证下列签名: NO_PUBKEY 15CF4D18AF4F7421
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 15CF4D18AF4F7421
$ sudo apt update
$ sudo apt install libclang-17-dev

2 download llvm from kernel
https://mirrors.edge.kernel.org/pub/tools/llvm/
https://mirrors.edge.kernel.org/pub/tools/llvm/files/llvm-17.0.6-x86_64.tar.gz

3 tar -zxvf llvm-17.0.6-x86_64.tar.gz /media/fmin/nvme/llvm-17.0.6-x86_64
$ export PATH=$PATH:/media/fmin/nvme/llvm-17.0.6-x86_64/bin

4 following guide Documentation/rust/quick-start.rst
$ rustup override set $(scripts/min-tool-version.sh rustc)
$ rustup component add rust-src
$ cargo install --locked --version $(scripts/min-tool-version.sh bindgen) bindgen-cli
$ rustup component add rustfmt
$ rustup component add clippy
$ make LLVM=1 rustavailable
 
 

5 build kernel with rust enable

$ make x86_64_defconfig

$ make menuconfig

enable below configs

CONFIG_SAMPLES_RUST=y                                                            
CONFIG_SAMPLE_RUST_MINIMAL=y                                                     
CONFIG_SAMPLE_RUST_PRINT=y                                                       
CONFIG_SAMPLE_RUST_HOSTPROGS=y                

$ time make LLVM=1 -j8

$ make LLVM=1 rust-analyzer

  • 22
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值