This seems to fix the notorious "CommandLine Error: Option 'xxxxx'
registered more than once!" error in applications that use both Mesa and
ROCm.
Since Mesa is built with llvmPackages_latest and ROCm stuff is built
with llvmPackages_rocm, applications that use both (such as Blender) end
up with two different `libLLVM*.so`s loaded, which breaks things.
This seems like a straightforward way to fix the problem, and since the
ROCm stack seems to be the only thing in Nixpkgs that uses
llvmPackages_rocm this hopefully shouldn't break anything.
While there might be another way to fix this problem that doesn't
require disabling the shared libraries, I haven't been able to find it
yet, and since this issue seems to affect a lot of people I think it
might make sense to merge this fix for now and revisit it later if a
better solution is found.
This also removes a small patch to rocm-comgr since there are no longer
LLVM shared libraries for it to link against.
This fixes a CI warning [0]:
Run cat "$HOME/changed_files" | xargs -r editorconfig-checker -disable-indent-size
pkgs/development/compilers/llvm/14/lld/default.nix:
28: Wrong indent style found (tabs instead of spaces)
29: Wrong indent style found (tabs instead of spaces)
30: Wrong indent style found (tabs instead of spaces)
[0]: https://github.com/NixOS/nixpkgs/runs/5351700772
substituteStream(): WARNING: pattern '# define _LIBCPP_USE_AVAILABILITY_APPLE' doesn't match anything in file 'include/__config'
The new mechanism for those is a cmake option
LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS that is off by default:
https://reviews.llvm.org/D90843
libcxxClang still depends on cc wrapper's gccForLibs for libgcc which is
not available when useLLVM is set. In such cases we need to switch to
clangUseLLVM and (try) to use compiler-rt instead.
Resolves#153759: pkgsLLVM.llvmPackages.stdenv now correctly
clangUseLLVM as cc, allowing compilation to work as expected.
llvmPackages_*.clang should check the default compiler for the package
set it is targeting (targetPackages.stdenv.cc) instead of the compiler
that has been used to build it (stdenv.cc) in order to get some sense of
whether to use libc++ or libstdc++.
Since we are now inspecting targetPackages in the llvmPackages.clang
attribute, we need to avoid using it in the cross stdenv — which just
forces us to explicitly request libcxxClang for darwin instead of
relying on the clang attribute to pick it for us.
We also need to do something similar for targetPackages.stdenv.cc: Here
the llvmPackages.clang logic would work as we want (inspect
targetPackages.stdenv.cc and if it doesn't exist, make the choice based
on stdenv.cc), but it gets locked in a cycle with the previous package.
We can easily break this, however: We know that the previous set had
clang and the next one doesn't exist, so we'd choose libcxxClang any day
of the week.
LLVM 12 added the memory profiling runtime and LLVM 13 the ORC
runtime. Both need a libc in order to build (or at least headers not
present in clang's resource root), so we'll disable them for any sort of
baremetal-ish build. memprof likely doesn't work in a baremetal
situation at all, orc is unknown. Whether both would compile with musl
is to be checked.
The main thing we need to pass LLVM_ENABLE_PIC=OFF to prevent LLVM from
building shared objects because our cc-wrapper is incapable of producing
shared objects. Building LLVM statically also influences other LLVM
projects like clang and lld -- which can be built linked fully
statically with this change.
To make the value of doCheck in the argument attribute set accurate we
also need to include the condition for cross compilation which normally
is added by stdenv.mkDerivation.
LLVM's build system creates NATIVE/bin/llvm-config by reexecuting cmake
with entirely new flags. Problematically, the `CMAKE_INSTALL_*` flags
are not inherited, causing llvm-config-native to return wrong
installation paths, e. g. CMAKE_INSTALL_LIBDIR would default to `lib64`
on x86_64-linux. Previously this was masked by outputs.patch which
replaced ActiveLibDir with a string passed in from Nix, however
`--cmakedir` for example would turn out to be wrong always, breaking
cross-compilation of e. g. lld.
Additionally LLVM_ENABLE_RTTI needs to be repassed, as it is used to
determine if RTTI is available. Passing LLVM_LINK_LLVM_DYLIB is crucial
if we are building LLVM non-statically: It influences the --shared-mode
flag (which should indicate that -lLLVM is enough to link all
components) and makes --link-shared work in the first place,
i. e. llvm-config-native believes the built shared libs don't exist
unless we repass this flag.
Passing LLVM_LINK_LLVM_DYLIB=ON, however, makes the native build produce
a full libLLVM.so which is something we don't want, so we introduce a
patch which forces llvm-config to link statically against the LLVM
components it needs.
Starting with LLVM 8, clang does no longer use llvm-config to detect the
LLVM installation: https://github.com/llvm/llvm-project/commit/e4faa5c7986b7
Consequently, there is no point passing LLVM_CONFIG_PATH (in fact the
variable is unused currently).