Created
October 6, 2024 01:02
-
-
Save U007D/33a4cc3d01c45c04626958a7a166bbbd to your computer and use it in GitHub Desktop.
Building `mos-rust` from source
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Note: `mos-rust` is available via https://hub.docker.com. But if you're not on `amd64` and don't mind potentially stale builds | |
(the docker image is 8 months old and 19,980 commits behind `llvm-mos` as of the time of this writing). | |
# Installation | |
## 1. Build & install `llvm-mos` to `/opt/llvm-mos` | |
### macOS | |
```fish | |
sudo mkdir /opt/llvm-mos | |
sudo chwown "$(whoami)" /opt/llvm-mos | |
git clone https://github.com/llvm-mos/llvm-mos | |
cd llvm-mos | |
cmake -C clang/cmake/caches/MOS.cmake -G "Ninja" -S llvm -B build -DCMAKE_INSTALL_PREFIX=/opt/llvm-mos -DLLVM_INSTALL_TOOLCHAIN_ONLY=OFF -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON -DLLVM_INSTALL_UTILS=ON -DLLVM_BUILD_UTILS=ON -DLLVM_TOOLCHAIN_UTILITIES=FileCheck -DLLVM_TOOLCHAIN_TOOLS="llvm-addr2line;llvm-ar;llvm-cxxfilt;llvm-dwarfdump;llvm-mc;llvm-nm;llvm-objcopy;llvm-objdump;llvm-ranlib;llvm-readelf;llvm-readobj;llvm-size;llvm-strings;llvm-strip;llvm-symbolizer;llvm-config;llc" -DLIBXML2_LIBRARY=/usr/local/opt/libxml2/lib/libxml2.dylib -DLLVM_TARGETS_TO_BUILD="MOS;AArch64" -DCMAKE_BUILD_TYPE=Release | |
cmake --build build -t install | |
# Wait about 8 minutes; there will be a few warnings | |
fish_add_path -a "/opt/llvm-mos/bin" "/opt/llvm-mos" | |
``` | |
### Linux (incomplete) | |
```bash | |
sudo mkdir /opt/llvm-mos | |
sudo chwown "$(whoami)" /opt/llvm-mos | |
git clone https://github.com/llvm-mos/llvm-mos | |
cd llvm-mos | |
cmake -C clang/cmake/caches/MOS.cmake -G "Ninja" -S llvm -B build \ | |
-DCMAKE_INSTALL_PREFIX=/opt/llvm-mos \ | |
-DLLVM_INSTALL_TOOLCHAIN_ONLY=OFF \ | |
-DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON \ | |
-DLLVM_INSTALL_UTILS=ON -DLLVM_BUILD_UTILS=ON -DLLVM_TOOLCHAIN_UTILITIES=FileCheck \ | |
-DLLVM_TOOLCHAIN_TOOLS="llvm-addr2line;llvm-ar;llvm-cxxfilt;llvm-dwarfdump;llvm-mc;llvm-nm;llvm-objcopy;llvm-objdump;llvm-ranlib;llvm-readelf;llvm-readobj;llvm-size;llvm-strings;llvm-strip;llvm-symbolizer;llvm-config;llc" \ | |
-DLIBXML2_LIBRARY=/usr/lib/x86_64-linux-gnu/libxml2.so \ | |
-DLLVM_TARGETS_TO_BUILD="MOS;X86" \ | |
-DLLVM_ENABLE_PROJECTS="clang;lld;lldb" # remove this line if you see strange errors | |
cmake --build build -t install | |
fish_add_path -a "/opt/llvm-mos/bin" "/opt/llvm-mos" | |
``` | |
## 2. Build & install `llvm-mos-sdk` to `llvm-mos` | |
### All Unix platforms | |
```fish | |
git clone https://github.com/llvm-mos/llvm-mos-sdk | |
cd llvm-mos-sdk | |
cmake -S . -B build -G "Ninja" -DCMAKE_INSTALL_PREFIX=/opt/llvm-mos | |
cmake --build build -t install | |
``` | |
## 3. Build & install `rust-mos` Rust compiler | |
export RUST_TARGET_PATH=/opt/rust-mos-targets/ | |
cp config.toml.example config.toml # even though there's a (smaller) `config.toml` there already | |
# in config.toml adjust path to llvm-config | |
llvm-config = "/opt/llvm-mos/bin/llvm-config" | |
# add 'download-ci-llvm = false' commenting out existing `download-ci-live` line (currently l.53 | |
# comment out '# llvm-has-rust-patches = if llvm-config { false } else { true }' line (currently l.777) | |
./x.py build -i --stage 0 src/tools/cargo # seems like `rust-mos` builds its own llvm here; is `llvm-mos` even needed? | |
./x.py build -i | |
ln -s ../../stage0-tools-bin/cargo build/aarch64-apple-darwin/stage1/bin/cargo | |
rustup toolchain link mos build/aarch64-apple-darwin/stage1 | |
rustup default mos | |
mkdir -p $RUST_TARGET_PATH # may require `sudo` if `$RUST_TARGET_PATH` is in a protected folder | |
sudo chown u007d $RUST_TARGET_PATH # if `mkdir -p $RUST_TARGET_PATH` required `sudo` | |
python3 create_mos_targets.py $RUST_TARGET_PATH # <-- failing here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment