compiler/filc0.nix
λpkgs, sources?
| pkgs | |
| sources | default import../lib/sources.nix inherit pkgs; |
let
Shared with shells/filc-llvm.nix so out-of-Nix builds match this one.
"RelWithDebInfo"
true
false
false
false
false
false
false
false
false
true
"-static-libgcc"
"gold"
"clang"
uses lib used by allOptions
in
46inherit
cmakeOptions
pkgs.ccacheStdenv.mkDerivation
"filc0"
The LLVM build tree needs well over 100 GB; keep it off small remote builders, which advertise no big-parallel.
"big-parallel"
"git"
"out" "dev" "bin" "lib"
patches=
Records read from a precompiled header keep their union handling.
../patches/fil-c/clang-pch-has-union.patch ++ pkgs.lib.optionalsources.variant ≡ "staging" ../patches/fil-c/noinline-callee-users.patch ++ pkgs.lib.optionalsources.variant ≡ "staging" ../patches/fil-c/filpizlonator-zmark-shared.patch
Sealed closures (docs/sealed-closures.md): functions that read their callee are not inlined, so the read stays in the function it was written in.
zmark_shared's pass half (docs/zmark-shared.md); the runtime half is in runtime/libpizlo.nix. Staging only.
true
let
in
export HOME=$TMPDIR
export HOSTNAME=nix-build
${setupCcache}
mkdir -p build
cmake -B build -S llvm -G Ninja ${stdlib.concatStringsSep" " cmakeFlagsallOptions}
NINJA_STATUS="[B %f/%t %es] " ninja -j$NIX_BUILD_CORES -v -C build clang
# Install everything to a temporary location
NINJA_STATUS="[I %f/%t %es] " ninja -j$NIX_BUILD_CORES -v -C build install
cd $TMPDIR/install
# --- OUTPUT: out (essential compiler toolchain) ---
mkdir -p $out/bin
# Core compiler binary (clang is the real binary, others are symlinks)
cp -p bin/clang $out/bin/clang
# Create symlinks for clang variants (they share the same binary)
for tool in clang++ clang-20 clang-cl clang-cpp; do
if [ -e "bin/$tool" ]; then
ln -s clang $out/bin/$tool
fi
done
# Essential LLVM binary utilities (equivalent to GNU binutils)
# Note: Some of these are hard links to the same binary
# llvm-ar is the main binary, llvm-ranlib links to it
[ -e bin/llvm-ar ] && cp -p bin/llvm-ar $out/bin/
[ -e bin/llvm-ranlib ] && ln -s llvm-ar $out/bin/llvm-ranlib
# llvm-objcopy is the main binary, llvm-strip links to it
[ -e bin/llvm-objcopy ] && cp -p bin/llvm-objcopy $out/bin/
[ -e bin/llvm-strip ] && ln -s llvm-objcopy $out/bin/llvm-strip
# llvm-readobj is the main binary, llvm-readelf links to it
[ -e bin/llvm-readobj ] && cp -p bin/llvm-readobj $out/bin/
[ -e bin/llvm-readelf ] && ln -s llvm-readobj $out/bin/llvm-readelf
# These are typically standalone binaries
for tool in llvm-nm llvm-objdump llvm-size llvm-strings llvm-addr2line; do
[ -e "bin/$tool" ] && cp -p "bin/$tool" $out/bin/
done
# LLVM core tools for compilation pipeline
for tool in \
llvm-as llvm-dis \
llvm-link \
opt llc lli \
llvm-config; do
[ -e "bin/$tool" ] && cp -p "bin/$tool" $out/bin/
done
# Linker (lld is main binary, variants are symlinks)
[ -e bin/lld ] && cp -p bin/lld $out/bin/
for tool in ld.lld ld64.lld wasm-ld; do
[ -e "bin/$tool" ] && ln -s lld $out/bin/$tool
done
# Clang driver wrappers and resource tools
for tool in \
clang-linker-wrapper \
clang-offload-bundler clang-offload-packager; do
[ -e "bin/$tool" ] && cp -p "bin/$tool" $out/bin/
done
# Clang resource directory (headers, libs for compilation)
mkdir -p $out/lib
if [ -d lib/clang ]; then
cp -r lib/clang $out/lib/
fi
# Shared libraries needed at runtime (copy all symlinks and files)
if ls lib/libclang.so* 1> /dev/null 2>&1; then
cp -a lib/libclang.so* $out/lib/
fi
if ls lib/libclang-cpp.so* 1> /dev/null 2>&1; then
cp -a lib/libclang-cpp.so* $out/lib/
fi
if ls lib/libRemarks.so* 1> /dev/null 2>&1; then
cp -a lib/libRemarks.so* $out/lib/
fi
# --- OUTPUT: dev (headers + static libs for LLVM development) ---
mkdir -p $dev/include
cp -r include/* $dev/include/
mkdir -p $dev/lib
cp -p lib/*.a $dev/lib/ 2>/dev/null || true
# CMake files for find_package(LLVM) and find_package(Clang)
[ -d lib/cmake ] && cp -r lib/cmake $dev/lib/
# --- OUTPUT: bin (extra LLVM tools and utilities) ---
mkdir -p $bin/bin
for tool in bin/*; do
toolname=$(basename "$tool")
# Skip if already in $out
[ ! -e "$out/bin/$toolname" ] && cp -p "$tool" $bin/bin/
done
# --- OUTPUT: lib (documentation, helper scripts, misc) ---
[ -d libexec ] && mkdir -p $lib/libexec && cp -r libexec/* $lib/libexec/
[ -d share ] && mkdir -p $lib/share && cp -r share/* $lib/share/
uses cmakeFlags setupCcache stdlib