Trying to compile Rust code to C code through LLVM CBE.
Rust code is taken from Getting Started with ECS using Planck ECS.
Install LLVM 11 and cmake with Homebrew
brew install llvm@11 cmake
Pull in the LLVM CBE repo
git submodule init
git submodule update
Configure and build
cd llvm-cbe
mkdir build && cd build
LLVM_DIR="$(brew --prefix)/opt/llvm@11/lib/cmake/llvm" cmake -S ..
make llvm-cbe
The result will be at rust2c-llvm-cbe/llvm-cbe/build/tools/llvm-cbe/llvm-cbe
.
The last stable version using LLVM 11 is 1.50.0 so we change to that with rustup. In project root run:
rustup toolchain install 1.50.0
rustup override set 1.50.0
There is a bug so we disable incremental build
mkdir -p .cargo
echo 'build.incremental = false' >> .cargo/config.toml
Finally we emit LLVM IR:
cargo rustc -- --emit=llvm-ir
The results will be in rust2c-llvm-cbe/target/debug/deps
with suffix .ll
.
sh build.sh
Cross build the Rust part of pyca/cryptography to m86k.