From b17052ae9306cad34fd83bfe1f4f830d171052d4 Mon Sep 17 00:00:00 2001 From: Daniƫl de Kok Date: Fri, 10 Jul 2020 19:28:08 +0200 Subject: llvmPackages_rocm: init at 3.5.1 (cherry picked from commit e492cd92a918068c50b65ea04ef062d4acc8814c) --- .../pkgs/development/compilers/llvm/rocm/clang.nix | 67 +++++++++++++++ .../development/compilers/llvm/rocm/default.nix | 41 +++++++++ .../pkgs/development/compilers/llvm/rocm/lld.nix | 33 ++++++++ .../compilers/llvm/rocm/llvm-outputs.patch | 26 ++++++ .../pkgs/development/compilers/llvm/rocm/llvm.nix | 97 ++++++++++++++++++++++ 5 files changed, 264 insertions(+) create mode 100644 nixpkgs/pkgs/development/compilers/llvm/rocm/clang.nix create mode 100644 nixpkgs/pkgs/development/compilers/llvm/rocm/default.nix create mode 100644 nixpkgs/pkgs/development/compilers/llvm/rocm/lld.nix create mode 100644 nixpkgs/pkgs/development/compilers/llvm/rocm/llvm-outputs.patch create mode 100644 nixpkgs/pkgs/development/compilers/llvm/rocm/llvm.nix (limited to 'nixpkgs/pkgs/development/compilers/llvm/rocm') diff --git a/nixpkgs/pkgs/development/compilers/llvm/rocm/clang.nix b/nixpkgs/pkgs/development/compilers/llvm/rocm/clang.nix new file mode 100644 index 000000000000..86853a97c931 --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/llvm/rocm/clang.nix @@ -0,0 +1,67 @@ +{ stdenv +, fetchFromGitHub +, cmake +, python +, llvm +, clang-tools-extra_src ? null +, rocm-runtime +, lld + +, version +, src +}: + +stdenv.mkDerivation rec { + inherit version src; + + pname = "clang"; + + nativeBuildInputs = [ cmake python ]; + + buildInputs = [ llvm rocm-runtime ]; + + 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 = stdenv.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 + ''; + + meta = with stdenv.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; [ danieldk ]; + platforms = platforms.linux; + }; +} diff --git a/nixpkgs/pkgs/development/compilers/llvm/rocm/default.nix b/nixpkgs/pkgs/development/compilers/llvm/rocm/default.nix new file mode 100644 index 000000000000..e90818d8505d --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/llvm/rocm/default.nix @@ -0,0 +1,41 @@ +{ stdenv, fetchFromGitHub, callPackage, wrapCCWith }: + +let + version = "3.5.1"; + src = fetchFromGitHub { + owner = "RadeonOpenCompute"; + repo = "llvm-project"; + rev = "rocm-${version}"; + sha256 = "03k2xp8wf4awf1zcjc2hb3kf9bqp567c3s569gp1q3q1zjg6r2ib"; + }; +in rec { + clang = wrapCCWith rec { + cc = clang-unwrapped; + 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" + 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 + ''; + }; + + clang-unwrapped = callPackage ./clang.nix { + inherit lld llvm version; + src = "${src}/clang"; + }; + + lld = callPackage ./lld.nix { + inherit llvm version; + src = "${src}/lld"; + }; + + llvm = callPackage ./llvm.nix { + inherit version; + src = "${src}/llvm"; + }; +} diff --git a/nixpkgs/pkgs/development/compilers/llvm/rocm/lld.nix b/nixpkgs/pkgs/development/compilers/llvm/rocm/lld.nix new file mode 100644 index 000000000000..052bfd1c62d8 --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/llvm/rocm/lld.nix @@ -0,0 +1,33 @@ +{ stdenv +, cmake +, libxml2 +, llvm + +, version +, src +}: + +stdenv.mkDerivation rec { + inherit version src; + + pname = "lld"; + + nativeBuildInputs = [ cmake ]; + + buildInputs = [ libxml2 llvm ]; + + outputs = [ "out" "dev" ]; + + postInstall = '' + moveToOutput include "$dev" + moveToOutput lib "$dev" + ''; + + meta = with stdenv.lib; { + description = "ROCm fork of the LLVM Linker"; + homepage = "https://github.com/RadeonOpenCompute/llvm-project"; + license = licenses.ncsa; + maintainers = with maintainers; [ danieldk ]; + platforms = platforms.linux; + }; +} diff --git a/nixpkgs/pkgs/development/compilers/llvm/rocm/llvm-outputs.patch b/nixpkgs/pkgs/development/compilers/llvm/rocm/llvm-outputs.patch new file mode 100644 index 000000000000..40096fa3497f --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/llvm/rocm/llvm-outputs.patch @@ -0,0 +1,26 @@ +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,21 @@ int main(int argc, char **argv) { + ActiveIncludeOption = "-I" + ActiveIncludeDir; + } + ++ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared ++ if (!IsInDevelopmentTree) { ++ bool WantShared = true; ++ for (int i = 1; i < argc; ++i) { ++ StringRef Arg = argv[i]; ++ if (Arg == "--link-shared") ++ WantShared = true; ++ else if (Arg == "--link-static") ++ WantShared = false; // the last one wins ++ } ++ ++ if (WantShared) ++ 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, diff --git a/nixpkgs/pkgs/development/compilers/llvm/rocm/llvm.nix b/nixpkgs/pkgs/development/compilers/llvm/rocm/llvm.nix new file mode 100644 index 000000000000..909284a3e919 --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/llvm/rocm/llvm.nix @@ -0,0 +1,97 @@ +{ stdenv +, fetchFromGitHub +, cmake +, python3 +, libxml2 +, libffi +, libbfd +, ncurses +, zlib +, debugVersion ? false +, enableManpages ? false +, enableSharedLibraries ? true + +, version +, src +}: + +let + llvmNativeTarget = + if stdenv.isx86_64 then "X86" + else if stdenv.isAarch64 then "AArch64" + else throw "Unsupported ROCm LLVM platform"; +in stdenv.mkDerivation rec { + inherit src version; + + pname = "rocm-llvm"; + + outputs = [ "out" "python" ] + ++ stdenv.lib.optional enableSharedLibraries "lib"; + + nativeBuildInputs = [ cmake python3 ]; + + buildInputs = [ libxml2 libffi ]; + + 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}" + ] + ++ + stdenv.lib.optional + enableSharedLibraries + "-DLLVM_LINK_LLVM_DYLIB=ON" + ++ stdenv.lib.optionals enableManpages [ + "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" + "-DLLVM_BUILD_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ]; + + postPatch = '' + substitute '${./llvm-outputs.patch}' ./llvm-outputs.patch --subst-var lib + patch -p1 < ./llvm-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 + ''; + + preCheck = '' + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/lib + ''; + + postInstall = '' + moveToOutput share/opt-viewer "$python" + '' + + stdenv.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; + + meta = with stdenv.lib; { + description = "ROCm fork of the LLVM compiler infrastructure"; + homepage = "https://github.com/RadeonOpenCompute/llvm-project"; + license = with licenses; [ ncsa ]; + maintainers = with maintainers; [ danieldk ]; + platforms = platforms.linux; + }; +} -- cgit 1.4.1