summary refs log tree commit diff
path: root/pkgs/development/compilers/llvm
diff options
context:
space:
mode:
authorSebastian Neubauer <Sebastian.Neubauer@amd.com>2022-08-16 19:20:55 +0200
committerSebastian Neubauer <Sebastian.Neubauer@amd.com>2022-08-16 19:20:55 +0200
commitec590fdd24430f672bec6704c6507e59d72a60b5 (patch)
tree67c067132650256325e3a5eeb749b675eac3bff5 /pkgs/development/compilers/llvm
parent9513a3b0c20b34582ee186cb0677d8aff1117941 (diff)
downloadnixpkgs-ec590fdd24430f672bec6704c6507e59d72a60b5.tar
nixpkgs-ec590fdd24430f672bec6704c6507e59d72a60b5.tar.gz
nixpkgs-ec590fdd24430f672bec6704c6507e59d72a60b5.tar.bz2
nixpkgs-ec590fdd24430f672bec6704c6507e59d72a60b5.tar.lz
nixpkgs-ec590fdd24430f672bec6704c6507e59d72a60b5.tar.xz
nixpkgs-ec590fdd24430f672bec6704c6507e59d72a60b5.tar.zst
nixpkgs-ec590fdd24430f672bec6704c6507e59d72a60b5.zip
llvmPackages_rocm: compile as one derivation
This is the supported way rocm is tested.
It makes packaging in nix a *lot* easier (see the code size).

An important change is the dontLink detection in the clang/clang++
wrapper script: When compiling with --cuda-device-only,
the linker must not be set, otherwise e.g. the blender kernels fail to
compile.
Diffstat (limited to 'pkgs/development/compilers/llvm')
-rw-r--r--pkgs/development/compilers/llvm/rocm/clang.nix72
-rw-r--r--pkgs/development/compilers/llvm/rocm/compiler-rt/default.nix64
-rw-r--r--pkgs/development/compilers/llvm/rocm/default.nix35
-rw-r--r--pkgs/development/compilers/llvm/rocm/install-symlinks.patch23
-rw-r--r--pkgs/development/compilers/llvm/rocm/lld.nix43
-rw-r--r--pkgs/development/compilers/llvm/rocm/llvm.nix (renamed from pkgs/development/compilers/llvm/rocm/llvm/default.nix)55
-rw-r--r--pkgs/development/compilers/llvm/rocm/llvm/outputs.patch16
7 files changed, 49 insertions, 259 deletions
diff --git a/pkgs/development/compilers/llvm/rocm/clang.nix b/pkgs/development/compilers/llvm/rocm/clang.nix
deleted file mode 100644
index 2fac661b58a..00000000000
--- a/pkgs/development/compilers/llvm/rocm/clang.nix
+++ /dev/null
@@ -1,72 +0,0 @@
-{ stdenv
-, lib
-, fetchFromGitHub
-, cmake
-, python3
-, llvm
-, clang-tools-extra_src ? null
-, lld
-
-, version
-, src
-}:
-
-stdenv.mkDerivation rec {
-  inherit version src;
-
-  pname = "clang";
-
-  nativeBuildInputs = [ cmake python3 ];
-
-  buildInputs = [ llvm ];
-
-  hardeningDisable = [ "all" ];
-
-  cmakeFlags = [
-    "-DLLVM_CMAKE_PATH=${llvm}/lib/cmake/llvm"
-    "-DLLVM_MAIN_SRC_DIR=${llvm.src}"
-    "-DCLANG_SOURCE_DIR=${src}"
-    "-DLLVM_ENABLE_RTTI=ON"
-  ];
-
-  VCSVersion = ''
-    #undef LLVM_REVISION
-    #undef LLVM_REPOSITORY
-    #undef CLANG_REVISION
-    #undef CLANG_REPOSITORY
-  '';
-
-  postUnpack = lib.optionalString (!(isNull clang-tools-extra_src)) ''
-    ln -s ${clang-tools-extra_src} $sourceRoot/tools/extra
-  '';
-
-  # Rather than let cmake extract version information from LLVM or
-  # clang source control repositories, we generate the wanted
-  # `VCSVersion.inc` file ourselves and remove it from the
-  # depencencies of the `clangBasic` target.
-  preConfigure = ''
-    sed 's/  ''${version_inc}//' -i lib/Basic/CMakeLists.txt
-    sed 's|sys::path::parent_path(BundlerExecutable)|StringRef("${llvm}/bin")|' -i tools/clang-offload-bundler/ClangOffloadBundler.cpp
-    sed 's|\([[:space:]]*std::string Linker = \)getToolChain().GetProgramPath(getShortName())|\1"${lld}/bin/ld.lld"|' -i lib/Driver/ToolChains/AMDGPU.cpp
-    substituteInPlace lib/Driver/ToolChains/AMDGPU.h --replace ld.lld ${lld}/bin/ld.lld
-    sed 's|configure_file(AST/gen_ast_dump_json_test.py ''${LLVM_TOOLS_BINARY_DIR}/gen_ast_dump_json_test.py COPYONLY)||' -i test/CMakeLists.txt
-  '';
-
-  postConfigure = ''
-    mkdir -p lib/Basic
-    echo "$VCSVersion" > lib/Basic/VCSVersion.inc
-  '';
-
-  passthru = {
-    isClang = true;
-    inherit llvm;
-  };
-
-  meta = with lib; {
-    description = "ROCm fork of the clang C/C++/Objective-C/Objective-C++ LLVM compiler frontend";
-    homepage = "https://llvm.org/";
-    license = with licenses; [ ncsa ];
-    maintainers = with maintainers; [ acowley lovesegfault ];
-    platforms = platforms.linux;
-  };
-}
diff --git a/pkgs/development/compilers/llvm/rocm/compiler-rt/default.nix b/pkgs/development/compilers/llvm/rocm/compiler-rt/default.nix
deleted file mode 100644
index dfc21e7fe01..00000000000
--- a/pkgs/development/compilers/llvm/rocm/compiler-rt/default.nix
+++ /dev/null
@@ -1,64 +0,0 @@
-{ stdenv, lib, version, src, cmake, python3, llvm, libcxxabi, fetchpatch }:
-stdenv.mkDerivation rec {
-  pname = "compiler-rt";
-  inherit version src;
-
-  nativeBuildInputs = [ cmake python3 llvm ];
-
-  NIX_CFLAGS_COMPILE = [
-    "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0"
-  ];
-
-  cmakeFlags = [
-    "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON"
-    "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}"
-    "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}"
-    "-DCOMPILER_RT_BUILD_SANITIZERS=OFF"
-    "-DCOMPILER_RT_BUILD_XRAY=OFF"
-    "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF"
-    "-DCOMPILER_RT_BUILD_PROFILE=OFF"
-    "-DCMAKE_C_COMPILER_WORKS=ON"
-    "-DCMAKE_CXX_COMPILER_WORKS=ON"
-    "-DCOMPILER_RT_BAREMETAL_BUILD=ON"
-    "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}"
-    "-DCOMPILER_RT_BUILD_BUILTINS=ON"
-    "-DCMAKE_C_FLAGS=-nodefaultlibs"
-    #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program
-    "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY"
-  ];
-
-  outputs = [ "out" "dev" ];
-
-  prePatch = ''
-    cd compiler-rt
-  '';
-
-  # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks
-  # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra
-  # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd
-  # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by
-  # a flag and turn the flag off during the stdenv build.
-  postPatch = lib.optionalString (!stdenv.isDarwin) ''
-    substituteInPlace cmake/builtin-config-ix.cmake \
-      --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)'
-  '';
-
-  # Hack around weird upsream RPATH bug
-  postInstall = ''
-    ln -s "$out/lib"/*/* "$out/lib"
-    ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o
-    ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o
-    ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o
-    ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o
-  '';
-
-  enableParallelBuilding = true;
-
-  meta = with lib; {
-    description = "ROCm fork of the LLVM Compiler runtime libraries";
-    homepage = "https://github.com/RadeonOpenCompute/llvm-project";
-    license = licenses.ncsa;
-    maintainers = with maintainers; [ acowley lovesegfault ];
-    platforms = platforms.linux;
-  };
-}
diff --git a/pkgs/development/compilers/llvm/rocm/default.nix b/pkgs/development/compilers/llvm/rocm/default.nix
index a2c269251d1..20c1a20b68a 100644
--- a/pkgs/development/compilers/llvm/rocm/default.nix
+++ b/pkgs/development/compilers/llvm/rocm/default.nix
@@ -10,23 +10,27 @@ let
   };
 in rec {
   clang = wrapCCWith rec {
-    cc = clang-unwrapped;
+    cc = llvm;
     extraBuildCommands = ''
       clang_version=`${cc}/bin/clang -v 2>&1 | grep "clang version " | grep -E -o "[0-9.-]+"`
       rsrc="$out/resource-root"
       mkdir "$rsrc"
       ln -s "${cc}/lib/clang/$clang_version/include" "$rsrc"
-      ln -s "${compiler-rt}/lib" "$rsrc/lib"
+      ln -s "${cc}/lib/clang/$clang_version/lib" "$rsrc/lib"
       echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
       echo "--gcc-toolchain=${stdenv.cc.cc}" >> $out/nix-support/cc-cflags
-      echo "-Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags
       rm $out/nix-support/add-hardening.sh
       touch $out/nix-support/add-hardening.sh
+      # GPU compilation uses builtin lld
+      substituteInPlace $out/bin/clang \
+        --replace '-MM) dontLink=1 ;;' $'-MM | --cuda-device-only) dontLink=1 ;;\n--cuda-host-only | --cuda-compile-host-device) dontLink=0 ;;'
+      substituteInPlace $out/bin/clang++ \
+        --replace '-MM) dontLink=1 ;;' $'-MM | --cuda-device-only) dontLink=1 ;;\n--cuda-host-only | --cuda-compile-host-device) dontLink=0 ;;'
     '';
   };
 
   clangNoCompilerRt = wrapCCWith rec {
-    cc = clang-unwrapped;
+    cc = llvm;
     extraBuildCommands = ''
       clang_version=`${cc}/bin/clang -v 2>&1 | grep "clang version " | grep -E -o "[0-9.-]+"`
       rsrc="$out/resource-root"
@@ -34,28 +38,17 @@ in rec {
       ln -s "${cc}/lib/clang/$clang_version/include" "$rsrc"
       echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
       echo "--gcc-toolchain=${stdenv.cc.cc}" >> $out/nix-support/cc-cflags
-      echo "-Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags
       rm $out/nix-support/add-hardening.sh
       touch $out/nix-support/add-hardening.sh
+      # GPU compilation uses builtin lld
+      substituteInPlace $out/bin/clang \
+        --replace '-MM) dontLink=1 ;;' $'-MM | --cuda-device-only) dontLink=1 ;;\n--cuda-host-only | --cuda-compile-host-device) dontLink=0 ;;'
+      substituteInPlace $out/bin/clang++ \
+        --replace '-MM) dontLink=1 ;;' $'-MM | --cuda-device-only) dontLink=1 ;;\n--cuda-host-only | --cuda-compile-host-device) dontLink=0 ;;'
     '';
   };
 
-  clang-unwrapped = callPackage ./clang.nix {
-    inherit lld llvm version;
-    src = "${src}/clang";
-  };
-
-  compiler-rt = callPackage ./compiler-rt {
-    inherit version llvm;
-    inherit src;
-    stdenv = overrideCC stdenv clangNoCompilerRt;
-  };
-
-  lld = callPackage ./lld.nix {
-    inherit llvm src version;
-  };
-
-  llvm = callPackage ./llvm {
+  llvm = callPackage ./llvm.nix {
     inherit src version;
   };
 }
diff --git a/pkgs/development/compilers/llvm/rocm/install-symlinks.patch b/pkgs/development/compilers/llvm/rocm/install-symlinks.patch
new file mode 100644
index 00000000000..8d9bb83632d
--- /dev/null
+++ b/pkgs/development/compilers/llvm/rocm/install-symlinks.patch
@@ -0,0 +1,23 @@
+diff --git a/llvm/cmake/modules/LLVMInstallSymlink.cmake b/llvm/cmake/modules/LLVMInstallSymlink.cmake
+index b5c35f706cb7..ac25e40b1436 100644
+--- a/cmake/modules/LLVMInstallSymlink.cmake
++++ b/cmake/modules/LLVMInstallSymlink.cmake
+@@ -4,11 +4,16 @@
+ 
+ include(GNUInstallDirs)
+ 
++set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../../../cmake/Modules" ${CMAKE_MODULE_PATH})
++include(ExtendPath)
++
+ function(install_symlink name target outdir)
+   set(DESTDIR $ENV{DESTDIR})
+-  set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}")
++  message(STATUS "Creating ${name} at ${bindir} (${CMAKE_MODULE_PATH})")
++  extend_path(prefixed_outdir "${CMAKE_INSTALL_PREFIX}" "${outdir}")
++  set(bindir "${DESTDIR}${prefixed_outdir}")
+ 
+-  message(STATUS "Creating ${name}")
++  message(STATUS "Creating ${name} at ${bindir}")
+ 
+   execute_process(
+     COMMAND "${CMAKE_COMMAND}" -E create_symlink "${target}" "${name}"
diff --git a/pkgs/development/compilers/llvm/rocm/lld.nix b/pkgs/development/compilers/llvm/rocm/lld.nix
deleted file mode 100644
index 272e430c1fc..00000000000
--- a/pkgs/development/compilers/llvm/rocm/lld.nix
+++ /dev/null
@@ -1,43 +0,0 @@
-{ stdenv
-, lib
-, cmake
-, libxml2
-, llvm
-, ninja
-
-, version
-, src
-}:
-
-stdenv.mkDerivation rec {
-  inherit version src;
-
-  sourceRoot = "${src.name}/lld";
-
-  pname = "lld";
-
-  nativeBuildInputs = [ cmake ninja ];
-
-  buildInputs = [ libxml2 llvm ];
-
-  outputs = [ "out" "dev" ];
-
-  cmakeFlags = [ "-DLLVM_MAIN_SRC_DIR=${src}/llvm" ];
-
-  postInstall = ''
-    moveToOutput include "$dev"
-    moveToOutput lib "$dev"
-
-    # Fix lld binary path for CMake.
-    substituteInPlace "$dev/lib/cmake/lld/LLDTargets-release.cmake" \
-      --replace "\''${_IMPORT_PREFIX}/bin/lld" "$out/bin/lld"
-  '';
-
-  meta = with lib; {
-    description = "ROCm fork of the LLVM Linker";
-    homepage = "https://github.com/RadeonOpenCompute/llvm-project";
-    license = licenses.ncsa;
-    maintainers = with maintainers; [ acowley lovesegfault ];
-    platforms = platforms.linux;
-  };
-}
diff --git a/pkgs/development/compilers/llvm/rocm/llvm/default.nix b/pkgs/development/compilers/llvm/rocm/llvm.nix
index 80a387b3650..557d1946686 100644
--- a/pkgs/development/compilers/llvm/rocm/llvm/default.nix
+++ b/pkgs/development/compilers/llvm/rocm/llvm.nix
@@ -1,5 +1,6 @@
 { stdenv
 , lib
+, fetchgit
 , fetchFromGitHub
 , writeScript
 , cmake
@@ -12,7 +13,6 @@
 , zlib
 , debugVersion ? false
 , enableManpages ? false
-, enableSharedLibraries ? false
 
 , version
 , src
@@ -30,28 +30,18 @@ in stdenv.mkDerivation rec {
 
   sourceRoot = "${src.name}/llvm";
 
-  outputs = [ "out" "python" ]
-    ++ lib.optional enableSharedLibraries "lib";
-
   nativeBuildInputs = [ cmake ninja python3 ];
 
-  buildInputs = [ libxml2 libffi ];
+  buildInputs = [ libxml2 ];
 
   propagatedBuildInputs = [ ncurses zlib ];
 
   cmakeFlags = with stdenv; [
     "-DCMAKE_BUILD_TYPE=${if debugVersion then "Debug" else "Release"}"
     "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc
-    "-DLLVM_BUILD_TESTS=OFF"
-    "-DLLVM_ENABLE_FFI=ON"
-    "-DLLVM_ENABLE_RTTI=ON"
-    "-DLLVM_ENABLE_DUMP=ON"
     "-DLLVM_TARGETS_TO_BUILD=AMDGPU;${llvmNativeTarget}"
+    "-DLLVM_ENABLE_PROJECTS=clang;lld;compiler-rt"
   ]
-  ++
-  lib.optional
-    enableSharedLibraries
-    "-DLLVM_LINK_LLVM_DYLIB=ON"
   ++ lib.optionals enableManpages [
     "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include"
     "-DLLVM_BUILD_DOCS=ON"
@@ -61,39 +51,16 @@ in stdenv.mkDerivation rec {
     "-DSPHINX_WARNINGS_AS_ERRORS=OFF"
   ];
 
+  patches = [
+    ./install-symlinks.patch
+  ];
+
   postPatch = ''
     patchShebangs lib/OffloadArch/make_generated_offload_arch_h.sh
-  '' + lib.optionalString enableSharedLibraries ''
-    substitute '${./outputs.patch}' ./outputs.patch --subst-var lib
-    patch -p1 < ./outputs.patch
-  '';
-
-  # hacky fix: created binaries need to be run before installation
-  preBuild = ''
-    mkdir -p $out/
-    ln -sv $PWD/lib $out
-  '';
-
-  postBuild = ''
-    rm -fR $out
+    substituteInPlace ../clang/cmake/modules/CMakeLists.txt \
+      --replace 'FILES_MATCHING' 'NO_SOURCE_PERMISSIONS FILES_MATCHING'
   '';
 
-  preCheck = ''
-    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib
-  '';
-
-  postInstall = ''
-    moveToOutput share/opt-viewer "$python"
-  ''
-  + lib.optionalString enableSharedLibraries ''
-    moveToOutput "lib/libLLVM-*" "$lib"
-    moveToOutput "lib/libLLVM${stdenv.hostPlatform.extensions.sharedLibrary}" "$lib"
-    substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
-      --replace "\''${_IMPORT_PREFIX}/lib/libLLVM-" "$lib/lib/libLLVM-"
-  '';
-
-  passthru.src = src;
-
   updateScript = writeScript "update.sh" ''
     #!/usr/bin/env nix-shell
     #!nix-shell -i bash -p curl jq common-updater-scripts nix-prefetch-github
@@ -111,11 +78,13 @@ in stdenv.mkDerivation rec {
     fi
   '';
 
+  passthru.isClang = true;
+
   meta = with lib; {
     description = "ROCm fork of the LLVM compiler infrastructure";
     homepage = "https://github.com/RadeonOpenCompute/llvm-project";
     license = with licenses; [ ncsa ];
-    maintainers = with maintainers; [ acowley lovesegfault ];
+    maintainers = with maintainers; [ acowley lovesegfault Flakebi ];
     platforms = platforms.linux;
   };
 }
diff --git a/pkgs/development/compilers/llvm/rocm/llvm/outputs.patch b/pkgs/development/compilers/llvm/rocm/llvm/outputs.patch
deleted file mode 100644
index 878460e05b8..00000000000
--- a/pkgs/development/compilers/llvm/rocm/llvm/outputs.patch
+++ /dev/null
@@ -1,16 +0,0 @@
-diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
-index 94d426b..37f7794 100644
---- a/tools/llvm-config/llvm-config.cpp
-+++ b/tools/llvm-config/llvm-config.cpp
-@@ -333,6 +333,11 @@ int main(int argc, char **argv) {
-     ActiveIncludeOption = "-I" + ActiveIncludeDir;
-   }
- 
-+  /// Nix-specific multiple-output handling: override ActiveLibDir
-+  if (!IsInDevelopmentTree) {
-+    ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX;
-+  }
-+
-   /// We only use `shared library` mode in cases where the static library form
-   /// of the components provided are not available; note however that this is
-   /// skipped if we're run from within the build dir. However, once installed,