Skip to content

Instantly share code, notes, and snippets.

@theoparis
Last active October 15, 2024 07:27
Show Gist options
  • Save theoparis/9bfe099cd3aee6cbbecebc1b01de0322 to your computer and use it in GitHub Desktop.
Save theoparis/9bfe099cd3aee6cbbecebc1b01de0322 to your computer and use it in GitHub Desktop.
llvm-project git build with nix (without runtimes, clangir enabled, using mold as the linker)
{
src,
targets ? "host",
projects ? "clang;lld;mlir;libc",
stdenv,
cmakeMinimal,
ninja,
python313,
mold,
}:
{
llvm-project = stdenv.mkDerivation {
name = "llvm-project";
version = "20.0.0.git";
src = src;
cmakeFlags = [
"-DC_INCLUDE_DIRS=${stdenv.cc.libc.dev}/include"
"-GNinja"
"-DCMAKE_BUILD_TYPE=MinSizeRel"
"-DCMAKE_INSTALL_PREFIX=$out"
# Reduce installation size by using a single 'llvm' binary with symlinks
"-DLLVM_TOOL_LLVM_DRIVER_BUILD=ON"
"-DLLVM_ENABLE_PROJECTS=${projects}"
"-DLIBC_HDRGEN_ONLY=ON"
"-DLLVM_LIBC_FULL_BUILD=ON"
"-DLLVM_TARGETS_TO_BUILD=${targets}"
"-DCLANG_ENABLE_CIR=ON"
"-DCLANG_DEFAULT_CXX_STDLIB=libc++"
"-DCLANG_DEFAULT_UNWINDLIB=libunwind"
"-DCLANG_DEFAULT_RTLIB=compiler-rt"
"-DMLIR_ENABLE_SPIRV_CPU_RUNNER=ON"
"-DMLIR_ENABLE_EXECUTION_ENGINE=ON"
"-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=all"
"-DLLVM_USE_LINKER=mold"
"-S${src}/llvm"
];
nativeBuildInputs = [
cmakeMinimal
ninja
python313
mold
];
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment