This is my overlay for musl & clang & systemd & arm64.
The patches and changes in it may only apply to me, so it is not recommended to use it directly. Please follow the official instruction to add this overlay, and mask/unmask ebuild you don't want/want, otherwise your system may break after installing some ebuild only for musl.
(Note that some text here shows LLVM version 22, if you are building for 21 substitute that value where appropriate)
- Create
crossdevoverlay
(Easiest with eselect repository create crossdev)
Symlink cmake.eclass in this overlay to crossdev
ln -s 12101111-overlay/eclass crossdev/eclass- Create crossdev wrapper
crossdev -L -t wasm32-wasip1This will fail with the message: error: Target architecture not supported by installed LLVM toolchain. This is expected as Gentoo doesn't have official wasm32-wasi support.
Symlink llvm-runtimes in this overlay to crossdev (possible that crossdev will do some of this for you, likely first five lines)
ln -s ../../12101111-overlay/sys-devel/clang-crossdev-wrappers crossdev/cross_llvm-wasm32-wasip1
ln -s ../../12101111-overlay/llvm-runtimes/compiler-rt crossdev/cross_llvm-wasm32-wasip1
ln -s ../../12101111-overlay/llvm-runtimes/libcxx crossdev/cross_llvm-wasm32-wasip1
ln -s ../../12101111-overlay/llvm-runtimes/libcxxabi crossdev/cross_llvm-wasm32-wasip1
ln -s ../../12101111-overlay/llvm-runtimes/libunwind crossdev/cross_llvm-wasm32-wasip1
ln -s ../../12101111-overlay/sys-devel/rust-std crossdev/cross_llvm-wasm32-wasip1
ln -s ../../12101111-overlay/dev-libs/wasi-libc crossdev/cross_llvm-wasm32-wasip1- Edit configs
Append these flags to /etc/portage/env/cross_llvm-wasm32-wasip1/llvm.conf:
AS="wasm32-wasip1-as"
CPP="wasm32-wasip1-cpp"
CFLAGS="-Os -pipe -mcpu=lime1"
CXXFLAGS="-Os -pipe -mcpu=lime1"
LDFLAGS=""
RUSTFLAGS="-Ctarget-cpu=lime1 -Copt-level=s -Ccodegen-units=1"Append these flags to /etc/portage/package.env/cross_llvm-wasm32-wasip1:
cross_llvm-wasm32-wasip1/wasi-libc cross_llvm-wasm32-wasip1/wasi-libc.conf
cross_llvm-wasm32-wasip1/wasi-libc cross_llvm-wasm32-wasip1/llvm.conf
cross_llvm-wasm32-wasip1/libcxxabi cross_llvm-wasm32-wasip1/libcxx.conf
cross_llvm-wasm32-wasip1/libcxxabi cross_llvm-wasm32-wasip1/llvm.confThen, to create wasi-libc.conf:
cp /etc/portage/env/cross_llvm-wasm32-wasip1/{linux-headers.conf,wasi-libc.conf}Remove @../gentoo-runtimes.cfg in /etc/clang/cross/wasm32-wasip1.cfg and append these flags:
--sysroot=/usr/wasm32-wasip1
--target=wasm32-wasip1
--rtlib=compiler-rt
--stdlib=libc++
--unwindlib=none- Install packages:
emerge cross_llvm-wasm32-wasip1/clang-crossdev-wrappers
emerge cross_llvm-wasm32-wasip1/compiler-rtCheck compiler-rt is compiled correctly:
llvm-readelf -h /usr/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a | grep WASM | wc -l
# should output number like 150
llvm-readelf -h /usr/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a | grep ELF
# should output nothing
(this will need to be unmasked)
emerge cross_llvm-wasm32-wasip1/wasi-libcCheck wasi-libc is compiled correctly (wasmtime can be installed with cargo or in dev-util/wasm-tools):
cat << EOF > /tmp/hello.c
#include <stdio.h>
int main() {
printf("Hello world!\n");
return 0;
}
EOF
wasm32-wasip1-cc /tmp/hello.c -Os -o /tmp/hello.wasm
wasmtime /tmp/hello.wasmInstall C++ std (unmask for 21 or 22):
emerge cross_llvm-wasm32-wasip1/libcxxabi
emerge cross_llvm-wasm32-wasip1/libcxxCheck libc++ is compiled correctly:
cat << EOF > /tmp/hello.cpp
#include <iostream>
int main() {
std::cout << "Gentoo Linux Clang/LLVM/LLD toolchain for WASI!" << std::endl;
return 0;
}
EOF
wasm32-wasip1-c++ /tmp/hello.cpp -fno-exceptions -Os -o /tmp/hello.wasm
wasmtime /tmp/hello.wasmInstall Rust std (need at least Rust 1.94.1 for this):
/etc/portage/package.accept_keywords/cross_llvm-wasm32-wasip1
cross_llvm-wasm32-wasip1/rust-std **
emerge cross_llvm-wasm32-wasip1/rust-stdCheck Rust-std is compiled correctly:
/usr/bin/cargo new hello
cd hello
/usr/bin/cargo build -r --target wasm32-wasip1
wasmtime target/wasm32-wasip1/release/hello.wasm- Setup portage
Most packages don't work under wasm32-wasi. But if you want try it, set those flags.
/usr/wasm32-wasip1/etc/portage/profile/make.defaults
ARCH="wasm32"
KERNEL="wasi"
ELIBC="wasip1"
AS=wasm32-wasip1-as
CPP=wasm32-wasip1-cpp
CC="wasm32-wasip1-clang"
CXX="wasm32-wasip1-clang++"
LD=wasm-ld/usr/wasm32-wasip1/etc/portage/repos.conf
[DEFAULT]
main-repo = gentoo
[gentoo]
location = <fill this>
[12101111-overlay]
location = <fill this>
priority = 1000- app-doc/zeal: Live ebuild, use qtwebengine as backend.
- app-editors/vnote: Vnote 2 and vnotex 3.
- app-editors/vscode: Build vscode from source code.
- app-text/goldendict: Live ebuild of xiaoyifang's fork, use qtwebengine as backend.
- dev-java/openjdk: Fix for clang and musl.
- dev-lang/deno: A modern runtime for JavaScript and TypeScript.
- dev-lang/luajit: OpenResty's fork of LuaJIT.
- dev-lang/rust: Add libcxx, profiler, sanitizers support. fix for musl system. add wasm32-wasi support.
- dev-libs/mimalloc: Build static and object files.
- dev-libs/wasi-libc: Live ebuild for wasi-libc, used in rust support for wasm32-wasi.
- dev-util/electron: Build Electron from source code. Fix for musl.
- dev-util/electron-bin: Electron built by upstream for glibc.
- dev-util/mingw64-toolchain: ignore USE=-abi_x86_32 and build as multilib toolchain on musl.
- dev-util/cemu: Fix for musl, currently one minor version behind.
- gui-apps/waybar: Libcxx support.
- gui-apps/wob: Live ebuild.
- sys-apps/busybox: Fix for clang.
- sys-apps/systemd: systemd with musl patches from openembedded. Use with
12101111-overlay:clang/musl/<arch>/systemdprofile. - sys-boot/m1n1: First stage bootloader for Apple Silicon computer. Update the binary using sys-boot/m1n1/files/update-m1n1.
- sys-boot/uboot-asahi: Second stage bootloader for Apple Silicon computer.
- sys-devel/binutils: GNU binutils ebuild that can disable most component. Useful for llvm binutils users
- sys-fs/zfs: Fix systemd support for musl.
- sys-libs/gcompat: gcompat with more symbol. Keep for history reason.
- sys-libs/libexecinfo:
backtracefrom NetBSD. - sys-libs/musl: Fix for chromium's partation allocator. Change the default allocator to rpmalloc. Update some assembly code.
- sys-libs/musl-legacy-compat. Some header files from voidlinux.
- virtual/fortran:
add llvm-core/flang - www-client/chromium: Fix for musl.
- www-client/firefox: Enable C++/Rust cross language LTO & PGO.
- x11-misc/rofi: ebuild of wayland fork
All ebuild files are distributed under the terms of the GNU General Public License v2.
The following ebuild are not a fork from Gentoo main tree or GURU Project:
app-editors/vnote:2: jorgicio overlayapp-editors/vscode: this overlaydev-util/electron: electron overlaysys-boot/m1n1: this overlaysys-boot/uboot-asahi: this overlaysys-libs/gcompat: lanodan overlaysys-libs/libexecinfo: original from Voidlinux and FreeBSD, port to NetBSD source by myself.sys-libs/musl-legacy-compat: Voidlinux
All patch files are distributed under the same license of the corresponding package.
The following patches are not a fork from Gentoo main tree, musl overlay or GURU Project
www-client/chromiumanddev-util/electron: Alpine Linux and Voidlinux