Hi all,
I’m trying to run the libc++ test suite using llvm-lit
on NixOS (I’m building LLVM from source). However, I’m running into the following fatal error when running the test suite:
llvm-lit: /home/omkar/Source/dev/llvm-project/llvm/utils/lit/lit/TestingConfig.py:157: fatal: unable to parse config file '/home/omkar/Source/dev/llvm-project/build-rt/libcxx/test/lit.site.cfg', traceback: Traceback (most recent call last):
File "/home/omkar/Source/dev/llvm-project/llvm/utils/lit/lit/TestingConfig.py", line 145, in load_from_path
exec(compile(data, path, "exec"), cfg_globals, None)
File "/home/omkar/Source/dev/llvm-project/build-rt/libcxx/test/lit.site.cfg", line 22, in <module>
libcxx.test.config.configure(
File "/home/omkar/Source/dev/llvm-project/libcxx/utils/libcxx/test/config.py", line 31, in configure
actions = param.getActions(config, lit_config.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/omkar/Source/dev/llvm-project/libcxx/utils/libcxx/test/dsl.py", line 832, in getActions
(_, parameterValue) = self._getValue(config, litParams)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/omkar/Source/dev/llvm-project/libcxx/utils/libcxx/test/dsl.py", line 807, in _getValue
value = getDefault()
^^^^^^^^^^^^
File "/home/omkar/Source/dev/llvm-project/libcxx/utils/libcxx/test/dsl.py", line 801, in <lambda>
lambda: self._default(config) if callable(self._default) else self._default
^^^^^^^^^^^^^^^^^^^^^
File "/home/omkar/Source/dev/llvm-project/libcxx/utils/libcxx/test/params.py", line 182, in <lambda>
default=lambda cfg: getDefaultStdValue(cfg),
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/omkar/Source/dev/llvm-project/libcxx/utils/libcxx/test/params.py", line 93, in getDefaultStdValue
raise RuntimeError(
RuntimeError: Unable to successfully detect the presence of any -std=c++NN flag. This likely indicates an issue with your compiler.
My flake.nix
{
description = "A Nix-flake-based c++ dev environment with clang";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs =
{ nixpkgs, ... }:
let
# system should match the system you are running on
# system = "x86_64-linux";
system = "x86_64-linux";
in
{
devShells."${system}".default =
let
pkgs = import nixpkgs {
inherit system;
};
inherit (pkgs)
lib
clangStdenv
targetPlatform
cmakeCurses
;
stdenv = clangStdenv;
llvmRuntimes = lib.concatStringsSep ";" [
"libcxx"
"libcxxabi"
"libunwind"
];
llvmProjects = lib.concatStringsSep ";" [ "clang" ];
llvmTargets = lib.concatStringsSep ";" [ "Native" ];
cmakeFlags = [
"-GNinja"
"-DCMAKE_CXX_COMPILER=clang++"
"-DCMAKE_C_COMPILER=clang"
"-DCMAKE_BUILD_TYPE=Debug"
"-DCMAKE_C_FLAGS=\"${flags}\""
"-DCMAKE_CXX_FLAGS=\"${flags}\""
"-DLLVM_ENABLE_PROJECTS=${llvmProjects}"
"-DLLVM_TARGETS_TO_BUILD=${llvmTargets}"
"-DC_INCLUDE_DIRS=${stdenv.cc.libc.dev}/include"
];
cmakeRuntimeFlags = [
"-DCMAKE_CXX_COMPILER=clang++"
"-DCMAKE_C_COMPILER=clang"
"-DLIBCXXABI_ENABLE_SHARED=ON"
"-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi;libunwind"
"-DLIBCXX_TEST_COMPILER_FLAGS=\"${flags}\""
"-DLIBCXX_TEST_LINKER_FLAGS=\"${flags}\""
];
builddir = "build";
gccForLibs = stdenv.cc.cc;
dynLinker = lib.fileContents "${stdenv.cc}/nix-support/dynamic-linker";
libcFlags = [
"-L ${stdenv.cc.libc}/lib"
"-B ${stdenv.cc.libc}/lib"
];
# The string version of just the gcc flags for NIX_LDFLAGS
nixLd = lib.concatStringsSep " " [
"-L ${gccForLibs}/lib"
"-L ${gccForLibs}/lib/clang/${targetPlatform.config}/${gccForLibs.version}"
];
gccFlags = [
"-B ${gccForLibs}/lib/clang/${targetPlatform.config}/${gccForLibs.version}"
"${nixLd}"
];
flags = lib.concatStringsSep " " (
[
"-Wno-unused-command-line-argument"
"-Wl,--dynamic-linker=${dynLinker}"
]
++ gccFlags
++ libcFlags
);
cmakeCmd = [
"${cmakeCurses}/bin/cmake -B ${builddir} --fresh -S llvm"
] ++ cmakeFlags;
cmakeRtCmd = [
"${cmakeCurses}/bin/cmake -B ${builddir}-rt -S runtimes"
] ++ cmakeRuntimeFlags;
in
pkgs.mkShell.override
{
stdenv = pkgs.clangStdenv;
}
{
nativeBuildInputs = with pkgs; [
python3
ninja
zlib
];
buildInputs = with pkgs; [
python313Packages.pyyaml
cmake
llvmPackages.llvm
llvmPackages.libcxx
llvmPackages.clang
llvmPackages.bintools
python313Packages.lit
];
shellHook = ''
echo "`clang --version`"
echo "Enabled Runtimes : $llvmRuntimes"
echo "Enabled Projects : $llvmProjects"
echo "Targets being build : $llvmTargets"
'';
inherit
llvmRuntimes
llvmProjects
llvmTargets
cmakeRuntimeFlags
cmakeFlags
cmakeRtCmd
cmakeCmd
;
# where to find libgcc
NIX_LDFLAGS = "${nixLd}";
# teach clang about C startup file locations
CFLAGS = "${flags}";
CXXFLAGS = "${flags}";
};
};
}
I built llvm and clang using eval "$cmakeCmd"
.
I built the runtimes using cmake $cmakeRuntimes -B build-rt ./runtimes