Fil-C on Nix

Filnix wiki

mbrock/filnix

compiler/filc0.nix

λpkgs, sources?
pkgs
sourcesdefault import../lib/sources.nix inherit pkgs;
let
7lib=
import../lib inherit pkgs;
9inherit lib
setupCcache
10stdlib=
pkgs.lib
12cmakeFlags=
lib.cmakeFlags or opts: stdlib.mapAttrsToListk: v: let val = if stdlib.isBoolv then if v then "ON" else "OFF" else toStringv; in "-D${k}=${val}" opts
uses lib stdlib used by filc0

Shared with shells/filc-llvm.nix so out-of-Nix builds match this one.

25cmakeOptions=
26CMAKE_BUILD_TYPE=
"RelWithDebInfo"
27LLVM_ENABLE_ASSERTIONS=
true
28LLVM_ENABLE_WARNINGS=
false
29LLVM_ENABLE_ZSTD=
false
30LLVM_TARGETS_TO_BUILD=
lib.llvmTarget
31LLVM_ENABLE_LIBXML2=
false
32LLVM_ENABLE_LIBEDIT=
false
33LLVM_ENABLE_LIBPFM=
false
34LLVM_ENABLE_ZLIB=
false
35LLVM_ENABLE_CURL=
false
36LLVM_ENABLE_HTTPLIB=
false
37LLVM_STATIC_LINK_CXX_STDLIB=
true
38CMAKE_EXE_LINKER_FLAGS=
"-static-libgcc"
39LLVM_USE_LINKER=
"gold"
40LLVM_ENABLE_PROJECTS=
"clang"
41LLVM_BINUTILS_INCDIR=
"${pkgs.binutils-unwrapped.dev}/include"
uses lib used by allOptions
in
46inherit
cmakeOptions
48filc0=
pkgs.ccacheStdenv.mkDerivation
49pname=
"filc0"

The LLVM build tree needs well over 100 GB; keep it off small remote builders, which advertise no big-parallel.

52requiredSystemFeatures=
"big-parallel"
53version=
"git"
54src=
sources.filc0-src
56outputs=
"out" "dev" "bin" "lib"

Records read from a precompiled header keep their union handling.

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.

79enableParallelBuilding=
true
81nativeBuildInputs=
with pkgs; cmake ninja python3 git patchelf ccache binutils
91configurePhase=
let
93allOptions=
cmakeOptions // CMAKE_INSTALL_PREFIX = "$TMPDIR/install";
in
export HOME=$TMPDIR
export HOSTNAME=nix-build
mkdir -p build
cmake -B build -S llvm -G Ninja ${stdlib.concatStringsSep" " cmakeFlagsallOptions}
106buildPhase=
NINJA_STATUS="[B %f/%t %es] " ninja -j$NIX_BUILD_CORES -v -C build clang
110installPhase=
# 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/
211meta=
212description=

Fil-C Clang compiler (LLVM stage only, pinned and isolated)

213outputsToInstall=
"out"