provide PKGBUILD
for MabezDev/rust-xtensa
- download this repo and unzip, click this
cd rust
makepkg -s
pacman -U rust-xtensa-git-*.pkg.tar.zst
This will build rust toolchain and llvm and install it. You will need at least 10GB ram and 25GB disk to build.
For more about build, refer to MabezDev/rust-xtensa
As MabezDev/rust-xtensa
update llvm upstream to espressif
, the llvm
directory is no longer requried,
you can still build llvm-project
yourself, and add --llvm-root=/opt/llvm-xtensa
to rust/PKGBUILD
,
but this will break install
due to the lack of libunwind
source code in src/llvm-project/libunwind
, you will need to fix it.
Download from release.
There is no guarantee that prebuilt package will work due to archlinux update policy. If you encounter error, try build yourself or open an issue.
This package will install rust toolchain and cargo
in /opt/rust-xtensa
, you can call cargo
and rustc
directly from /opt/rust-xtensa/bin
.
Or link to rustup
:
rustup toolchain link xtensa /opt/rust-xtensa
And call with cargo +xtensa build
or override using rustup override set xtensa
.
To build to xtensa, use xtensa-esp32-none-elf
/xtensa-esp32s2-none-elf
/xtensa-esp8266-none-elf
target.
Install cargo-xbuild with cargo install cargo-xbuild
, this tool will help you to compile crate like core
, alloc
to xtensa target.
example
export XARGO_RUST_SRC=/opt/rust-xtensa/lib/rustlib/src/rust/library
cargo xbuild --target xtensa-esp32-none-elf
Cargo also have a unstable feature build-std
, works similar to cargo-xbuild
.
example
cargo build -Z build-std --target xtensa-esp32-none-elf
NOTE build-std
doesn't work for esp8266
target, but work fine for esp32
and esp32s2
-
add
#![no_std]
to yourlib.rs
ormain.rs
. -
#![no_std]
doesn't meant to the end of world, you can still useextern crate core
to addcore
library to your crate. -
add a panic handler, for examples,
panic-abort
/panic-halt
. -
if you need alloc feature, like
vec
, addextern crate alloc
, and you will need to provide aGlobalAlloc
, impl it or find a crate. In my project, i impl it like this:use core::alloc::{GlobalAlloc, Layout}; mod ffi { extern "C" { pub fn malloc(size: usize) -> *mut u8; pub fn free(ptr: *mut u8); } } pub struct IdfAlloc; unsafe impl GlobalAlloc for IdfAlloc { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { ffi::malloc(layout.size()) } unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { ffi::free(ptr); } } #[global_allocator] static ALLOC: IdfAlloc = IdfAlloc;
this need link to
newlib
ofesp-idf
to work. -
For API like
wifi
,bluetooth
,GPIO
, i just write ffi bindings toesp-idf
and link to them.