From 281516cfb4f7f0da6b98764891faf65afcc57b5f Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Tue, 4 Oct 2022 11:25:28 -0500 Subject: [PATCH 01/30] llvmPackages_15: copy from `llvmPackages_git` (cherry picked from commit 201ef33028bbb02cbcb91eaaa6520157af71b412) --- .../compilers/llvm/15/bintools/default.nix | 29 ++ .../compilers/llvm/15/clang/default.nix | 133 +++++++++ .../llvm/15/clang/gnu-install-dirs.patch | 105 +++++++ .../compilers/llvm/15/clang/purity.patch | 29 ++ .../compiler-rt/X86-support-extension.patch | 21 ++ .../llvm/15/compiler-rt/armv7l.patch | 32 ++ .../llvm/15/compiler-rt/codesign.patch | 33 +++ .../darwin-targetconditionals.patch | 71 +++++ .../compilers/llvm/15/compiler-rt/default.nix | 127 ++++++++ .../15/compiler-rt/gnu-install-dirs.patch | 20 ++ .../llvm/15/compiler-rt/normalize-var.patch | 16 + .../development/compilers/llvm/15/default.nix | 280 ++++++++++++++++++ .../compilers/llvm/15/libcxx/default.nix | 94 ++++++ .../llvm/15/libcxx/gnu-install-dirs.patch | 22 ++ .../compilers/llvm/15/libcxxabi/default.nix | 97 ++++++ .../llvm/15/libcxxabi/gnu-install-dirs.patch | 22 ++ .../compilers/llvm/15/libcxxabi/wasm.patch | 16 + .../compilers/llvm/15/libunwind/default.nix | 61 ++++ .../llvm/15/libunwind/gnu-install-dirs.patch | 22 ++ .../compilers/llvm/15/lld/default.nix | 53 ++++ .../llvm/15/lld/gnu-install-dirs.patch | 46 +++ .../compilers/llvm/15/lldb/default.nix | 145 +++++++++ .../llvm/15/lldb/gnu-install-dirs.patch | 23 ++ .../compilers/llvm/15/lldb/procfs.patch | 40 +++ .../compilers/llvm/15/lldb/resource-dir.patch | 13 + .../compilers/llvm/15/llvm/default.nix | 267 +++++++++++++++++ .../llvm/15/llvm/gnu-install-dirs-polly.patch | 102 +++++++ .../llvm/15/llvm/gnu-install-dirs.patch | 138 +++++++++ .../compilers/llvm/15/openmp/default.nix | 67 +++++ .../llvm/15/openmp/fix-find-tool.patch | 18 ++ .../llvm/15/openmp/gnu-install-dirs.patch | 22 ++ .../llvm/15/openmp/run-lit-directly.patch | 12 + pkgs/top-level/all-packages.nix | 16 + 33 files changed, 2192 insertions(+) create mode 100644 pkgs/development/compilers/llvm/15/bintools/default.nix create mode 100644 pkgs/development/compilers/llvm/15/clang/default.nix create mode 100644 pkgs/development/compilers/llvm/15/clang/gnu-install-dirs.patch create mode 100644 pkgs/development/compilers/llvm/15/clang/purity.patch create mode 100644 pkgs/development/compilers/llvm/15/compiler-rt/X86-support-extension.patch create mode 100644 pkgs/development/compilers/llvm/15/compiler-rt/armv7l.patch create mode 100644 pkgs/development/compilers/llvm/15/compiler-rt/codesign.patch create mode 100644 pkgs/development/compilers/llvm/15/compiler-rt/darwin-targetconditionals.patch create mode 100644 pkgs/development/compilers/llvm/15/compiler-rt/default.nix create mode 100644 pkgs/development/compilers/llvm/15/compiler-rt/gnu-install-dirs.patch create mode 100644 pkgs/development/compilers/llvm/15/compiler-rt/normalize-var.patch create mode 100644 pkgs/development/compilers/llvm/15/default.nix create mode 100644 pkgs/development/compilers/llvm/15/libcxx/default.nix create mode 100644 pkgs/development/compilers/llvm/15/libcxx/gnu-install-dirs.patch create mode 100644 pkgs/development/compilers/llvm/15/libcxxabi/default.nix create mode 100644 pkgs/development/compilers/llvm/15/libcxxabi/gnu-install-dirs.patch create mode 100644 pkgs/development/compilers/llvm/15/libcxxabi/wasm.patch create mode 100644 pkgs/development/compilers/llvm/15/libunwind/default.nix create mode 100644 pkgs/development/compilers/llvm/15/libunwind/gnu-install-dirs.patch create mode 100644 pkgs/development/compilers/llvm/15/lld/default.nix create mode 100644 pkgs/development/compilers/llvm/15/lld/gnu-install-dirs.patch create mode 100644 pkgs/development/compilers/llvm/15/lldb/default.nix create mode 100644 pkgs/development/compilers/llvm/15/lldb/gnu-install-dirs.patch create mode 100644 pkgs/development/compilers/llvm/15/lldb/procfs.patch create mode 100644 pkgs/development/compilers/llvm/15/lldb/resource-dir.patch create mode 100644 pkgs/development/compilers/llvm/15/llvm/default.nix create mode 100644 pkgs/development/compilers/llvm/15/llvm/gnu-install-dirs-polly.patch create mode 100644 pkgs/development/compilers/llvm/15/llvm/gnu-install-dirs.patch create mode 100644 pkgs/development/compilers/llvm/15/openmp/default.nix create mode 100644 pkgs/development/compilers/llvm/15/openmp/fix-find-tool.patch create mode 100644 pkgs/development/compilers/llvm/15/openmp/gnu-install-dirs.patch create mode 100644 pkgs/development/compilers/llvm/15/openmp/run-lit-directly.patch diff --git a/pkgs/development/compilers/llvm/15/bintools/default.nix b/pkgs/development/compilers/llvm/15/bintools/default.nix new file mode 100644 index 0000000000000..53f7941e33699 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/bintools/default.nix @@ -0,0 +1,29 @@ +{ runCommand, stdenv, llvm, lld, version }: + +let + prefix = + if stdenv.hostPlatform != stdenv.targetPlatform + then "${stdenv.targetPlatform.config}-" + else ""; +in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } '' + mkdir -p $out/bin + for prog in ${lld}/bin/*; do + ln -s $prog $out/bin/${prefix}$(basename $prog) + done + for prog in ${llvm}/bin/*; do + ln -sf $prog $out/bin/${prefix}$(basename $prog) + done + + ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ar + ln -s ${llvm}/bin/llvm-as $out/bin/${prefix}as + ln -s ${llvm}/bin/llvm-dwp $out/bin/${prefix}dwp + ln -s ${llvm}/bin/llvm-nm $out/bin/${prefix}nm + ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}objcopy + ln -s ${llvm}/bin/llvm-objdump $out/bin/${prefix}objdump + ln -s ${llvm}/bin/llvm-ranlib $out/bin/${prefix}ranlib + ln -s ${llvm}/bin/llvm-readelf $out/bin/${prefix}readelf + ln -s ${llvm}/bin/llvm-size $out/bin/${prefix}size + ln -s ${llvm}/bin/llvm-strip $out/bin/${prefix}strip + + ln -s ${lld}/bin/lld $out/bin/${prefix}ld +'' diff --git a/pkgs/development/compilers/llvm/15/clang/default.nix b/pkgs/development/compilers/llvm/15/clang/default.nix new file mode 100644 index 0000000000000..3110bef09e969 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/clang/default.nix @@ -0,0 +1,133 @@ +{ lib, stdenv, llvm_meta +, monorepoSrc, runCommand +, substituteAll, cmake, libxml2, libllvm, version, python3 +, buildLlvmTools +, fixDarwinDylibNames +, enableManpages ? false +}: + +let + self = stdenv.mkDerivation (rec { + pname = "clang"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + cp -r ${monorepoSrc}/clang-tools-extra "$out" + ''; + + sourceRoot = "${src.name}/${pname}"; + + nativeBuildInputs = [ cmake python3 ] + ++ lib.optional enableManpages python3.pkgs.sphinx + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ libxml2 libllvm ]; + + cmakeFlags = [ + "-DCLANG_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/clang" + "-DCMAKE_CXX_FLAGS=-std=c++14" + "-DCLANGD_BUILD_XPC=OFF" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ lib.optionals enableManpages [ + "-DCLANG_INCLUDE_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + ]; + + patches = [ + ./purity.patch + # https://reviews.llvm.org/D51899 + ./gnu-install-dirs.patch + (substituteAll { + src = ../../clang-11-12-LLVMgold-path.patch; + libllvmLibdir = "${libllvm.lib}/lib"; + }) + ]; + + postPatch = '' + (cd tools && ln -s ../../clang-tools-extra extra) + + sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' \ + -e 's/Args.hasArg(options::OPT_nostdlibinc)/true/' \ + lib/Driver/ToolChains/*.cpp + + # Patch for standalone doc building + sed -i '1s,^,find_package(Sphinx REQUIRED)\n,' docs/CMakeLists.txt + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + postInstall = '' + ln -sv $out/bin/clang $out/bin/cpp + + # Move libclang to 'lib' output + moveToOutput "lib/libclang.*" "$lib" + moveToOutput "lib/libclang-cpp.*" "$lib" + substituteInPlace $dev/lib/cmake/clang/ClangTargets-release.cmake \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp." + + mkdir -p $python/bin $python/share/clang/ + mv $out/bin/{git-clang-format,scan-view} $python/bin + if [ -e $out/bin/set-xcode-analyzer ]; then + mv $out/bin/set-xcode-analyzer $python/bin + fi + mv $out/share/clang/*.py $python/share/clang + rm $out/bin/c-index-test + + mkdir -p $dev/bin + cp bin/clang-tblgen $dev/bin + ''; + + passthru = { + isClang = true; + inherit libllvm; + }; + + meta = llvm_meta // { + homepage = "https://clang.llvm.org/"; + description = "A C language family frontend for LLVM"; + longDescription = '' + The Clang project provides a language front-end and tooling + infrastructure for languages in the C language family (C, C++, Objective + C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. + It aims to deliver amazingly fast compiles, extremely useful error and + warning messages and to provide a platform for building great source + level tools. The Clang Static Analyzer and clang-tidy are tools that + automatically find bugs in your code, and are great examples of the sort + of tools that can be built using the Clang frontend as a library to + parse C/C++ code. + ''; + }; + } // lib.optionalAttrs enableManpages { + pname = "clang-manpages"; + + buildPhase = '' + make docs-clang-man + ''; + + installPhase = '' + mkdir -p $out/share/man/man1 + # Manually install clang manpage + cp docs/man/*.1 $out/share/man/man1/ + ''; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man page for Clang ${version}"; + }; + }); +in self diff --git a/pkgs/development/compilers/llvm/15/clang/gnu-install-dirs.patch b/pkgs/development/compilers/llvm/15/clang/gnu-install-dirs.patch new file mode 100644 index 0000000000000..f767c56836d5c --- /dev/null +++ b/pkgs/development/compilers/llvm/15/clang/gnu-install-dirs.patch @@ -0,0 +1,105 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index c27beec313d7..480f13e73c9f 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -78,15 +78,17 @@ if(CLANG_BUILT_STANDALONE) + if (NOT LLVM_CONFIG_FOUND) + # Pull values from LLVMConfig.cmake. We can drop this once the llvm-config + # path is removed. +- set(MAIN_INCLUDE_DIR "${LLVM_INCLUDE_DIR}") ++ set(INCLUDE_DIRS ${LLVM_INCLUDE_DIRS}) + set(LLVM_OBJ_DIR "${LLVM_BINARY_DIR}") + # N.B. this is just a default value, the CACHE PATHs below can be overriden. + set(MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm") + set(TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}") + set(LIBRARY_DIR "${LLVM_LIBRARY_DIR}") ++ else() ++ set(INCLUDE_DIRS "${LLVM_BINARY_DIR}/include" "${MAIN_INCLUDE_DIR}") + endif() + +- set(LLVM_MAIN_INCLUDE_DIR "${MAIN_INCLUDE_DIR}" CACHE PATH "Path to llvm/include") ++ set(LLVM_INCLUDE_DIRS ${INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed") + set(LLVM_BINARY_DIR "${LLVM_OBJ_ROOT}" CACHE PATH "Path to LLVM build tree") + set(LLVM_MAIN_SRC_DIR "${MAIN_SRC_DIR}" CACHE PATH "Path to LLVM source tree") + set(LLVM_TOOLS_BINARY_DIR "${TOOLS_BINARY_DIR}" CACHE PATH "Path to llvm/bin") +@@ -128,7 +130,7 @@ if(CLANG_BUILT_STANDALONE) + set(LLVM_INCLUDE_TESTS ON) + endif() + +- include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_MAIN_INCLUDE_DIR}") ++ include_directories(${LLVM_INCLUDE_DIRS}) + link_directories("${LLVM_LIBRARY_DIR}") + + set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) +diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake +index 21ac332e4f5f..b16c314bd1e2 100644 +--- a/cmake/modules/AddClang.cmake ++++ b/cmake/modules/AddClang.cmake +@@ -119,8 +119,8 @@ macro(add_clang_library name) + install(TARGETS ${lib} + COMPONENT ${lib} + ${export_to_clangtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + + if (NOT LLVM_ENABLE_IDE) +diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt +index 6e2060991b92..b9bc930d26b8 100644 +--- a/lib/Headers/CMakeLists.txt ++++ b/lib/Headers/CMakeLists.txt +@@ -420,7 +420,7 @@ add_header_target("openmp-resource-headers" ${openmp_wrapper_files}) + add_header_target("windows-resource-headers" ${windows_only_files}) + add_header_target("utility-resource-headers" ${utility_files}) + +-set(header_install_dir lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) ++set(header_install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) + + ############################################################# + # Install rules for the catch-all clang-resource-headers target +diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt +index 8d95d0900e8c..ebc70ff7526d 100644 +--- a/tools/libclang/CMakeLists.txt ++++ b/tools/libclang/CMakeLists.txt +@@ -180,7 +180,7 @@ foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS}) + COMPONENT + libclang-python-bindings + DESTINATION +- "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") ++ "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") + endforeach() + if(NOT LLVM_ENABLE_IDE) + add_custom_target(libclang-python-bindings) +diff --git a/tools/scan-build-py/CMakeLists.txt b/tools/scan-build-py/CMakeLists.txt +index 061dc7ef4dd9..adc54b2edc32 100644 +--- a/tools/scan-build-py/CMakeLists.txt ++++ b/tools/scan-build-py/CMakeLists.txt +@@ -88,7 +88,7 @@ foreach(lib ${LibScanbuild}) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libscanbuild/${lib}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libscanbuild/${lib}) + install(PROGRAMS lib/libscanbuild/${lib} +- DESTINATION lib/libscanbuild ++ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libscanbuild" + COMPONENT scan-build-py) + endforeach() + +@@ -106,7 +106,7 @@ foreach(resource ${LibScanbuildResources}) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libscanbuild/resources/${resource}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libscanbuild/resources/${resource}) + install(PROGRAMS lib/libscanbuild/resources/${resource} +- DESTINATION lib/libscanbuild/resources ++ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libscanbuild/resources" + COMPONENT scan-build-py) + endforeach() + +@@ -122,7 +122,7 @@ foreach(lib ${LibEar}) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libear/${lib}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libear/${lib}) + install(PROGRAMS lib/libear/${lib} +- DESTINATION lib/libear ++ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libear" + COMPONENT scan-build-py) + endforeach() + diff --git a/pkgs/development/compilers/llvm/15/clang/purity.patch b/pkgs/development/compilers/llvm/15/clang/purity.patch new file mode 100644 index 0000000000000..1c94f293eb934 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/clang/purity.patch @@ -0,0 +1,29 @@ +From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Thu, 18 May 2017 11:56:12 -0500 +Subject: [PATCH] "purity" patch for 5.0 + +--- + lib/Driver/ToolChains/Gnu.cpp | 7 ------- + 1 file changed, 7 deletions(-) + +diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp +index fe3c0191bb..c6a482bece 100644 +--- a/lib/Driver/ToolChains/Gnu.cpp ++++ b/lib/Driver/ToolChains/Gnu.cpp +@@ -487,13 +487,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + } else { + if (Args.hasArg(options::OPT_rdynamic)) + CmdArgs.push_back("-export-dynamic"); + +- if (!Args.hasArg(options::OPT_shared) && !IsStaticPIE && +- !Args.hasArg(options::OPT_r)) { +- CmdArgs.push_back("-dynamic-linker"); +- CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) + +- ToolChain.getDynamicLinker(Args))); +- } + } + + CmdArgs.push_back("-o"); +-- +2.11.0 diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/X86-support-extension.patch b/pkgs/development/compilers/llvm/15/compiler-rt/X86-support-extension.patch new file mode 100644 index 0000000000000..07013e5a68259 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/compiler-rt/X86-support-extension.patch @@ -0,0 +1,21 @@ +diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt +index 3a66dd9c3fb..7efc85d9f9f 100644 +--- a/lib/builtins/CMakeLists.txt ++++ b/lib/builtins/CMakeLists.txt +@@ -348,4 +348,8 @@ if (NOT MSVC) + ++ set(i486_SOURCES ${i386_SOURCES}) ++ set(i586_SOURCES ${i386_SOURCES}) ++ set(i686_SOURCES ${i386_SOURCES}) ++ + if (WIN32) + set(i386_SOURCES + ${i386_SOURCES} +@@ -723,6 +723,7 @@ else () + endif() + + foreach (arch ${BUILTIN_SUPPORTED_ARCH}) ++ message("arch: ${arch}") + if (CAN_TARGET_${arch}) + # For ARM archs, exclude any VFP builtins if VFP is not supported + if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/armv7l.patch b/pkgs/development/compilers/llvm/15/compiler-rt/armv7l.patch new file mode 100644 index 0000000000000..120cfe6feb2a6 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/compiler-rt/armv7l.patch @@ -0,0 +1,32 @@ +diff -ur compiler-rt-10.0.0.src/cmake/builtin-config-ix.cmake compiler-rt-10.0.0.src-patched/cmake/builtin-config-ix.cmake +--- compiler-rt-10.0.0.src/cmake/builtin-config-ix.cmake 2020-03-24 00:01:02.000000000 +0900 ++++ compiler-rt-10.0.0.src-patched/cmake/builtin-config-ix.cmake 2020-05-10 03:42:00.883450706 +0900 +@@ -24,7 +24,7 @@ + + + set(ARM64 aarch64) +-set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k) ++set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv7l) + set(HEXAGON hexagon) + set(X86 i386) + set(X86_64 x86_64) +diff -ur compiler-rt-10.0.0.src/lib/builtins/CMakeLists.txt compiler-rt-10.0.0.src-patched/lib/builtins/CMakeLists.txt +--- compiler-rt-10.0.0.src/lib/builtins/CMakeLists.txt 2020-03-24 00:01:02.000000000 +0900 ++++ compiler-rt-10.0.0.src-patched/lib/builtins/CMakeLists.txt 2020-05-10 03:44:49.468579650 +0900 +@@ -474,6 +474,7 @@ + set(armv7_SOURCES ${arm_SOURCES}) + set(armv7s_SOURCES ${arm_SOURCES}) + set(armv7k_SOURCES ${arm_SOURCES}) ++set(armv7l_SOURCES ${arm_SOURCES}) + set(arm64_SOURCES ${aarch64_SOURCES}) + + # macho_embedded archs +@@ -595,7 +596,7 @@ + foreach (arch ${BUILTIN_SUPPORTED_ARCH}) + if (CAN_TARGET_${arch}) + # For ARM archs, exclude any VFP builtins if VFP is not supported +- if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") ++ if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7l|armv7m|armv7em)$") + string(REPLACE ";" " " _TARGET_${arch}_CFLAGS "${TARGET_${arch}_CFLAGS}") + check_compile_definition(__VFP_FP__ "${CMAKE_C_FLAGS} ${_TARGET_${arch}_CFLAGS}" COMPILER_RT_HAS_${arch}_VFP) + if(NOT COMPILER_RT_HAS_${arch}_VFP) diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/codesign.patch b/pkgs/development/compilers/llvm/15/compiler-rt/codesign.patch new file mode 100644 index 0000000000000..065959d14d46c --- /dev/null +++ b/pkgs/development/compilers/llvm/15/compiler-rt/codesign.patch @@ -0,0 +1,33 @@ +From 3dec5f3475a26aeb4678627795c4b67c6b7b4785 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Tue, 19 Sep 2017 13:13:06 -0500 +Subject: [PATCH] remove codesign use on Apple, disable ios sim testing that + needs it + +--- + cmake/Modules/AddCompilerRT.cmake | 8 ------ + test/asan/CMakeLists.txt | 52 --------------------------------------- + test/tsan/CMakeLists.txt | 47 ----------------------------------- + 3 files changed, 107 deletions(-) + +diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake +index bc69ec95c419..9f100fdcec2f 100644 +--- a/cmake/Modules/AddCompilerRT.cmake ++++ b/cmake/Modules/AddCompilerRT.cmake +@@ -366,14 +366,6 @@ function(add_compiler_rt_runtime name type) + set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "") + set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib") + endif() +- if(APPLE) +- # Ad-hoc sign the dylibs +- add_custom_command(TARGET ${libname} +- POST_BUILD +- COMMAND codesign --sign - $ +- WORKING_DIRECTORY ${COMPILER_RT_OUTPUT_LIBRARY_DIR} +- ) +- endif() + endif() + + set(parent_target_arg) +2.14.1 + diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/darwin-targetconditionals.patch b/pkgs/development/compilers/llvm/15/compiler-rt/darwin-targetconditionals.patch new file mode 100644 index 0000000000000..425dc2af01e7c --- /dev/null +++ b/pkgs/development/compilers/llvm/15/compiler-rt/darwin-targetconditionals.patch @@ -0,0 +1,71 @@ +diff --git a/lib/sanitizer_common/sanitizer_mac.cpp b/lib/sanitizer_common/sanitizer_mac.cpp +--- a/lib/sanitizer_common/sanitizer_mac.cpp ++++ b/lib/sanitizer_common/sanitizer_mac.cpp +@@ -613,9 +613,15 @@ HandleSignalMode GetHandleSignalMode(int signum) { + // Offset example: + // XNU 17 -- macOS 10.13 -- iOS 11 -- tvOS 11 -- watchOS 4 + constexpr u16 GetOSMajorKernelOffset() { +- if (TARGET_OS_OSX) return 4; +- if (TARGET_OS_IOS || TARGET_OS_TV) return 6; +- if (TARGET_OS_WATCH) return 13; ++#if TARGET_OS_OSX ++ return 4; ++#endif ++#if TARGET_OS_IOS || TARGET_OS_TV ++ return 6; ++#endif ++#if TARGET_OS_WATCH ++ return 13; ++#endif + } + + using VersStr = char[64]; +@@ -627,13 +633,13 @@ static uptr ApproximateOSVersionViaKernelVersion(VersStr vers) { + u16 os_major = kernel_major - offset; + + const char *format = "%d.0"; +- if (TARGET_OS_OSX) { +- if (os_major >= 16) { // macOS 11+ +- os_major -= 5; +- } else { // macOS 10.15 and below +- format = "10.%d"; +- } ++#if TARGET_OS_OSX ++ if (os_major >= 16) { // macOS 11+ ++ os_major -= 5; ++ } else { // macOS 10.15 and below ++ format = "10.%d"; + } ++#endif + return internal_snprintf(vers, sizeof(VersStr), format, os_major); + } + +@@ -681,15 +687,14 @@ void ParseVersion(const char *vers, u16 *major, u16 *minor) { + // Aligned versions example: + // macOS 10.15 -- iOS 13 -- tvOS 13 -- watchOS 6 + static void MapToMacos(u16 *major, u16 *minor) { +- if (TARGET_OS_OSX) +- return; +- +- if (TARGET_OS_IOS || TARGET_OS_TV) ++#if !TARGET_OS_OSX ++#if TARGET_OS_IOS || TARGET_OS_TV + *major += 2; +- else if (TARGET_OS_WATCH) ++#elif TARGET_OS_WATCH + *major += 9; +- else ++#else + UNREACHABLE("unsupported platform"); ++#endif + + if (*major >= 16) { // macOS 11+ + *major -= 5; +@@ -697,6 +702,7 @@ static void MapToMacos(u16 *major, u16 *minor) { + *minor = *major; + *major = 10; + } ++#endif + } + + static MacosVersion GetMacosAlignedVersionInternal() { diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/default.nix b/pkgs/development/compilers/llvm/15/compiler-rt/default.nix new file mode 100644 index 0000000000000..ce28a7ef9bbd0 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/compiler-rt/default.nix @@ -0,0 +1,127 @@ +{ lib, stdenv, llvm_meta, version +, monorepoSrc, runCommand +, cmake, python3, libllvm, libcxxabi, libxcrypt +}: + +let + + useLLVM = stdenv.hostPlatform.useLLVM or false; + bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; + haveLibc = stdenv.cc.libc != null; + inherit (stdenv.hostPlatform) isMusl; + + baseName = "compiler-rt"; + + src = runCommand "${baseName}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${baseName} "$out" + ''; +in + +stdenv.mkDerivation { + pname = baseName + lib.optionalString (haveLibc) "-libc"; + inherit version; + + inherit src; + sourceRoot = "${src.name}/${baseName}"; + + nativeBuildInputs = [ cmake python3 libllvm.dev ]; + buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; + + 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}" + ] ++ lib.optionals (haveLibc && !isMusl) [ + "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" + ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ + "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" + "-DCOMPILER_RT_BUILD_XRAY=OFF" + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" + "-DCOMPILER_RT_BUILD_PROFILE=OFF" + "-DCOMPILER_RT_BUILD_MEMPROF=OFF" + "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary + ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ + "-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)}" + ] ++ lib.optionals (useLLVM && !haveLibc) [ + "-DCMAKE_C_FLAGS=-nodefaultlibs" + ] ++ lib.optionals (useLLVM) [ + "-DCOMPILER_RT_BUILD_BUILTINS=ON" + #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" + ] ++ lib.optionals (bareMetal) [ + "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ + "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" + "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" + ]; + + outputs = [ "out" "dev" ]; + + patches = [ + ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + ./gnu-install-dirs.patch + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./normalize-var.patch + ] # Prevent a compilation error on darwin + ++ lib.optional stdenv.hostPlatform.isDarwin ./darwin-targetconditionals.patch + ++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch; + + # 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)' + '' + lib.optionalString stdenv.isDarwin '' + substituteInPlace cmake/builtin-config-ix.cmake \ + --replace 'set(ARM64 arm64 arm64e)' 'set(ARM64)' + substituteInPlace cmake/config-ix.cmake \ + --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' + '' + lib.optionalString (useLLVM) '' + substituteInPlace lib/builtins/int_util.c \ + --replace "#include " "" + substituteInPlace lib/builtins/clear_cache.c \ + --replace "#include " "" + substituteInPlace lib/builtins/cpu_model.c \ + --replace "#include " "" + ''; + + # Hack around weird upsream RPATH bug + postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' + ln -s "$out/lib"/*/* "$out/lib" + '' + lib.optionalString (useLLVM) '' + 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 + ''; + + meta = llvm_meta // { + homepage = "https://compiler-rt.llvm.org/"; + description = "Compiler runtime libraries"; + longDescription = '' + The compiler-rt project provides highly tuned implementations of the + low-level code generator support routines like "__fixunsdfdi" and other + calls generated when a target doesn't have a short sequence of native + instructions to implement a core IR operation. It also provides + implementations of run-time libraries for dynamic testing tools such as + AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. + ''; + # "All of the code in the compiler-rt project is dual licensed under the MIT + # license and the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/gnu-install-dirs.patch b/pkgs/development/compilers/llvm/15/compiler-rt/gnu-install-dirs.patch new file mode 100644 index 0000000000000..f3b1f63a7d713 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/compiler-rt/gnu-install-dirs.patch @@ -0,0 +1,20 @@ +diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake +index 8a6219568b3f..30ee68a47ccf 100644 +--- a/cmake/base-config-ix.cmake ++++ b/cmake/base-config-ix.cmake +@@ -100,13 +100,13 @@ endif() + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(COMPILER_RT_OUTPUT_LIBRARY_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib) +- extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" lib) ++ extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}") + set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH + "Path where built compiler-rt libraries should be installed.") + else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(COMPILER_RT_OUTPUT_LIBRARY_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) +- extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "lib/${COMPILER_RT_OS_DIR}") ++ extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}/${COMPILER_RT_OS_DIR}") + set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH + "Path where built compiler-rt libraries should be installed.") + endif() diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/normalize-var.patch b/pkgs/development/compilers/llvm/15/compiler-rt/normalize-var.patch new file mode 100644 index 0000000000000..135cf625ef78f --- /dev/null +++ b/pkgs/development/compilers/llvm/15/compiler-rt/normalize-var.patch @@ -0,0 +1,16 @@ +diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake +index f1f46fb9599c..6f19e69507ba 100644 +--- a/cmake/Modules/CompilerRTUtils.cmake ++++ b/cmake/Modules/CompilerRTUtils.cmake +@@ -302,8 +302,9 @@ macro(load_llvm_config) + # Get some LLVM variables from LLVMConfig. + include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake") + +- set(LLVM_LIBRARY_OUTPUT_INTDIR +- ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) ++ get_filename_component(LLVM_LIBRARY_OUTPUT_INTDIR ++ ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX} ++ REALPATH) + endif() + endmacro() + diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix new file mode 100644 index 0000000000000..3a1ba402ef671 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/default.nix @@ -0,0 +1,280 @@ +{ lowPrio, newScope, pkgs, lib, stdenv, cmake +, gccForLibs, preLibcCrossHeaders +, libxml2, python3, isl, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith +, buildLlvmTools # tools, but from the previous stage, for cross +, targetLlvmLibraries # libraries, but from the next stage, for cross +# This is the default binutils, but with *this* version of LLD rather +# than the default LLVM verion's, if LLD is the choice. We use these for +# the `useLLVM` bootstrapping below. +, bootBintoolsNoLibc ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintoolsNoLibc +, bootBintools ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintools +, darwin +}: + +let + release_version = "14.0.6"; + candidate = ""; # empty or "rcN" + dash-candidate = lib.optionalString (candidate != "") "-${candidate}"; + rev = ""; # When using a Git commit + rev-version = ""; # When using a Git commit + version = if rev != "" then rev-version else "${release_version}${dash-candidate}"; + targetConfig = stdenv.targetPlatform.config; + + monorepoSrc = fetchFromGitHub { + owner = "llvm"; + repo = "llvm-project"; + rev = if rev != "" then rev else "llvmorg-${version}"; + sha256 = "sha256-vffu4HilvYwtzwgq+NlS26m65DGbp6OSSne2aje1yJE="; + }; + + llvm_meta = { + license = lib.licenses.ncsa; + maintainers = with lib.maintainers; [ lovek323 raskin dtzWill primeos ]; + platforms = lib.platforms.all; + }; + + tools = lib.makeExtensible (tools: let + callPackage = newScope (tools // { inherit stdenv cmake libxml2 python3 isl release_version version monorepoSrc buildLlvmTools; }); + mkExtraBuildCommands0 = cc: '' + rsrc="$out/resource-root" + mkdir "$rsrc" + ln -s "${cc.lib}/lib/clang/${release_version}/include" "$rsrc" + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags + ''; + mkExtraBuildCommands = cc: mkExtraBuildCommands0 cc + '' + ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" + ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share" + ''; + + bintoolsNoLibc' = + if bootBintoolsNoLibc == null + then tools.bintoolsNoLibc + else bootBintoolsNoLibc; + bintools' = + if bootBintools == null + then tools.bintools + else bootBintools; + + in { + + libllvm = callPackage ./llvm { + inherit llvm_meta; + }; + + # `llvm` historically had the binaries. When choosing an output explicitly, + # we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get* + llvm = tools.libllvm.out // { outputSpecified = false; }; + + libclang = callPackage ./clang { + inherit llvm_meta; + }; + + clang-unwrapped = tools.libclang.out // { outputSpecified = false; }; + + llvm-manpages = lowPrio (tools.libllvm.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + clang-manpages = lowPrio (tools.libclang.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + # TODO: lldb/docs/index.rst:155:toctree contains reference to nonexisting document 'design/structureddataplugins' + # lldb-manpages = lowPrio (tools.lldb.override { + # enableManpages = true; + # python3 = pkgs.python3; # don't use python-boot + # }); + + # pick clang appropriate for package set we are targeting + clang = + /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang + else tools.libcxxClang; + + libstdcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper. + libcxx = null; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + libcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + extraPackages = [ + targetLlvmLibraries.libcxxabi + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + lld = callPackage ./lld { + inherit llvm_meta; + }; + + lldb = callPackage ./lldb { + inherit llvm_meta; + inherit (darwin) libobjc bootstrap_cmds; + inherit (darwin.apple_sdk.libs) xpc; + inherit (darwin.apple_sdk.frameworks) Foundation Carbon Cocoa; + }; + + # Below, is the LLVM bootstrapping logic. It handles building a + # fully LLVM toolchain from scratch. No GCC toolchain should be + # pulled in. As a consequence, it is very quick to build different + # targets provided by LLVM and we can also build for what GCC + # doesn’t support like LLVM. Probably we should move to some other + # file. + + bintools-unwrapped = callPackage ./bintools {}; + + bintoolsNoLibc = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + libc = preLibcCrossHeaders; + }; + + bintools = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + }; + + clangUseLLVM = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + bintools = bintools'; + extraPackages = [ + targetLlvmLibraries.libcxxabi + targetLlvmLibraries.compiler-rt + ] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [ + targetLlvmLibraries.libunwind + ]; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = + [ "-rtlib=compiler-rt" + "-Wno-unused-command-line-argument" + "-B${targetLlvmLibraries.compiler-rt}/lib" + ] + ++ lib.optional (!stdenv.targetPlatform.isWasm) "--unwindlib=libunwind" + ++ lib.optional + (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) + "-lunwind" + ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; + }; + + clangNoLibcxx = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = [ + "-rtlib=compiler-rt" + "-B${targetLlvmLibraries.compiler-rt}/lib" + "-nostdlib++" + ]; + }; + + clangNoLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = [ + "-rtlib=compiler-rt" + "-B${targetLlvmLibraries.compiler-rt}/lib" + ]; + }; + + clangNoCompilerRt = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ ]; + extraBuildCommands = mkExtraBuildCommands0 cc; + nixSupport.cc-cflags = [ "-nostartfiles" ]; + }; + + clangNoCompilerRtWithLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ ]; + extraBuildCommands = mkExtraBuildCommands0 cc; + }; + + }); + + libraries = lib.makeExtensible (libraries: let + callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python3 isl release_version version monorepoSrc; }); + in { + + compiler-rt-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc + else stdenv; + }; + + compiler-rt-no-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRt + else stdenv; + }; + + # N.B. condition is safe because without useLLVM both are the same. + compiler-rt = if stdenv.hostPlatform.isAndroid + then libraries.compiler-rt-libc + else libraries.compiler-rt-no-libc; + + stdenv = overrideCC stdenv buildLlvmTools.clang; + + libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; + + libcxx = callPackage ./libcxx { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + libcxxabi = let + stdenv_ = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + cxx-headers = callPackage ./libcxx { + inherit llvm_meta; + stdenv = stdenv_; + headersOnly = true; + }; + in callPackage ./libcxxabi { + stdenv = stdenv_; + inherit llvm_meta cxx-headers; + }; + + libunwind = callPackage ./libunwind { + inherit llvm_meta; + stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; + }; + + openmp = callPackage ./openmp { + inherit llvm_meta; + }; + }); + +in { inherit tools libraries release_version; } // libraries // tools diff --git a/pkgs/development/compilers/llvm/15/libcxx/default.nix b/pkgs/development/compilers/llvm/15/libcxx/default.nix new file mode 100644 index 0000000000000..5e1f875bf338f --- /dev/null +++ b/pkgs/development/compilers/llvm/15/libcxx/default.nix @@ -0,0 +1,94 @@ +{ lib, stdenv, llvm_meta +, monorepoSrc, runCommand +, cmake, python3, fixDarwinDylibNames, version +, libcxxabi +, enableShared ? !stdenv.hostPlatform.isStatic + +# If headersOnly is true, the resulting package would only include the headers. +# Use this to break the circular dependency between libcxx and libcxxabi. +# +# Some context: +# https://reviews.llvm.org/rG1687f2bbe2e2aaa092f942d4a97d41fad43eedfb +, headersOnly ? false +}: + +let + basename = "libcxx"; +in + +stdenv.mkDerivation rec { + pname = basename + lib.optionalString headersOnly "-headers"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${basename} "$out" + mkdir -p "$out/libcxxabi" + cp -r ${monorepoSrc}/libcxxabi/include "$out/libcxxabi" + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" + cp -r ${monorepoSrc}/third-party "$out" + cp -r ${monorepoSrc}/runtimes "$out" + ''; + + sourceRoot = "${src.name}/runtimes"; + + outputs = [ "out" ] ++ lib.optional (!headersOnly) "dev"; + + prePatch = '' + cd ../${basename} + chmod -R u+w . + ''; + + patches = [ + ./gnu-install-dirs.patch + ] ++ lib.optionals stdenv.hostPlatform.isMusl [ + ../../libcxx-0001-musl-hacks.patch + ]; + + postPatch = '' + cd ../runtimes + ''; + + preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' + patchShebangs utils/cat_files.py + ''; + + nativeBuildInputs = [ cmake python3 ] + ++ lib.optional stdenv.isDarwin fixDarwinDylibNames; + + buildInputs = lib.optionals (!headersOnly) [ libcxxabi ]; + + cmakeFlags = [ + "-DLLVM_ENABLE_RUNTIMES=libcxx" + "-DLIBCXX_CXX_ABI=${lib.optionalString (!headersOnly) "system-"}libcxxabi" + ] ++ lib.optional (!headersOnly) "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${libcxxabi.dev}/include/c++/v1" + ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" + ++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON" + ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXX_ENABLE_THREADS=OFF" + "-DLIBCXX_ENABLE_FILESYSTEM=OFF" + "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"; + + buildFlags = lib.optional headersOnly "generate-cxx-headers"; + installTargets = lib.optional headersOnly "install-cxx-headers"; + + passthru = { + isLLVM = true; + }; + + meta = llvm_meta // { + homepage = "https://libcxx.llvm.org/"; + description = "C++ standard library"; + longDescription = '' + libc++ is an implementation of the C++ standard library, targeting C++11, + C++14 and above. + ''; + # "All of the code in libc++ is dual licensed under the MIT license and the + # UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/pkgs/development/compilers/llvm/15/libcxx/gnu-install-dirs.patch b/pkgs/development/compilers/llvm/15/libcxx/gnu-install-dirs.patch new file mode 100644 index 0000000000000..daee5bdd0ed33 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/libcxx/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 74eff2002fc9..c935d10878bb 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -419,7 +419,7 @@ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) + set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1") +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH + "Path where built libc++ libraries should be installed.") + set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1" CACHE PATH + "Path where target-specific libc++ headers should be installed.") +@@ -436,7 +436,7 @@ else() + set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1") + endif() + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}") +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX} CACHE PATH + "Path where built libc++ libraries should be installed.") + set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE PATH + "Path where target-specific libc++ headers should be installed.") diff --git a/pkgs/development/compilers/llvm/15/libcxxabi/default.nix b/pkgs/development/compilers/llvm/15/libcxxabi/default.nix new file mode 100644 index 0000000000000..2d4fe974c016b --- /dev/null +++ b/pkgs/development/compilers/llvm/15/libcxxabi/default.nix @@ -0,0 +1,97 @@ +{ lib, stdenv, llvm_meta, cmake, python3 +, monorepoSrc, runCommand, fetchpatch +, cxx-headers, libunwind, version +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation rec { + pname = "libcxxabi"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + mkdir -p "$out/libcxx/src" + cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/include "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/src/include "$out/libcxx/src" + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" + cp -r ${monorepoSrc}/runtimes "$out" + ''; + + sourceRoot = "${src.name}/runtimes"; + + outputs = [ "out" "dev" ]; + + postUnpack = lib.optionalString stdenv.isDarwin '' + export TRIPLE=x86_64-apple-darwin + '' + lib.optionalString stdenv.hostPlatform.isWasm '' + patch -p1 -d llvm -i ${./wasm.patch} + ''; + + prePatch = '' + cd ../${pname} + chmod -R u+w . + ''; + + patches = [ + ./gnu-install-dirs.patch + + # https://reviews.llvm.org/D132298, Allow building libcxxabi alone + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/e6a0800532bb409f6d1c62f3698bdd6994a877dc.patch"; + sha256 = "1xyjd56m4pfwq8p3xh6i8lhkk9kq15jaml7qbhxdf87z4jjkk63a"; + stripLen = 1; + }) + ]; + + postPatch = '' + cd ../runtimes + ''; + + nativeBuildInputs = [ cmake python3 ]; + buildInputs = lib.optional (!stdenv.isDarwin && !stdenv.isFreeBSD && !stdenv.hostPlatform.isWasm) libunwind; + + cmakeFlags = [ + "-DLLVM_ENABLE_RUNTIMES=libcxxabi" + "-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1" + ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXXABI_ENABLE_THREADS=OFF" + "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optionals (!enableShared) [ + "-DLIBCXXABI_ENABLE_SHARED=OFF" + ]; + + preInstall = lib.optionalString stdenv.isDarwin '' + for file in lib/*.dylib; do + # this should be done in CMake, but having trouble figuring out + # the magic combination of necessary CMake variables + # if you fancy a try, take a look at + # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling + install_name_tool -id $out/$file $file + done + ''; + + postInstall = '' + mkdir -p "$dev/include" + install -m 644 ../../${pname}/include/${if stdenv.isDarwin then "*" else "cxxabi.h"} "$dev/include" + ''; + + meta = llvm_meta // { + homepage = "https://libcxxabi.llvm.org/"; + description = "Provides C++ standard library support"; + longDescription = '' + libc++abi is a new implementation of low level support for a standard C++ library. + ''; + # "All of the code in libc++abi is dual licensed under the MIT license and + # the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + maintainers = llvm_meta.maintainers ++ [ lib.maintainers.vlstill ]; + }; +} diff --git a/pkgs/development/compilers/llvm/15/libcxxabi/gnu-install-dirs.patch b/pkgs/development/compilers/llvm/15/libcxxabi/gnu-install-dirs.patch new file mode 100644 index 0000000000000..fa587612aaf63 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/libcxxabi/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b8326d08d23a..a1e36f713161 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -187,7 +187,7 @@ set(LIBCXXABI_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR}) + set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH + "Path where built libc++abi libraries should be installed.") + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR}) +@@ -201,7 +201,7 @@ else() + set(LIBCXXABI_HEADER_DIR ${CMAKE_BINARY_DIR}) + set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX}) + endif() +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH + "Path where built libc++abi libraries should be installed.") + endif() + diff --git a/pkgs/development/compilers/llvm/15/libcxxabi/wasm.patch b/pkgs/development/compilers/llvm/15/libcxxabi/wasm.patch new file mode 100644 index 0000000000000..4ebfe46aa813d --- /dev/null +++ b/pkgs/development/compilers/llvm/15/libcxxabi/wasm.patch @@ -0,0 +1,16 @@ +diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake +index 15497d405e0..33f7f18193a 100644 +--- a/cmake/modules/HandleLLVMOptions.cmake ++++ b/cmake/modules/HandleLLVMOptions.cmake +@@ -127,7 +127,10 @@ else(WIN32) + set(LLVM_HAVE_LINK_VERSION_SCRIPT 1) + endif() + else(FUCHSIA OR UNIX) +- MESSAGE(SEND_ERROR "Unable to determine platform") ++ if(${CMAKE_SYSTEM_NAME} MATCHES "Wasi") ++ else() ++ MESSAGE(SEND_ERROR "Unable to determine platform") ++ endif() + endif(FUCHSIA OR UNIX) + endif(WIN32) + diff --git a/pkgs/development/compilers/llvm/15/libunwind/default.nix b/pkgs/development/compilers/llvm/15/libunwind/default.nix new file mode 100644 index 0000000000000..0b59fff1357e1 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/libunwind/default.nix @@ -0,0 +1,61 @@ +{ lib, stdenv, llvm_meta, version +, monorepoSrc, runCommand +, cmake +, python3 +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation rec { + pname = "libunwind"; + inherit version; + + # I am not so comfortable giving libc++ and friends the whole monorepo as + # requested, so I filter it to what is needed. + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + mkdir -p "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx" + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" + cp -r ${monorepoSrc}/runtimes "$out" + ''; + + sourceRoot = "${src.name}/runtimes"; + + prePatch = '' + cd ../${pname} + chmod -R u+w . + ''; + + patches = [ + ./gnu-install-dirs.patch + ]; + + postPatch = '' + cd ../runtimes + ''; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ cmake python3 ]; + + cmakeFlags = [ + "-DLLVM_ENABLE_RUNTIMES=libunwind" + ] ++ lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF"; + + meta = llvm_meta // { + # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst + homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library"; + description = "LLVM's unwinder library"; + longDescription = '' + The unwind library provides a family of _Unwind_* functions implementing + the language-neutral stack unwinding portion of the Itanium C++ ABI (Level + I). It is a dependency of the C++ ABI library, and sometimes is a + dependency of other runtimes. + ''; + }; +} diff --git a/pkgs/development/compilers/llvm/15/libunwind/gnu-install-dirs.patch b/pkgs/development/compilers/llvm/15/libunwind/gnu-install-dirs.patch new file mode 100644 index 0000000000000..edfb2a8760bd6 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/libunwind/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 5a06805f05f1..86a50329e6a8 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -117,7 +117,7 @@ set(LIBUNWIND_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH + + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH + "Path where built libunwind libraries should be installed.") + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR}) +@@ -129,7 +129,7 @@ else() + else() + set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX}) + endif() +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH + "Path where built libunwind libraries should be installed.") + endif() + diff --git a/pkgs/development/compilers/llvm/15/lld/default.nix b/pkgs/development/compilers/llvm/15/lld/default.nix new file mode 100644 index 0000000000000..9d17766436845 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/lld/default.nix @@ -0,0 +1,53 @@ +{ lib, stdenv, llvm_meta +, buildLlvmTools +, monorepoSrc, runCommand +, cmake +, libxml2 +, libllvm +, version +}: + +stdenv.mkDerivation rec { + pname = "lld"; + inherit version; + + # Blank llvm dir just so relative path works + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + mkdir -p "$out/libunwind" + cp -r ${monorepoSrc}/libunwind/include "$out/libunwind" + mkdir -p "$out/llvm" + ''; + + sourceRoot = "${src.name}/${pname}"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake ]; + buildInputs = [ libllvm libxml2 ]; + + cmakeFlags = [ + "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/lld" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ]; + + outputs = [ "out" "lib" "dev" ]; + + meta = llvm_meta // { + homepage = "https://lld.llvm.org/"; + description = "The LLVM linker (unwrapped)"; + longDescription = '' + LLD is a linker from the LLVM project that is a drop-in replacement for + system linkers and runs much faster than them. It also provides features + that are useful for toolchain developers. + The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and + WebAssembly in descending order of completeness. Internally, LLD consists + of several different linkers. + ''; + }; +} diff --git a/pkgs/development/compilers/llvm/15/lld/gnu-install-dirs.patch b/pkgs/development/compilers/llvm/15/lld/gnu-install-dirs.patch new file mode 100644 index 0000000000000..ea62b2ad50c75 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/lld/gnu-install-dirs.patch @@ -0,0 +1,46 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index dcc649629a4b..58dca54642e4 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -70,13 +70,15 @@ if(LLD_BUILT_STANDALONE) + if (NOT LLVM_CONFIG_FOUND) + # Pull values from LLVMConfig.cmake. We can drop this once the llvm-config + # path is removed. +- set(MAIN_INCLUDE_DIR "${LLVM_INCLUDE_DIR}") ++ set(INCLUDE_DIRS ${LLVM_INCLUDE_DIRS}) + set(LLVM_OBJ_DIR "${LLVM_BINARY_DIR}") + # N.B. this is just a default value, the CACHE PATHs below can be overridden. + set(MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm") ++ else() ++ set(INCLUDE_DIRS "${LLVM_BINARY_DIR}/include" "${MAIN_INCLUDE_DIR}") + endif() + +- set(LLVM_MAIN_INCLUDE_DIR "${MAIN_INCLUDE_DIR}" CACHE PATH "Path to llvm/include") ++ set(LLVM_INCLUDE_DIRS ${INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed") + set(LLVM_BINARY_DIR "${LLVM_OBJ_ROOT}" CACHE PATH "Path to LLVM build tree") + set(LLVM_MAIN_SRC_DIR "${MAIN_SRC_DIR}" CACHE PATH "Path to LLVM source tree") + +@@ -95,7 +97,7 @@ if(LLD_BUILT_STANDALONE) + + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") + +- include_directories("${LLVM_BINARY_DIR}/include" ${LLVM_INCLUDE_DIRS}) ++ include_directories(${LLVM_INCLUDE_DIRS}) + link_directories(${LLVM_LIBRARY_DIRS}) + + if(LLVM_INCLUDE_TESTS) +diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake +index d3924f7243d4..42a7cd62281c 100644 +--- a/cmake/modules/AddLLD.cmake ++++ b/cmake/modules/AddLLD.cmake +@@ -18,8 +18,8 @@ macro(add_lld_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_lldtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + + if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES) diff --git a/pkgs/development/compilers/llvm/15/lldb/default.nix b/pkgs/development/compilers/llvm/15/lldb/default.nix new file mode 100644 index 0000000000000..6e6fe5cf0671d --- /dev/null +++ b/pkgs/development/compilers/llvm/15/lldb/default.nix @@ -0,0 +1,145 @@ +{ lib, stdenv, llvm_meta +, runCommand +, monorepoSrc +, cmake +, zlib +, ncurses +, swig +, which +, libedit +, libxml2 +, libllvm +, libclang +, python3 +, version +, libobjc +, xpc +, Foundation +, bootstrap_cmds +, Carbon +, Cocoa +, lit +, makeWrapper +, enableManpages ? false +, lua5_3 +}: + +stdenv.mkDerivation (rec { + pname = "lldb"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + ''; + + sourceRoot = "${src.name}/${pname}"; + + patches = [ + ./procfs.patch + (runCommand "resource-dir.patch" { + clangLibDir = "${libclang.lib}/lib"; + } '' + substitute '${./resource-dir.patch}' "$out" --subst-var clangLibDir + '') + ./gnu-install-dirs.patch + ]; + + outputs = [ "out" "lib" "dev" ]; + + nativeBuildInputs = [ + cmake python3 which swig lit makeWrapper lua5_3 + ] ++ lib.optionals enableManpages [ + python3.pkgs.sphinx python3.pkgs.recommonmark + ]; + + buildInputs = [ + ncurses + zlib + libedit + libxml2 + libllvm + ] ++ lib.optionals stdenv.isDarwin [ + libobjc + xpc + Foundation + bootstrap_cmds + Carbon + Cocoa + ]; + + hardeningDisable = [ "format" ]; + + cmakeFlags = [ + "-DLLDB_INCLUDE_TESTS=${if doCheck then "YES" else "NO"}" + "-DLLVM_ENABLE_RTTI=OFF" + "-DClang_DIR=${libclang.dev}/lib/cmake" + "-DLLVM_EXTERNAL_LIT=${lit}/bin/lit" + ] ++ lib.optionals stdenv.isDarwin [ + "-DLLDB_USE_SYSTEM_DEBUGSERVER=ON" + ] ++ lib.optionals (!stdenv.isDarwin) [ + "-DLLDB_CODESIGN_IDENTITY=" # codesigning makes nondeterministic + ] ++ lib.optionals enableManpages [ + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + ] ++ lib.optionals doCheck [ + "-DLLDB_TEST_C_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" + "-DLLDB_TEST_CXX_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++" + ]; + + doCheck = false; + + installCheckPhase = '' + if [ ! -e "$lib/${python3.sitePackages}/lldb/_lldb.so" ] ; then + return 1; + fi + ''; + + postInstall = '' + wrapProgram $out/bin/lldb --prefix PYTHONPATH : $lib/${python3.sitePackages}/ + + # Editor support + # vscode: + install -D ../tools/lldb-vscode/package.json $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/package.json + mkdir -p $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin + ln -s $out/bin/lldb-vscode $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin + ''; + + meta = llvm_meta // { + homepage = "https://lldb.llvm.org/"; + description = "A next-generation high-performance debugger"; + longDescription = '' + LLDB is a next generation, high-performance debugger. It is built as a set + of reusable components which highly leverage existing libraries in the + larger LLVM Project, such as the Clang expression parser and LLVM + disassembler. + ''; + }; +} // lib.optionalAttrs enableManpages { + pname = "lldb-manpages"; + + buildPhase = '' + make docs-lldb-man + ''; + + propagatedBuildInputs = []; + + # manually install lldb man page + installPhase = '' + mkdir -p $out/share/man/man1 + install docs/man/lldb.1 -t $out/share/man/man1/ + ''; + + postPatch = null; + postInstall = null; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man pages for LLDB ${version}"; + }; +}) diff --git a/pkgs/development/compilers/llvm/15/lldb/gnu-install-dirs.patch b/pkgs/development/compilers/llvm/15/lldb/gnu-install-dirs.patch new file mode 100644 index 0000000000000..4388f5c7f593f --- /dev/null +++ b/pkgs/development/compilers/llvm/15/lldb/gnu-install-dirs.patch @@ -0,0 +1,23 @@ +diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake +index 3291a7c808e1..b27d27ce6a87 100644 +--- a/cmake/modules/AddLLDB.cmake ++++ b/cmake/modules/AddLLDB.cmake +@@ -109,7 +109,7 @@ function(add_lldb_library name) + endif() + + if(PARAM_SHARED) +- set(install_dest lib${LLVM_LIBDIR_SUFFIX}) ++ set(install_dest ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(PARAM_INSTALL_PREFIX) + set(install_dest ${PARAM_INSTALL_PREFIX}) + endif() +diff --git a/tools/intel-features/CMakeLists.txt b/tools/intel-features/CMakeLists.txt +index 7d48491ec89a..c04543585588 100644 +--- a/tools/intel-features/CMakeLists.txt ++++ b/tools/intel-features/CMakeLists.txt +@@ -30,4 +30,4 @@ add_lldb_library(lldbIntelFeatures SHARED + ) + + install(TARGETS lldbIntelFeatures +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) diff --git a/pkgs/development/compilers/llvm/15/lldb/procfs.patch b/pkgs/development/compilers/llvm/15/lldb/procfs.patch new file mode 100644 index 0000000000000..a798216aa62c4 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/lldb/procfs.patch @@ -0,0 +1,40 @@ +--- a/source/Plugins/Process/Linux/Procfs.h ++++ b/source/Plugins/Process/Linux/Procfs.h +@@ -10,6 +10,7 @@ + // sys/procfs.h on Android/Linux for all supported architectures. + + #include ++#include + + #include "lldb/lldb-types.h" + +@@ -17,23 +18,13 @@ + + #include + +-#ifdef __ANDROID__ +-#if defined(__arm64__) || defined(__aarch64__) +-typedef unsigned long elf_greg_t; +-typedef elf_greg_t +- elf_gregset_t[(sizeof(struct user_pt_regs) / sizeof(elf_greg_t))]; +-typedef struct user_fpsimd_state elf_fpregset_t; +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#elif defined(__mips__) +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#endif +-#else // __ANDROID__ ++#if !defined(__GLIBC__) && defined(__powerpc__) ++#define pt_regs musl_pt_regs ++#include ++#undef pt_regs ++#else + #include +-#endif // __ANDROID__ ++#endif + + namespace lldb_private { + namespace process_linux { diff --git a/pkgs/development/compilers/llvm/15/lldb/resource-dir.patch b/pkgs/development/compilers/llvm/15/lldb/resource-dir.patch new file mode 100644 index 0000000000000..e0db80afeb9f7 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/lldb/resource-dir.patch @@ -0,0 +1,13 @@ +diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake +index 37364341ff8b..7f74c1a3e257 100644 +--- a/cmake/modules/LLDBConfig.cmake ++++ b/cmake/modules/LLDBConfig.cmake +@@ -257,7 +257,7 @@ if (NOT TARGET clang-resource-headers) + # Iterate over the possible places where the external resource directory + # could be and pick the first that exists. + foreach(CANDIDATE "${Clang_DIR}/../.." "${LLVM_DIR}" "${LLVM_LIBRARY_DIRS}" +- "${LLVM_BUILD_LIBRARY_DIR}" ++ "${LLVM_BUILD_LIBRARY_DIR}" "@clangLibDir@" + "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}") + # Build the resource directory path by appending 'clang/'. + set(CANDIDATE_RESOURCE_DIR "${CANDIDATE}/clang/${LLDB_CLANG_RESOURCE_DIR_NAME}") diff --git a/pkgs/development/compilers/llvm/15/llvm/default.nix b/pkgs/development/compilers/llvm/15/llvm/default.nix new file mode 100644 index 0000000000000..656c226574a41 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/llvm/default.nix @@ -0,0 +1,267 @@ +{ lib, stdenv, llvm_meta +, pkgsBuildBuild +, monorepoSrc +, runCommand +, fetchpatch +, cmake +, python3 +, libffi +, libbfd +, libpfm +, libxml2 +, ncurses +, version +, release_version +, zlib +, which +, buildLlvmTools +, debugVersion ? false +, enableManpages ? false +, enableSharedLibraries ? !stdenv.hostPlatform.isStatic +, enablePFM ? !(stdenv.isDarwin + || stdenv.isAarch64 # broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 + || stdenv.isAarch32 # broken for the armv7l builder +) +, enablePolly ? false +} @args: + +let + inherit (lib) optional optionals optionalString; + + # Used when creating a version-suffixed symlink of libLLVM.dylib + shortVersion = with lib; + concatStringsSep "." (take 1 (splitString "." release_version)); + +in stdenv.mkDerivation (rec { + pname = "llvm"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} ('' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + cp -r ${monorepoSrc}/third-party "$out" + '' + lib.optionalString enablePolly '' + cp -r ${monorepoSrc}/polly "$out/llvm/tools" + ''); + + sourceRoot = "${src.name}/${pname}"; + + outputs = [ "out" "lib" "dev" "python" ]; + + nativeBuildInputs = [ cmake python3 ] + ++ optionals enableManpages [ python3.pkgs.sphinx python3.pkgs.recommonmark ]; + + buildInputs = [ libxml2 libffi ] + ++ optional enablePFM libpfm; # exegesis + + propagatedBuildInputs = [ ncurses zlib ]; + + checkInputs = [ which ]; + + patches = [ + ./gnu-install-dirs.patch + ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; + + postPatch = optionalString stdenv.isDarwin '' + substituteInPlace cmake/modules/AddLLVM.cmake \ + --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ + --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" + '' + '' + # FileSystem permissions tests fail with various special bits + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "Path.cpp" "" + rm unittests/Support/Path.cpp + substituteInPlace unittests/IR/CMakeLists.txt \ + --replace "PassBuilderCallbacksTest.cpp" "" + rm unittests/IR/PassBuilderCallbacksTest.cpp + rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test + '' + optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -i ${../../TLI-musl.patch} + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "add_subdirectory(DynamicLibrary)" "" + rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp + # valgrind unhappy with musl or glibc, but fails w/musl only + rm test/CodeGen/AArch64/wineh4.mir + '' + optionalString stdenv.hostPlatform.isAarch32 '' + # skip failing X86 test cases on 32-bit ARM + rm test/DebugInfo/X86/convert-debugloc.ll + rm test/DebugInfo/X86/convert-inlined.ll + rm test/DebugInfo/X86/convert-linked.ll + rm test/tools/dsymutil/X86/op-convert.test + rm test/tools/gold/X86/split-dwarf.ll + rm test/tools/llvm-dwarfdump/X86/prettyprint_types.s + rm test/tools/llvm-dwarfdump/X86/simplified-template-names.s + '' + optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' + # Seems to require certain floating point hardware (NEON?) + rm test/ExecutionEngine/frem.ll + '' + '' + patchShebangs test/BugPoint/compile-custom.ll.py + ''; + + preConfigure = '' + # Workaround for configure flags that need to have spaces + cmakeFlagsArray+=( + -DLLVM_LIT_ARGS='-svj''${NIX_BUILD_CORES} --no-progress-bar' + ) + ''; + + # hacky fix: created binaries need to be run before installation + preBuild = '' + mkdir -p $out/ + ln -sv $PWD/lib $out + ''; + + # E.g. mesa.drivers use the build-id as a cache key (see #93946): + LDFLAGS = optionalString (enableSharedLibraries && !stdenv.isDarwin) "-Wl,--build-id=sha1"; + + cmakeFlags = with stdenv; let + # These flags influence llvm-config's BuildVariables.inc in addition to the + # general build. We need to make sure these are also passed via + # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native + # will return different results from the cross llvm-config. + # + # Some flags don't need to be repassed because LLVM already does so (like + # CMAKE_BUILD_TYPE), others are irrelevant to the result. + flagsForLlvmConfig = [ + "-DLLVM_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/llvm" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ optionals enableSharedLibraries [ + "-DLLVM_LINK_LLVM_DYLIB=ON" + ]; + in flagsForLlvmConfig ++ [ + "-DCMAKE_BUILD_TYPE=${if debugVersion then "Debug" else "Release"}" + "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc + "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" + "-DLLVM_ENABLE_FFI=ON" + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_ENABLE_DUMP=ON" + ] ++ optionals stdenv.hostPlatform.isStatic [ + # Disables building of shared libs, -fPIC is still injected by cc-wrapper + "-DLLVM_ENABLE_PIC=OFF" + "-DLLVM_BUILD_STATIC=ON" + # libxml2 needs to be disabled because the LLVM build system ignores its .la + # file and doesn't link zlib as well. + # https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812 + "-DLLVM_ENABLE_LIBXML2=OFF" + ] ++ optionals enableManpages [ + "-DLLVM_BUILD_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ optionals (!isDarwin) [ + "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" + ] ++ optionals isDarwin [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DCAN_TARGET_i386=false" + ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DCMAKE_CROSSCOMPILING=True" + "-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ( + let + nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; + nativeBintools = nativeCC.bintools.bintools; + nativeToolchainFlags = [ + "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" + "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" + "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" + "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" + "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" + ]; + # We need to repass the custom GNUInstallDirs values, otherwise CMake + # will choose them for us, leading to wrong results in llvm-config-native + nativeInstallFlags = [ + "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" + "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin" + "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include" + "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" + "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" + ]; + in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" + + lib.concatStringsSep ";" (lib.concatLists [ + flagsForLlvmConfig + nativeToolchainFlags + nativeInstallFlags + ]) + ) + ]; + + postBuild = '' + rm -fR $out + ''; + + preCheck = '' + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib + ''; + + postInstall = '' + mkdir -p $python/share + mv $out/share/opt-viewer $python/share/opt-viewer + moveToOutput "bin/llvm-config*" "$dev" + substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ + --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \ + --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" + substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ + --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "'"$lib"'")' + '' + + optionalString (stdenv.isDarwin && enableSharedLibraries) '' + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib + '' + + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native + ''; + + doCheck = stdenv.isLinux && (!stdenv.isx86_32) && (!stdenv.hostPlatform.isMusl) + && (stdenv.hostPlatform == stdenv.buildPlatform); + + checkTarget = "check-all"; + + # For the update script: + passthru.monorepoSrc = monorepoSrc; + + requiredSystemFeatures = [ "big-parallel" ]; + meta = llvm_meta // { + homepage = "https://llvm.org/"; + description = "A collection of modular and reusable compiler and toolchain technologies"; + longDescription = '' + The LLVM Project is a collection of modular and reusable compiler and + toolchain technologies. Despite its name, LLVM has little to do with + traditional virtual machines. The name "LLVM" itself is not an acronym; it + is the full name of the project. + LLVM began as a research project at the University of Illinois, with the + goal of providing a modern, SSA-based compilation strategy capable of + supporting both static and dynamic compilation of arbitrary programming + languages. Since then, LLVM has grown to be an umbrella project consisting + of a number of subprojects, many of which are being used in production by + a wide variety of commercial and open source projects as well as being + widely used in academic research. Code in the LLVM project is licensed + under the "Apache 2.0 License with LLVM exceptions". + ''; + }; +} // lib.optionalAttrs enableManpages { + pname = "llvm-manpages"; + + buildPhase = '' + make docs-llvm-man + ''; + + propagatedBuildInputs = []; + + installPhase = '' + make -C docs install + ''; + + postPatch = null; + postInstall = null; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man pages for LLVM ${version}"; + }; +}) diff --git a/pkgs/development/compilers/llvm/15/llvm/gnu-install-dirs-polly.patch b/pkgs/development/compilers/llvm/15/llvm/gnu-install-dirs-polly.patch new file mode 100644 index 0000000000000..98e998e65a961 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/llvm/gnu-install-dirs-polly.patch @@ -0,0 +1,102 @@ +diff --git a/tools/polly/CMakeLists.txt b/tools/polly/CMakeLists.txt +index ca7c04c565bb..6a6155806ffa 100644 +--- a/tools/polly/CMakeLists.txt ++++ b/tools/polly/CMakeLists.txt +@@ -3,6 +3,8 @@ if (NOT DEFINED LLVM_MAIN_SRC_DIR) + project(Polly) + cmake_minimum_required(VERSION 3.13.4) + ++ include(GNUInstallDirs) ++ + # Where is LLVM installed? + find_package(LLVM CONFIG REQUIRED) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) +@@ -122,13 +124,13 @@ include_directories( + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + ) + + install(DIRECTORY ${POLLY_BINARY_DIR}/include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE +diff --git a/tools/polly/cmake/CMakeLists.txt b/tools/polly/cmake/CMakeLists.txt +index 7cc129ba2e90..137be25e4b80 100644 +--- a/tools/polly/cmake/CMakeLists.txt ++++ b/tools/polly/cmake/CMakeLists.txt +@@ -79,18 +79,18 @@ file(GENERATE + + # Generate PollyConfig.cmake for the install tree. + unset(POLLY_EXPORTS) +-set(POLLY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") ++set(POLLY_INSTALL_PREFIX "") + set(POLLY_CONFIG_LLVM_CMAKE_DIR "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}") ++set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") ++set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + if (POLLY_BUNDLED_ISL) + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" +- "${POLLY_INSTALL_PREFIX}/include/polly" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}/polly" + ) + else() + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_INCLUDEDIR}" + ${ISL_INCLUDE_DIRS} + ) + endif() +@@ -100,12 +100,12 @@ endif() + foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS) + get_target_property(tgt_type ${tgt} TYPE) + if (tgt_type STREQUAL "EXECUTABLE") +- set(tgt_prefix "bin/") ++ set(tgt_prefix "${CMAKE_INSTALL_BINDIR}/") + else() +- set(tgt_prefix "lib/") ++ set(tgt_prefix "${CMAKE_INSTALL_LIBDIR}/") + endif() + +- set(tgt_path "${CMAKE_INSTALL_PREFIX}/${tgt_prefix}$") ++ set(tgt_path "${tgt_prefix}$") + file(RELATIVE_PATH tgt_path ${POLLY_CONFIG_CMAKE_DIR} ${tgt_path}) + + if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY") +diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake +index 518a09b45a42..bd9d6f5542ad 100644 +--- a/tools/polly/cmake/polly_macros.cmake ++++ b/tools/polly/cmake/polly_macros.cmake +@@ -44,8 +44,8 @@ macro(add_polly_library name) + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly") + install(TARGETS ${name} + EXPORT LLVMExports +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) + endmacro(add_polly_library) +diff --git a/tools/polly/lib/External/CMakeLists.txt b/tools/polly/lib/External/CMakeLists.txt +index e3a5683fccdc..293b482eb28a 100644 +--- a/tools/polly/lib/External/CMakeLists.txt ++++ b/tools/polly/lib/External/CMakeLists.txt +@@ -290,7 +290,7 @@ if (POLLY_BUNDLED_ISL) + install(DIRECTORY + ${ISL_SOURCE_DIR}/include/ + ${ISL_BINARY_DIR}/include/ +- DESTINATION include/polly ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/polly + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE diff --git a/pkgs/development/compilers/llvm/15/llvm/gnu-install-dirs.patch b/pkgs/development/compilers/llvm/15/llvm/gnu-install-dirs.patch new file mode 100644 index 0000000000000..0ef317af8cc75 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/llvm/gnu-install-dirs.patch @@ -0,0 +1,138 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 45399dc0537e..5d946e9e6583 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -942,7 +942,7 @@ if (NOT TENSORFLOW_AOT_PATH STREQUAL "") + add_subdirectory(${TENSORFLOW_AOT_PATH}/xla_aot_runtime_src + ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tf_runtime) + install(TARGETS tf_xla_runtime EXPORT LLVMExports +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime) ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime) + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime) + # Once we add more modules, we should handle this more automatically. + if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_INLINERSIZEMODEL) +diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake +index 057431208322..56f0dcb258da 100644 +--- a/cmake/modules/AddLLVM.cmake ++++ b/cmake/modules/AddLLVM.cmake +@@ -844,8 +844,8 @@ macro(add_llvm_library name) + get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella}) + install(TARGETS ${name} + ${export_to_llvmexports} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name} ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name} + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${name}) + + if (NOT LLVM_ENABLE_IDE) +@@ -2007,7 +2007,7 @@ function(llvm_install_library_symlink name dest type) + set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX}) + set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX}) + +- set(output_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 AND "${type}" STREQUAL "SHARED") + set(output_dir "${CMAKE_INSTALL_BINDIR}") + endif() +@@ -2271,15 +2271,15 @@ function(llvm_setup_rpath name) + + if (APPLE) + set(_install_name_dir INSTALL_NAME_DIR "@rpath") +- set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "@loader_path/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND BUILD_SHARED_LIBS) + # $ORIGIN is not interpreted at link time by aix ld. + # Since BUILD_SHARED_LIBS is only recommended for use by developers, + # hardcode the rpath to build/install lib dir first in this mode. + # FIXME: update this when there is better solution. +- set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + elseif(UNIX) +- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") + set_property(TARGET ${name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-z,origin ") +diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake +index 891c9e6d618c..8d963f3b0069 100644 +--- a/cmake/modules/AddOCaml.cmake ++++ b/cmake/modules/AddOCaml.cmake +@@ -147,9 +147,9 @@ function(add_ocaml_library name) + endforeach() + + if( APPLE ) +- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + elseif( UNIX ) +- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + endif() + list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") + +diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt +index d4b0ab959148..26ed981fd09f 100644 +--- a/cmake/modules/CMakeLists.txt ++++ b/cmake/modules/CMakeLists.txt +@@ -128,7 +128,7 @@ set(LLVM_CONFIG_INCLUDE_DIRS + ) + list(REMOVE_DUPLICATES LLVM_CONFIG_INCLUDE_DIRS) + +-extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "lib\${LLVM_LIBDIR_SUFFIX}") ++extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}") + set(LLVM_CONFIG_LIBRARY_DIRS + "${LLVM_CONFIG_LIBRARY_DIR}" + # FIXME: Should there be other entries here? +diff --git a/docs/CMake.rst b/docs/CMake.rst +index 879b7b231d4c..9c31d14e8950 100644 +--- a/docs/CMake.rst ++++ b/docs/CMake.rst +@@ -250,7 +250,7 @@ description is in `LLVM-related variables`_ below. + **LLVM_LIBDIR_SUFFIX**:STRING + Extra suffix to append to the directory where libraries are to be + installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` +- to install libraries to ``/usr/lib64``. ++ to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``. + + **LLVM_PARALLEL_{COMPILE,LINK}_JOBS**:STRING + Building the llvm toolchain can use a lot of resources, particularly +@@ -284,6 +284,10 @@ manual, or execute ``cmake --help-variable VARIABLE_NAME``. + The path to install executables, relative to the *CMAKE_INSTALL_PREFIX*. + Defaults to "bin". + ++**CMAKE_INSTALL_LIBDIR**:PATH ++ The path to install libraries, relative to the *CMAKE_INSTALL_PREFIX*. ++ Defaults to "lib". ++ + **CMAKE_INSTALL_INCLUDEDIR**:PATH + The path to install header files, relative to the *CMAKE_INSTALL_PREFIX*. + Defaults to "include". +diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in +index 370005cd8d7d..7e790bc52111 100644 +--- a/tools/llvm-config/BuildVariables.inc.in ++++ b/tools/llvm-config/BuildVariables.inc.in +@@ -23,6 +23,7 @@ + #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" + #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" + #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" ++#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@" + #define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" + #define LLVM_INSTALL_PACKAGE_DIR "@LLVM_INSTALL_PACKAGE_DIR@" + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp +index 2c6c55f89d38..f6d2068a0827 100644 +--- a/tools/llvm-config/llvm-config.cpp ++++ b/tools/llvm-config/llvm-config.cpp +@@ -369,7 +369,11 @@ int main(int argc, char **argv) { + sys::fs::make_absolute(ActivePrefix, Path); + ActiveBinDir = std::string(Path.str()); + } +- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; ++ { ++ SmallString<256> Path(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX); ++ sys::fs::make_absolute(ActivePrefix, Path); ++ ActiveLibDir = std::string(Path.str()); ++ } + { + SmallString<256> Path(LLVM_INSTALL_PACKAGE_DIR); + sys::fs::make_absolute(ActivePrefix, Path); diff --git a/pkgs/development/compilers/llvm/15/openmp/default.nix b/pkgs/development/compilers/llvm/15/openmp/default.nix new file mode 100644 index 0000000000000..9355fe667f0cc --- /dev/null +++ b/pkgs/development/compilers/llvm/15/openmp/default.nix @@ -0,0 +1,67 @@ +{ lib +, stdenv +, llvm_meta +, monorepoSrc +, runCommand +, cmake +, llvm +, lit +, clang-unwrapped +, perl +, pkg-config +, version +}: + +stdenv.mkDerivation rec { + pname = "openmp"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + ''; + + sourceRoot = "${src.name}/${pname}"; + + patches = [ + ./fix-find-tool.patch + ./gnu-install-dirs.patch + ./run-lit-directly.patch + ]; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ cmake perl pkg-config lit ]; + buildInputs = [ llvm ]; + + # Unsup:Pass:XFail:Fail + # 26:267:16:8 + doCheck = false; + checkTarget = "check-openmp"; + + preCheck = '' + patchShebangs ../tools/archer/tests/deflake.bash + ''; + + cmakeFlags = [ + "-DCLANG_TOOL=${clang-unwrapped}/bin/clang" + "-DOPT_TOOL=${llvm}/bin/opt" + "-DLINK_TOOL=${llvm}/bin/llvm-link" + ]; + + meta = llvm_meta // { + homepage = "https://openmp.llvm.org/"; + description = "Support for the OpenMP language"; + longDescription = '' + The OpenMP subproject of LLVM contains the components required to build an + executable OpenMP program that are outside the compiler itself. + Contains the code for the runtime library against which code compiled by + "clang -fopenmp" must be linked before it can run and the library that + supports offload to target devices. + ''; + # "All of the code is dual licensed under the MIT license and the UIUC + # License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/pkgs/development/compilers/llvm/15/openmp/fix-find-tool.patch b/pkgs/development/compilers/llvm/15/openmp/fix-find-tool.patch new file mode 100644 index 0000000000000..103b054ed1763 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/openmp/fix-find-tool.patch @@ -0,0 +1,18 @@ +diff --git a/libomptarget/DeviceRTL/CMakeLists.txt b/libomptarget/DeviceRTL/CMakeLists.txt +index ce66214822a2..6ab7b33c95da 100644 +--- a/libomptarget/DeviceRTL/CMakeLists.txt ++++ b/libomptarget/DeviceRTL/CMakeLists.txt +@@ -27,10 +27,10 @@ endif() + if (LLVM_DIR) + # Builds that use pre-installed LLVM have LLVM_DIR set. + # A standalone or LLVM_ENABLE_RUNTIMES=openmp build takes this route +- find_program(CLANG_TOOL clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) ++ find_program(CLANG_TOOL clang PATHS ${LLVM_TOOLS_BINARY_DIR}) + find_program(LINK_TOOL llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} +- NO_DEFAULT_PATH) +- find_program(OPT_TOOL opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) ++ ) ++ find_program(OPT_TOOL opt PATHS ${LLVM_TOOLS_BINARY_DIR}) + if ((NOT CLANG_TOOL) OR (NOT LINK_TOOL) OR (NOT OPT_TOOL)) + libomptarget_say("Not building DeviceRTL. Missing clang: ${CLANG_TOOL}, llvm-link: ${LINK_TOOL} or opt: ${OPT_TOOL}") + return() diff --git a/pkgs/development/compilers/llvm/15/openmp/gnu-install-dirs.patch b/pkgs/development/compilers/llvm/15/openmp/gnu-install-dirs.patch new file mode 100644 index 0000000000000..77a93208832a1 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/openmp/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b6ddbe90516d..311ab1d50e7f 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -29,7 +29,7 @@ if (OPENMP_STANDALONE_BUILD) + set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING + "Suffix of lib installation directory, e.g. 64 => lib64") + # Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR. +- set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}") ++ set(OPENMP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}${OPENMP_LIBDIR_SUFFIX}") + + # Group test settings. + set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING +@@ -40,7 +40,7 @@ if (OPENMP_STANDALONE_BUILD) + else() + set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR}) + # If building in tree, we honor the same install suffix LLVM uses. +- set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}") ++ set(OPENMP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + + if (NOT MSVC) + set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang) diff --git a/pkgs/development/compilers/llvm/15/openmp/run-lit-directly.patch b/pkgs/development/compilers/llvm/15/openmp/run-lit-directly.patch new file mode 100644 index 0000000000000..1e952fdc36a8f --- /dev/null +++ b/pkgs/development/compilers/llvm/15/openmp/run-lit-directly.patch @@ -0,0 +1,12 @@ +diff --git a/cmake/OpenMPTesting.cmake b/cmake/OpenMPTesting.cmake +--- a/cmake/OpenMPTesting.cmake ++++ b/cmake/OpenMPTesting.cmake +@@ -185,7 +185,7 @@ function(add_openmp_testsuite target comment) + if (${OPENMP_STANDALONE_BUILD}) + set(LIT_ARGS ${OPENMP_LIT_ARGS} ${ARG_ARGS}) + add_custom_target(${target} +- COMMAND ${PYTHON_EXECUTABLE} ${OPENMP_LLVM_LIT_EXECUTABLE} ${LIT_ARGS} ${ARG_UNPARSED_ARGUMENTS} ++ COMMAND ${OPENMP_LLVM_LIT_EXECUTABLE} ${LIT_ARGS} ${ARG_UNPARSED_ARGUMENTS} + COMMENT ${comment} + DEPENDS ${ARG_DEPENDS} + USES_TERMINAL diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 761424d53b540..7181f4bde9d23 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -13585,6 +13585,7 @@ with pkgs; clang_12 = llvmPackages_12.clang; clang_13 = llvmPackages_13.clang; clang_14 = llvmPackages_14.clang; + clang_15 = llvmPackages_15.clang; clang-tools = callPackage ../development/tools/clang-tools { llvmPackages = llvmPackages_latest; @@ -13630,6 +13631,10 @@ with pkgs; llvmPackages = llvmPackages_14; }; + clang-tools_15 = callPackage ../development/tools/clang-tools { + llvmPackages = llvmPackages_15; + }; + clang-analyzer = callPackage ../development/tools/analysis/clang-analyzer { llvmPackages = llvmPackages_latest; inherit (llvmPackages_latest) clang; @@ -14624,6 +14629,7 @@ with pkgs; lld_12 = llvmPackages_12.lld; lld_13 = llvmPackages_13.lld; lld_14 = llvmPackages_14.lld; + lld_15 = llvmPackages_15.lld; lldb = llvmPackages_latest.lldb; lldb_5 = llvmPackages_5.lldb; @@ -14636,6 +14642,7 @@ with pkgs; lldb_12 = llvmPackages_12.lldb; lldb_13 = llvmPackages_13.lldb; lldb_14 = llvmPackages_14.lldb; + lldb_15 = llvmPackages_15.lldb; llvm = llvmPackages.llvm; llvm_5 = llvmPackages_5.llvm; @@ -14648,6 +14655,7 @@ with pkgs; llvm_12 = llvmPackages_12.llvm; llvm_13 = llvmPackages_13.llvm; llvm_14 = llvmPackages_14.llvm; + llvm_15 = llvmPackages_15.llvm; libllvm = llvmPackages.libllvm; llvm-manpages = llvmPackages.llvm-manpages; @@ -14740,6 +14748,14 @@ with pkgs; stdenv = gcc7Stdenv; })); + llvmPackages_15 = recurseIntoAttrs (callPackage ../development/compilers/llvm/15 ({ + inherit (stdenvAdapters) overrideCC; + buildLlvmTools = buildPackages.llvmPackages_15.tools; + targetLlvmLibraries = targetPackages.llvmPackages_15.libraries or llvmPackages_15.libraries; + } // lib.optionalAttrs (stdenv.hostPlatform.isi686 && stdenv.hostPlatform == stdenv.buildPlatform && buildPackages.stdenv.cc.isGNU) { + stdenv = gcc7Stdenv; + })); + llvmPackages_latest = llvmPackages_14; llvmPackages_rocm = recurseIntoAttrs (callPackage ../development/compilers/llvm/rocm { }); From 4fb70834afcc466d5e4552906b0e898dc0827d9e Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 8 Jan 2023 06:12:31 -0800 Subject: [PATCH 02/30] llvmPackages_15: apply some patches from `llvmPackages_14` See #194634 for details. PRs: - #191372 - #190936 - #82131 - #199844 - #197674 - #184408 - #193004 (cherry picked from commit 81ef82a029dfe2b67bf4fd306725ed3e3ed42a2c) --- pkgs/development/compilers/llvm/15/clang/default.nix | 2 ++ .../compilers/llvm/15/compiler-rt/default.nix | 5 +++++ pkgs/development/compilers/llvm/15/default.nix | 5 +++-- pkgs/development/compilers/llvm/15/libcxxabi/default.nix | 2 +- pkgs/development/compilers/llvm/15/lld/default.nix | 1 + pkgs/development/compilers/llvm/15/llvm/default.nix | 9 +++++---- pkgs/development/compilers/llvm/15/openmp/default.nix | 5 ++++- pkgs/top-level/all-packages.nix | 3 +-- 8 files changed, 22 insertions(+), 10 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/clang/default.nix b/pkgs/development/compilers/llvm/15/clang/default.nix index 3110bef09e969..d10c358ae1974 100644 --- a/pkgs/development/compilers/llvm/15/clang/default.nix +++ b/pkgs/development/compilers/llvm/15/clang/default.nix @@ -84,6 +84,7 @@ let fi mv $out/share/clang/*.py $python/share/clang rm $out/bin/c-index-test + patchShebangs $python/bin mkdir -p $dev/bin cp bin/clang-tblgen $dev/bin @@ -108,6 +109,7 @@ let of tools that can be built using the Clang frontend as a library to parse C/C++ code. ''; + mainProgram = "clang"; }; } // lib.optionalAttrs enableManpages { pname = "clang-manpages"; diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/default.nix b/pkgs/development/compilers/llvm/15/compiler-rt/default.nix index ce28a7ef9bbd0..7b0996845e2e5 100644 --- a/pkgs/development/compilers/llvm/15/compiler-rt/default.nix +++ b/pkgs/development/compilers/llvm/15/compiler-rt/default.nix @@ -1,6 +1,7 @@ { lib, stdenv, llvm_meta, version , monorepoSrc, runCommand , cmake, python3, libllvm, libcxxabi, libxcrypt +, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD }: let @@ -46,6 +47,8 @@ stdenv.mkDerivation { "-DCOMPILER_RT_BUILD_PROFILE=OFF" "-DCOMPILER_RT_BUILD_MEMPROF=OFF" "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary + ] ++ lib.optionals (useLLVM || bareMetal) [ + "-DCOMPILER_RT_BUILD_PROFILE=OFF" ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ "-DCMAKE_C_COMPILER_WORKS=ON" "-DCMAKE_CXX_COMPILER_WORKS=ON" @@ -107,6 +110,8 @@ stdenv.mkDerivation { 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 + '' + lib.optionalString doFakeLibgcc '' + ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a ''; meta = llvm_meta // { diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix index 3a1ba402ef671..26c0e23942068 100644 --- a/pkgs/development/compilers/llvm/15/default.nix +++ b/pkgs/development/compilers/llvm/15/default.nix @@ -3,6 +3,7 @@ , libxml2, python3, isl, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith , buildLlvmTools # tools, but from the previous stage, for cross , targetLlvmLibraries # libraries, but from the next stage, for cross +, targetLlvm # This is the default binutils, but with *this* version of LLD rather # than the default LLVM verion's, if LLD is the choice. We use these for # the `useLLVM` bootstrapping below. @@ -166,7 +167,7 @@ let ] ++ lib.optional (!stdenv.targetPlatform.isWasm) "--unwindlib=libunwind" ++ lib.optional - (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) + (!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD && stdenv.targetPlatform.useLLVM or false) "-lunwind" ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; }; @@ -273,7 +274,7 @@ let }; openmp = callPackage ./openmp { - inherit llvm_meta; + inherit llvm_meta targetLlvm; }; }); diff --git a/pkgs/development/compilers/llvm/15/libcxxabi/default.nix b/pkgs/development/compilers/llvm/15/libcxxabi/default.nix index 2d4fe974c016b..6e4f2edee2b8d 100644 --- a/pkgs/development/compilers/llvm/15/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/15/libcxxabi/default.nix @@ -53,7 +53,7 @@ stdenv.mkDerivation rec { ''; nativeBuildInputs = [ cmake python3 ]; - buildInputs = lib.optional (!stdenv.isDarwin && !stdenv.isFreeBSD && !stdenv.hostPlatform.isWasm) libunwind; + buildInputs = lib.optional (!stdenv.isDarwin && !stdenv.hostPlatform.isWasm) libunwind; cmakeFlags = [ "-DLLVM_ENABLE_RUNTIMES=libcxxabi" diff --git a/pkgs/development/compilers/llvm/15/lld/default.nix b/pkgs/development/compilers/llvm/15/lld/default.nix index 9d17766436845..fea7bf227bf8a 100644 --- a/pkgs/development/compilers/llvm/15/lld/default.nix +++ b/pkgs/development/compilers/llvm/15/lld/default.nix @@ -35,6 +35,7 @@ stdenv.mkDerivation rec { ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" ]; + LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152"; outputs = [ "out" "lib" "dev" ]; diff --git a/pkgs/development/compilers/llvm/15/llvm/default.nix b/pkgs/development/compilers/llvm/15/llvm/default.nix index 656c226574a41..5730006a8985f 100644 --- a/pkgs/development/compilers/llvm/15/llvm/default.nix +++ b/pkgs/development/compilers/llvm/15/llvm/default.nix @@ -18,10 +18,10 @@ , debugVersion ? false , enableManpages ? false , enableSharedLibraries ? !stdenv.hostPlatform.isStatic -, enablePFM ? !(stdenv.isDarwin - || stdenv.isAarch64 # broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 - || stdenv.isAarch32 # broken for the armv7l builder -) +, enablePFM ? stdenv.isLinux /* PFM only supports Linux */ + # broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 + # broken for the armv7l builder + && !stdenv.hostPlatform.isAarch , enablePolly ? false } @args: @@ -141,6 +141,7 @@ in stdenv.mkDerivation (rec { # Disables building of shared libs, -fPIC is still injected by cc-wrapper "-DLLVM_ENABLE_PIC=OFF" "-DLLVM_BUILD_STATIC=ON" + "-DLLVM_LINK_LLVM_DYLIB=off" # libxml2 needs to be disabled because the LLVM build system ignores its .la # file and doesn't link zlib as well. # https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812 diff --git a/pkgs/development/compilers/llvm/15/openmp/default.nix b/pkgs/development/compilers/llvm/15/openmp/default.nix index 9355fe667f0cc..7c2ab76c52583 100644 --- a/pkgs/development/compilers/llvm/15/openmp/default.nix +++ b/pkgs/development/compilers/llvm/15/openmp/default.nix @@ -5,6 +5,7 @@ , runCommand , cmake , llvm +, targetLlvm , lit , clang-unwrapped , perl @@ -33,7 +34,9 @@ stdenv.mkDerivation rec { outputs = [ "out" "dev" ]; nativeBuildInputs = [ cmake perl pkg-config lit ]; - buildInputs = [ llvm ]; + buildInputs = [ + (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) + ]; # Unsup:Pass:XFail:Fail # 26:267:16:8 diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 7181f4bde9d23..1342196b414c8 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -14752,8 +14752,7 @@ with pkgs; inherit (stdenvAdapters) overrideCC; buildLlvmTools = buildPackages.llvmPackages_15.tools; targetLlvmLibraries = targetPackages.llvmPackages_15.libraries or llvmPackages_15.libraries; - } // lib.optionalAttrs (stdenv.hostPlatform.isi686 && stdenv.hostPlatform == stdenv.buildPlatform && buildPackages.stdenv.cc.isGNU) { - stdenv = gcc7Stdenv; + targetLlvm = targetPackages.llvmPackages_15.llvm or llvmPackages_15.llvm; })); llvmPackages_latest = llvmPackages_14; From 2bc885cd11d37999a86036c660b2021a527d0ee3 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Fri, 27 Jan 2023 12:38:44 -0800 Subject: [PATCH 03/30] llvmPackages_15: apply some patches from `llvmPackages_14`, part 2 See https://github.com/NixOS/nixpkgs/pull/194634#issue-1398202534 for details. PRs: - #211401 - #211161 - #206742 - #211687 (cherry picked from commit 9bd92679c2e51784d4f0ada37a35594a6c63244a) --- .../compilers/llvm/15/bintools/default.nix | 21 ++++++++++++++----- .../development/compilers/llvm/15/default.nix | 2 +- .../compilers/llvm/15/llvm/default.nix | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/bintools/default.nix b/pkgs/development/compilers/llvm/15/bintools/default.nix index 53f7941e33699..303faf7bbb61b 100644 --- a/pkgs/development/compilers/llvm/15/bintools/default.nix +++ b/pkgs/development/compilers/llvm/15/bintools/default.nix @@ -5,7 +5,12 @@ let if stdenv.hostPlatform != stdenv.targetPlatform then "${stdenv.targetPlatform.config}-" else ""; -in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } '' +in runCommand "llvm-binutils-${version}" { + preferLocalBuild = true; + passthru = { + isLLVM = true; + }; +} '' mkdir -p $out/bin for prog in ${lld}/bin/*; do ln -s $prog $out/bin/${prefix}$(basename $prog) @@ -15,15 +20,21 @@ in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } '' done ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ar - ln -s ${llvm}/bin/llvm-as $out/bin/${prefix}as + ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}dlltool + ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ranlib + ln -s ${llvm}/bin/llvm-cxxfilt $out/bin/${prefix}c++filt + ln -s ${llvm}/bin/llvm-debuginfod $out/bin/${prefix}debuginfod + ln -s ${llvm}/bin/llvm-debuginfod-find $out/bin/${prefix}debuginfod-find ln -s ${llvm}/bin/llvm-dwp $out/bin/${prefix}dwp ln -s ${llvm}/bin/llvm-nm $out/bin/${prefix}nm ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}objcopy + ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}strip ln -s ${llvm}/bin/llvm-objdump $out/bin/${prefix}objdump - ln -s ${llvm}/bin/llvm-ranlib $out/bin/${prefix}ranlib - ln -s ${llvm}/bin/llvm-readelf $out/bin/${prefix}readelf + ln -s ${llvm}/bin/llvm-rc $out/bin/${prefix}windres + ln -s ${llvm}/bin/llvm-readobj $out/bin/${prefix}readelf ln -s ${llvm}/bin/llvm-size $out/bin/${prefix}size - ln -s ${llvm}/bin/llvm-strip $out/bin/${prefix}strip + ln -s ${llvm}/bin/llvm-strings $out/bin/${prefix}strings + ln -s ${llvm}/bin/llvm-symbolizer $out/bin/${prefix}addr2line ln -s ${lld}/bin/lld $out/bin/${prefix}ld '' diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix index 26c0e23942068..8965388ae691c 100644 --- a/pkgs/development/compilers/llvm/15/default.nix +++ b/pkgs/development/compilers/llvm/15/default.nix @@ -36,7 +36,7 @@ let llvm_meta = { license = lib.licenses.ncsa; - maintainers = with lib.maintainers; [ lovek323 raskin dtzWill primeos ]; + maintainers = lib.teams.llvm.members; platforms = lib.platforms.all; }; diff --git a/pkgs/development/compilers/llvm/15/llvm/default.nix b/pkgs/development/compilers/llvm/15/llvm/default.nix index 5730006a8985f..558c9a4828c3f 100644 --- a/pkgs/development/compilers/llvm/15/llvm/default.nix +++ b/pkgs/development/compilers/llvm/15/llvm/default.nix @@ -57,7 +57,7 @@ in stdenv.mkDerivation (rec { propagatedBuildInputs = [ ncurses zlib ]; - checkInputs = [ which ]; + nativeCheckInputs = [ which ]; patches = [ ./gnu-install-dirs.patch From f460f0f67f8d215ee41a8604e019e8aa677460ef Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Wed, 5 Oct 2022 10:16:21 -0500 Subject: [PATCH 04/30] llvmPackages_15: updates for LLVM 15 None of the patches required any touch-up; the only change of note is: - due to changes in the libc++/libc++abi build (https://reviews.llvm.org/D120719 and https://reviews.llvm.org/D131037) we have to add an extra build option to the libc++ header only build that sidesteps bits of the libc++ build config that assume libc++-abi is present in the build: https://github.com/llvm/llvm-project/blob/4f827318e3e8ccab4ff131e06234caa827e91e4e/libcxx/src/CMakeLists.txt#L255-L256 Rather than maintaining a precise set of build options that let us dodge referencing libc++-abi variables in the libc++ header only build, we set `LIBCXX_CXX_ABI` to `none`, as suggested by @lovesegfault. More discussion about this here: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r990267037 Co-authored-by: Bernardo Meurer (cherry picked from commit bc4dbee1150281fbd46663ef5e0e80493de9320e) --- pkgs/development/compilers/llvm/15/default.nix | 6 +++--- pkgs/development/compilers/llvm/15/libcxx/default.nix | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix index 8965388ae691c..405175838b60c 100644 --- a/pkgs/development/compilers/llvm/15/default.nix +++ b/pkgs/development/compilers/llvm/15/default.nix @@ -19,7 +19,7 @@ }: let - release_version = "14.0.6"; + release_version = "15.0.7"; candidate = ""; # empty or "rcN" dash-candidate = lib.optionalString (candidate != "") "-${candidate}"; rev = ""; # When using a Git commit @@ -31,7 +31,7 @@ let owner = "llvm"; repo = "llvm-project"; rev = if rev != "" then rev else "llvmorg-${version}"; - sha256 = "sha256-vffu4HilvYwtzwgq+NlS26m65DGbp6OSSne2aje1yJE="; + sha256 = "sha256-wjuZQyXQ/jsmvy6y1aksCcEDXGBjuhpgngF3XQJ/T4s="; }; llvm_meta = { @@ -88,7 +88,7 @@ let python3 = pkgs.python3; # don't use python-boot }); - # TODO: lldb/docs/index.rst:155:toctree contains reference to nonexisting document 'design/structureddataplugins' + # Needs package for spinhx-automodapi: https://github.com/astropy/sphinx-automodapi # lldb-manpages = lowPrio (tools.lldb.override { # enableManpages = true; # python3 = pkgs.python3; # don't use python-boot diff --git a/pkgs/development/compilers/llvm/15/libcxx/default.nix b/pkgs/development/compilers/llvm/15/libcxx/default.nix index 5e1f875bf338f..72563888c2f2b 100644 --- a/pkgs/development/compilers/llvm/15/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/15/libcxx/default.nix @@ -63,7 +63,7 @@ stdenv.mkDerivation rec { cmakeFlags = [ "-DLLVM_ENABLE_RUNTIMES=libcxx" - "-DLIBCXX_CXX_ABI=${lib.optionalString (!headersOnly) "system-"}libcxxabi" + "-DLIBCXX_CXX_ABI=${if headersOnly then "none" else "system-libcxxabi"}" ] ++ lib.optional (!headersOnly) "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${libcxxabi.dev}/include/c++/v1" ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" ++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON" From a7d2d75d0b5e5c662db2c0020b06cc08d729a3af Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Tue, 29 Nov 2022 14:12:29 -0600 Subject: [PATCH 05/30] llvmPackages_15.compiler_rt: apply #196909 to LLVM 15 `llvmPackages_15` originates from `llvmPackages_git` which does not include this change (cherry picked from commit 3b6d98d2b0faee93d8a6388bd06e7de1653f49a7) --- pkgs/development/compilers/llvm/15/compiler-rt/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/default.nix b/pkgs/development/compilers/llvm/15/compiler-rt/default.nix index 7b0996845e2e5..0a08f4dcf94b5 100644 --- a/pkgs/development/compilers/llvm/15/compiler-rt/default.nix +++ b/pkgs/development/compilers/llvm/15/compiler-rt/default.nix @@ -9,7 +9,7 @@ let useLLVM = stdenv.hostPlatform.useLLVM or false; bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; haveLibc = stdenv.cc.libc != null; - inherit (stdenv.hostPlatform) isMusl; + inherit (stdenv.hostPlatform) isMusl isGnu; baseName = "compiler-rt"; @@ -38,7 +38,7 @@ stdenv.mkDerivation { "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" - ] ++ lib.optionals (haveLibc && !isMusl) [ + ] ++ lib.optionals (haveLibc && isGnu) [ "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" From 97a97f1d74ca1c087aa263497d2bb5a5a5568a46 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Fri, 27 Jan 2023 12:23:54 -0800 Subject: [PATCH 06/30] llvmPackages_15: apply #211230 to llvmPackages_15 See the comments here for context: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r1089389188 Co-authored-by: Weijia Wang <9713184+wegank@users.noreply.github.com> (cherry picked from commit 4fabcf49458fc01f89ce494d0e5c18ec9ce167fb) --- .../development/compilers/llvm/15/default.nix | 6 +++--- .../compilers/llvm/15/libcxx/default.nix | 20 ++++++++++++++----- .../compilers/llvm/15/libcxxabi/default.nix | 4 ++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix index 405175838b60c..964ec5acd58db 100644 --- a/pkgs/development/compilers/llvm/15/default.nix +++ b/pkgs/development/compilers/llvm/15/default.nix @@ -114,7 +114,7 @@ let cc = tools.clang-unwrapped; libcxx = targetLlvmLibraries.libcxx; extraPackages = [ - targetLlvmLibraries.libcxxabi + libcxx.cxxabi targetLlvmLibraries.compiler-rt ]; extraBuildCommands = mkExtraBuildCommands cc; @@ -154,7 +154,7 @@ let libcxx = targetLlvmLibraries.libcxx; bintools = bintools'; extraPackages = [ - targetLlvmLibraries.libcxxabi + libcxx.cxxabi targetLlvmLibraries.compiler-rt ] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [ targetLlvmLibraries.libunwind @@ -167,7 +167,7 @@ let ] ++ lib.optional (!stdenv.targetPlatform.isWasm) "--unwindlib=libunwind" ++ lib.optional - (!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD && stdenv.targetPlatform.useLLVM or false) + (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) "-lunwind" ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; }; diff --git a/pkgs/development/compilers/llvm/15/libcxx/default.nix b/pkgs/development/compilers/llvm/15/libcxx/default.nix index 72563888c2f2b..1e3222da6b601 100644 --- a/pkgs/development/compilers/llvm/15/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/15/libcxx/default.nix @@ -1,7 +1,8 @@ { lib, stdenv, llvm_meta , monorepoSrc, runCommand , cmake, python3, fixDarwinDylibNames, version -, libcxxabi +, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi +, libcxxabi, libcxxrt , enableShared ? !stdenv.hostPlatform.isStatic # If headersOnly is true, the resulting package would only include the headers. @@ -16,6 +17,8 @@ let basename = "libcxx"; in +assert stdenv.isDarwin -> cxxabi.libName == "c++abi"; + stdenv.mkDerivation rec { pname = basename + lib.optionalString headersOnly "-headers"; inherit version; @@ -59,12 +62,18 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ cmake python3 ] ++ lib.optional stdenv.isDarwin fixDarwinDylibNames; - buildInputs = lib.optionals (!headersOnly) [ libcxxabi ]; + buildInputs = lib.optionals (!headersOnly) [ cxxabi ]; - cmakeFlags = [ + cmakeFlags = let + # See: https://libcxx.llvm.org/BuildingLibcxx.html#cmdoption-arg-libcxx-cxx-abi-string + libcxx_cxx_abi_opt = { + "c++abi" = "system-libcxxabi"; + "cxxrt" = "libcxxrt"; + }.${cxxabi.libName} or (throw "unknown cxxabi: ${cxxabi.libName} (${cxxabi.pname})"); + in [ "-DLLVM_ENABLE_RUNTIMES=libcxx" - "-DLIBCXX_CXX_ABI=${if headersOnly then "none" else "system-libcxxabi"}" - ] ++ lib.optional (!headersOnly) "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${libcxxabi.dev}/include/c++/v1" + "-DLIBCXX_CXX_ABI=${if headersOnly then "none" else libcxx_cxx_abi_opt}" + ] ++ lib.optional (!headersOnly && cxxabi.libName == "c++abi") "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${cxxabi.dev}/include/c++/v1" ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" ++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON" ++ lib.optionals stdenv.hostPlatform.isWasm [ @@ -78,6 +87,7 @@ stdenv.mkDerivation rec { passthru = { isLLVM = true; + inherit cxxabi; }; meta = llvm_meta // { diff --git a/pkgs/development/compilers/llvm/15/libcxxabi/default.nix b/pkgs/development/compilers/llvm/15/libcxxabi/default.nix index 6e4f2edee2b8d..22fbcc67c9355 100644 --- a/pkgs/development/compilers/llvm/15/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/15/libcxxabi/default.nix @@ -83,6 +83,10 @@ stdenv.mkDerivation rec { install -m 644 ../../${pname}/include/${if stdenv.isDarwin then "*" else "cxxabi.h"} "$dev/include" ''; + passthru = { + libName = "c++abi"; + }; + meta = llvm_meta // { homepage = "https://libcxxabi.llvm.org/"; description = "Provides C++ standard library support"; From b526c2912893955127f47328de662dbb9d9fe6eb Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Fri, 7 Oct 2022 15:22:55 -0500 Subject: [PATCH 07/30] llvmPackages_15.libcxx: use clang 15 instead of the stdenv's compiler libc++ has switched to using `__attribute__((using_if_exists))` to handle incomplete libc implementations; see: https://github.com/llvm/llvm-project/commit/a9c9183ca42629fa83cdda297d1d30c7bc1d7c91 These essentially require a modern C++ compiler (clang gained support in LLVM 13: https://github.com/llvm/llvm-project/commit/369c64839946d89cf5697550b6feeea031b2f270, gcc appears to not have support yet: https://gcc.gnu.org/bugzilla//show_bug.cgi?id=105584). Previously this was not an issue for us (despite the transition happening around LLVM 13) but something about the changes to the libc++/libc++-abi build has made it so that on platforms with incomplete libc impls (i.e. Darwin is missing `quick_exit`/`at_quick_exit`) we error during the `libcxx-abi` build when the stdenv's (older, not supporting `using_if_exists`) compiler tries to import libc symbols that aren't present. The libc++ docs suggest we use a modern compiler to build libc++ anyways (https://releases.llvm.org/15.0.0/projects/libcxx/docs/index.html#platform-and-compiler-support) so this commit uses stdenv's containing the package set's clang to build libcxx/libcxx-abi. This is similar to how libc++ bootstrapping builds (https://releases.llvm.org/15.0.0/projects/libcxx/docs/BuildingLibcxx.html#bootstrapping-build) work. (cherry picked from commit ca59a201ca1dfe77bdd5b6ce98b7ac75142549d2) --- .../development/compilers/llvm/15/default.nix | 34 +++++++++++++------ .../compilers/llvm/15/libcxxabi/default.nix | 7 ++++ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix index 964ec5acd58db..d9b117ee2343b 100644 --- a/pkgs/development/compilers/llvm/15/default.nix +++ b/pkgs/development/compilers/llvm/15/default.nix @@ -247,27 +247,39 @@ let libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; - libcxx = callPackage ./libcxx { - inherit llvm_meta; - stdenv = if stdenv.hostPlatform.useLLVM or false - then overrideCC stdenv buildLlvmTools.clangNoLibcxx - else stdenv; - }; - libcxxabi = let - stdenv_ = if stdenv.hostPlatform.useLLVM or false - then overrideCC stdenv buildLlvmTools.clangNoLibcxx - else stdenv; + # CMake will "require" a compiler capable of compiling C++ programs + # cxx-header's build does not actually use one so it doesn't really matter + # what stdenv we use here, as long as CMake is happy. cxx-headers = callPackage ./libcxx { inherit llvm_meta; - stdenv = stdenv_; headersOnly = true; }; + + # `libcxxabi` *doesn't* need a compiler with a working C++ stdlib but it + # *does* need a relatively modern C++ compiler (see: + # https://releases.llvm.org/15.0.0/projects/libcxx/docs/index.html#platform-and-compiler-support). + # + # So, we use the clang from this LLVM package set, like libc++ + # "boostrapping builds" do: + # https://releases.llvm.org/15.0.0/projects/libcxx/docs/BuildingLibcxx.html#bootstrapping-build + # + # We cannot use `clangNoLibcxx` because that contains `compiler-rt` which, + # on macOS, depends on `libcxxabi`, thus forming a cycle. + stdenv_ = overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc; in callPackage ./libcxxabi { stdenv = stdenv_; inherit llvm_meta cxx-headers; }; + # Like `libcxxabi` above, `libcxx` requires a fairly modern C++ compiler, + # so: we use the clang from this LLVM package set instead of the regular + # stdenv's compiler. + libcxx = callPackage ./libcxx { + inherit llvm_meta; + stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; + }; + libunwind = callPackage ./libunwind { inherit llvm_meta; stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; diff --git a/pkgs/development/compilers/llvm/15/libcxxabi/default.nix b/pkgs/development/compilers/llvm/15/libcxxabi/default.nix index 22fbcc67c9355..ea9f7cb0772ee 100644 --- a/pkgs/development/compilers/llvm/15/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/15/libcxxabi/default.nix @@ -58,6 +58,13 @@ stdenv.mkDerivation rec { cmakeFlags = [ "-DLLVM_ENABLE_RUNTIMES=libcxxabi" "-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1" + + # `libcxxabi`'s build does not need a toolchain with a c++ stdlib attached + # (we specify the headers it should use explicitly above). + # + # CMake however checks for this anyways; this flag tells it not to. See: + # https://github.com/llvm/llvm-project/blob/4bd3f3759259548e159aeba5c76efb9a0864e6fa/llvm/runtimes/CMakeLists.txt#L243 + "-DCMAKE_CXX_COMPILER_WORKS=ON" ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ "-DLLVM_ENABLE_LIBCXX=ON" "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" From ace04abef24d6dd71884c991cd9cbbec6d719381 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 15 Jan 2023 12:58:24 -0800 Subject: [PATCH 08/30] llvmPackages_15.libcxxabi: fix cycles that arise when `stdenv` is the LLVM stdenv (cherry picked from commit 501a9e1b4cabd86eae6f9476a91ef98e8de75565) --- pkgs/development/compilers/llvm/15/default.nix | 15 ++++++++++++++- .../compilers/llvm/15/libcxx/default.nix | 8 +++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix index d9b117ee2343b..8825f860c6161 100644 --- a/pkgs/development/compilers/llvm/15/default.nix +++ b/pkgs/development/compilers/llvm/15/default.nix @@ -1,4 +1,4 @@ -{ lowPrio, newScope, pkgs, lib, stdenv, cmake +{ lowPrio, newScope, pkgs, lib, stdenv, stdenvNoCC, cmake , gccForLibs, preLibcCrossHeaders , libxml2, python3, isl, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith , buildLlvmTools # tools, but from the previous stage, for cross @@ -253,6 +253,19 @@ let # what stdenv we use here, as long as CMake is happy. cxx-headers = callPackage ./libcxx { inherit llvm_meta; + # Note that if we use the regular stdenv here we'll get cycle errors + # when attempting to use this compiler in the stdenv. + # + # The final stdenv pulls `cxx-headers` from the package set where + # hostPlatform *is* the target platform which means that `stdenv` at + # that point attempts to use this toolchain. + # + # So, we use `stdenv_` (the stdenv containing `clang` from this package + # set, defined below) to sidestep this issue. + # + # Because we only use `cxx-headers` in `libcxxabi` (which depends on the + # clang stdenv _anyways_), this is okay. + stdenv = stdenv_; headersOnly = true; }; diff --git a/pkgs/development/compilers/llvm/15/libcxx/default.nix b/pkgs/development/compilers/llvm/15/libcxx/default.nix index 1e3222da6b601..b4d973f0b073f 100644 --- a/pkgs/development/compilers/llvm/15/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/15/libcxx/default.nix @@ -80,7 +80,13 @@ stdenv.mkDerivation rec { "-DLIBCXX_ENABLE_THREADS=OFF" "-DLIBCXX_ENABLE_FILESYSTEM=OFF" "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"; + ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF" + # If we're only building the headers we don't actually *need* a functioning + # C/C++ compiler: + ++ lib.optionals (headersOnly) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + ]; buildFlags = lib.optional headersOnly "generate-cxx-headers"; installTargets = lib.optional headersOnly "install-cxx-headers"; From 690c2d8e13e1131d6ea792900ae3bf0cd5a7001a Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Fri, 7 Oct 2022 17:16:05 -0500 Subject: [PATCH 09/30] llvmPackages_15.compiler-rt: fixes for Darwin this introduces a codesigning related patch that we can drop once #195107 goes through see: https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272116014 (cherry picked from commit 00839fea22bfa118b3897519d3a3be0f447dbeb1) --- .../llvm/15/compiler-rt/codesign.patch | 33 ------------------- .../compilers/llvm/15/compiler-rt/default.nix | 25 +++++++++++++- .../compiler-rt/skip-explicit-codesign.patch | 12 +++++++ 3 files changed, 36 insertions(+), 34 deletions(-) delete mode 100644 pkgs/development/compilers/llvm/15/compiler-rt/codesign.patch create mode 100644 pkgs/development/compilers/llvm/15/compiler-rt/skip-explicit-codesign.patch diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/codesign.patch b/pkgs/development/compilers/llvm/15/compiler-rt/codesign.patch deleted file mode 100644 index 065959d14d46c..0000000000000 --- a/pkgs/development/compilers/llvm/15/compiler-rt/codesign.patch +++ /dev/null @@ -1,33 +0,0 @@ -From 3dec5f3475a26aeb4678627795c4b67c6b7b4785 Mon Sep 17 00:00:00 2001 -From: Will Dietz -Date: Tue, 19 Sep 2017 13:13:06 -0500 -Subject: [PATCH] remove codesign use on Apple, disable ios sim testing that - needs it - ---- - cmake/Modules/AddCompilerRT.cmake | 8 ------ - test/asan/CMakeLists.txt | 52 --------------------------------------- - test/tsan/CMakeLists.txt | 47 ----------------------------------- - 3 files changed, 107 deletions(-) - -diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake -index bc69ec95c419..9f100fdcec2f 100644 ---- a/cmake/Modules/AddCompilerRT.cmake -+++ b/cmake/Modules/AddCompilerRT.cmake -@@ -366,14 +366,6 @@ function(add_compiler_rt_runtime name type) - set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "") - set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib") - endif() -- if(APPLE) -- # Ad-hoc sign the dylibs -- add_custom_command(TARGET ${libname} -- POST_BUILD -- COMMAND codesign --sign - $ -- WORKING_DIRECTORY ${COMPILER_RT_OUTPUT_LIBRARY_DIR} -- ) -- endif() - endif() - - set(parent_target_arg) -2.14.1 - diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/default.nix b/pkgs/development/compilers/llvm/15/compiler-rt/default.nix index 0a08f4dcf94b5..3bbb8a23c7708 100644 --- a/pkgs/development/compilers/llvm/15/compiler-rt/default.nix +++ b/pkgs/development/compilers/llvm/15/compiler-rt/default.nix @@ -66,6 +66,10 @@ stdenv.mkDerivation { "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" + + # `COMPILER_RT_DEFAULT_TARGET_ONLY` does not apply to Darwin: + # https://github.com/llvm/llvm-project/blob/27ef42bec80b6c010b7b3729ed0528619521a690/compiler-rt/cmake/base-config-ix.cmake#L153 + "-DCOMPILER_RT_ENABLE_IOS=OFF" ]; outputs = [ "out" "dev" ]; @@ -78,7 +82,26 @@ stdenv.mkDerivation { ./normalize-var.patch ] # Prevent a compilation error on darwin ++ lib.optional stdenv.hostPlatform.isDarwin ./darwin-targetconditionals.patch - ++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch; + ++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch + + # The `compiler-rt` build inspects `ld` to figure out whether it needs to + # explicitly call `codesign`: + # https://github.com/llvm/llvm-project/blob/27ef42bec80b6c010b7b3729ed0528619521a690/compiler-rt/cmake/Modules/AddCompilerRT.cmake#L409-L422 + # + # In our case, despite (currently) having an `ld` version than 609, we don't + # need an explicit codesigning step because `postLinkSignHook` handles this + # for us. + # + # Unfortunately there isn't an easy way to override + # `NEED_EXPLICIT_ADHOC_CODESIGN`. + # + # Adding `codesign` as a build input also doesn't currently work because, as + # of this writing, `codesign` in nixpkgs doesn't support the `--sign` alias + # which the `compiler-rt` build uses. See here for context: + # https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272116014 + # + # So, for now, we patch `compiler-rt` to skip the explicit codesigning step. + ++ lib.optional stdenv.hostPlatform.isDarwin ./skip-explicit-codesign.patch; # 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 diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/skip-explicit-codesign.patch b/pkgs/development/compilers/llvm/15/compiler-rt/skip-explicit-codesign.patch new file mode 100644 index 0000000000000..894a74e74d464 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/compiler-rt/skip-explicit-codesign.patch @@ -0,0 +1,12 @@ +diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake +--- a/cmake/Modules/AddCompilerRT.cmake ++++ b/cmake/Modules/AddCompilerRT.cmake +@@ -406,7 +406,7 @@ function(add_compiler_rt_runtime name type) + if (HAD_ERROR) + message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}") + endif() +- set(NEED_EXPLICIT_ADHOC_CODESIGN 1) ++ set(NEED_EXPLICIT_ADHOC_CODESIGN 0) # `postLinkSignHook` handles this for us + if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*") + string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT}) + if (HOST_LINK_VERSION VERSION_GREATER_EQUAL 609) From 068139d733c946ace7ec578f6477421e30e635c3 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 15 Jan 2023 16:14:51 -0800 Subject: [PATCH 10/30] llvmPackages_15.compiler-rt: apply #186575 to `llvmPackages_15` (cherry picked from commit 09b8886d5e7e2511a8e68cfe04f11cabb07da539) --- .../compilers/llvm/15/compiler-rt/default.nix | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/default.nix b/pkgs/development/compilers/llvm/15/compiler-rt/default.nix index 3bbb8a23c7708..16520243ebe85 100644 --- a/pkgs/development/compilers/llvm/15/compiler-rt/default.nix +++ b/pkgs/development/compilers/llvm/15/compiler-rt/default.nix @@ -1,6 +1,6 @@ { lib, stdenv, llvm_meta, version , monorepoSrc, runCommand -, cmake, python3, libllvm, libcxxabi, libxcrypt +, cmake, python3, xcbuild, libllvm, libcxxabi, libxcrypt , doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD }: @@ -27,7 +27,8 @@ stdenv.mkDerivation { inherit src; sourceRoot = "${src.name}/${baseName}"; - nativeBuildInputs = [ cmake python3 libllvm.dev ]; + nativeBuildInputs = [ cmake python3 libllvm.dev ] + ++ lib.optional stdenv.isDarwin xcbuild.xcrun; buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; NIX_CFLAGS_COMPILE = [ @@ -80,10 +81,13 @@ stdenv.mkDerivation { # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the # extra `/`. ./normalize-var.patch - ] # Prevent a compilation error on darwin - ++ lib.optional stdenv.hostPlatform.isDarwin ./darwin-targetconditionals.patch - ++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch - + # Prevent a compilation error on darwin + ./darwin-targetconditionals.patch + # See: https://github.com/NixOS/nixpkgs/pull/186575 + ../../common/compiler-rt/darwin-plistbuddy-workaround.patch + # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 + ./armv7l.patch + ] # The `compiler-rt` build inspects `ld` to figure out whether it needs to # explicitly call `codesign`: # https://github.com/llvm/llvm-project/blob/27ef42bec80b6c010b7b3729ed0528619521a690/compiler-rt/cmake/Modules/AddCompilerRT.cmake#L409-L422 From f11d5e6545747009f3f9aed92a452acafb63bb91 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 15 Jan 2023 16:12:15 -0800 Subject: [PATCH 11/30] llvmPackages_15.compiler-rt: update the armv7l patch see the discussion here for context: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 (cherry picked from commit f91fad438b3b150f20e6a222a254760d6fac302e) --- .../llvm/15/compiler-rt/armv7l.patch | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/armv7l.patch b/pkgs/development/compilers/llvm/15/compiler-rt/armv7l.patch index 120cfe6feb2a6..ca1c2332abd9f 100644 --- a/pkgs/development/compilers/llvm/15/compiler-rt/armv7l.patch +++ b/pkgs/development/compilers/llvm/15/compiler-rt/armv7l.patch @@ -1,19 +1,19 @@ -diff -ur compiler-rt-10.0.0.src/cmake/builtin-config-ix.cmake compiler-rt-10.0.0.src-patched/cmake/builtin-config-ix.cmake ---- compiler-rt-10.0.0.src/cmake/builtin-config-ix.cmake 2020-03-24 00:01:02.000000000 +0900 -+++ compiler-rt-10.0.0.src-patched/cmake/builtin-config-ix.cmake 2020-05-10 03:42:00.883450706 +0900 -@@ -24,7 +24,7 @@ - +diff -ur a/cmake/builtin-config-ix.cmake b/cmake/builtin-config-ix.cmake +--- a/cmake/builtin-config-ix.cmake @llvm 15.0.6 ++++ b/cmake/builtin-config-ix.cmake +@@ -46,7 +46,7 @@ set(ARM64 aarch64) --set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k) -+set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv7l) +-set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv8m.main armv8.1m.main) ++set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv7l armv8m.main armv8.1m.main) + set(AVR avr) set(HEXAGON hexagon) set(X86 i386) set(X86_64 x86_64) -diff -ur compiler-rt-10.0.0.src/lib/builtins/CMakeLists.txt compiler-rt-10.0.0.src-patched/lib/builtins/CMakeLists.txt ---- compiler-rt-10.0.0.src/lib/builtins/CMakeLists.txt 2020-03-24 00:01:02.000000000 +0900 -+++ compiler-rt-10.0.0.src-patched/lib/builtins/CMakeLists.txt 2020-05-10 03:44:49.468579650 +0900 -@@ -474,6 +474,7 @@ +diff -ur a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt +--- a/lib/builtins/CMakeLists.txt @llvm 15.0.6 ++++ b/lib/builtins/CMakeLists.txt +@@ -565,6 +565,7 @@ set(armv7_SOURCES ${arm_SOURCES}) set(armv7s_SOURCES ${arm_SOURCES}) set(armv7k_SOURCES ${arm_SOURCES}) @@ -21,12 +21,12 @@ diff -ur compiler-rt-10.0.0.src/lib/builtins/CMakeLists.txt compiler-rt-10.0.0.s set(arm64_SOURCES ${aarch64_SOURCES}) # macho_embedded archs -@@ -595,7 +596,7 @@ +@@ -734,7 +735,7 @@ foreach (arch ${BUILTIN_SUPPORTED_ARCH}) if (CAN_TARGET_${arch}) # For ARM archs, exclude any VFP builtins if VFP is not supported -- if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") -+ if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7l|armv7m|armv7em)$") +- if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em|armv8m.main|armv8.1m.main)$") ++ if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7l|armv7m|armv7em|armv8m.main|armv8.1m.main)$") string(REPLACE ";" " " _TARGET_${arch}_CFLAGS "${TARGET_${arch}_CFLAGS}") check_compile_definition(__VFP_FP__ "${CMAKE_C_FLAGS} ${_TARGET_${arch}_CFLAGS}" COMPILER_RT_HAS_${arch}_VFP) if(NOT COMPILER_RT_HAS_${arch}_VFP) From 572014aca117684f2003b0aa0202646196414841 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 15 Jan 2023 16:18:43 -0800 Subject: [PATCH 12/30] llvmPackages_15.compiler-rt: gate the `libxcrypt` dep on `plat.libc == "glibc"` This restores this check to what it originally was in #196909 (see: https://github.com/NixOS/nixpkgs/pull/196909#discussion_r1000536298) and lets `compiler-rt` eval successfully when trying to compile the `llvmPackages_15` set for mingw targets (i.e. a platform that *is* GNU but does *not* use glibc). --- It's not clear to me what the `haveLibc` check is doing here (platforms that seem to use glibc like `x86_64-linux` and have `plat.libc == "glibc"` have `haveLibc = false` because `stdenv.cc.libc` is `null`). (cherry picked from commit d7299071d4c5d765c7c5a6ea25a5fc98eb32c323) --- pkgs/development/compilers/llvm/15/compiler-rt/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/default.nix b/pkgs/development/compilers/llvm/15/compiler-rt/default.nix index 16520243ebe85..fbfff9ad10fd7 100644 --- a/pkgs/development/compilers/llvm/15/compiler-rt/default.nix +++ b/pkgs/development/compilers/llvm/15/compiler-rt/default.nix @@ -39,7 +39,7 @@ stdenv.mkDerivation { "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" - ] ++ lib.optionals (haveLibc && isGnu) [ + ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [ "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" From ab956d03afbbbd630849b6bfae285a692c0eeeb3 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Fri, 7 Oct 2022 20:01:05 -0500 Subject: [PATCH 13/30] llvmPackages_15.lldb: fix `lldb` on x86_64 macOS See: https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272129132 (cherry picked from commit 1d3ca42323ce573a12dccf2590e3b18454a58289) --- .../lldb/cpu_subtype_arm64e_replacement.patch | 12 +++++++ .../compilers/llvm/15/lldb/default.nix | 36 +++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 pkgs/development/compilers/llvm/15/lldb/cpu_subtype_arm64e_replacement.patch diff --git a/pkgs/development/compilers/llvm/15/lldb/cpu_subtype_arm64e_replacement.patch b/pkgs/development/compilers/llvm/15/lldb/cpu_subtype_arm64e_replacement.patch new file mode 100644 index 0000000000000..20d35c9f3ea91 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/lldb/cpu_subtype_arm64e_replacement.patch @@ -0,0 +1,12 @@ +diff --git a/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/source/Host/macosx/objcxx/HostInfoMacOSX.mm +--- a/source/Host/macosx/objcxx/HostInfoMacOSX.mm ++++ b/source/Host/macosx/objcxx/HostInfoMacOSX.mm +@@ -233,7 +233,7 @@ void HostInfoMacOSX::ComputeHostArchitectureSupport(ArchSpec &arch_32, + len = sizeof(is_64_bit_capable); + ::sysctlbyname("hw.cpu64bit_capable", &is_64_bit_capable, &len, NULL, 0); + +- if (cputype == CPU_TYPE_ARM64 && cpusubtype == CPU_SUBTYPE_ARM64E) { ++ if (cputype == CPU_TYPE_ARM64 && cpusubtype == ((cpu_subtype_t) 2)) { // CPU_SUBTYPE_ARM64E is not available in the macOS 10.12 headers + // The arm64e architecture is a preview. Pretend the host architecture + // is arm64. + cpusubtype = CPU_SUBTYPE_ARM64_ALL; diff --git a/pkgs/development/compilers/llvm/15/lldb/default.nix b/pkgs/development/compilers/llvm/15/lldb/default.nix index 6e6fe5cf0671d..1ceca3813fa4e 100644 --- a/pkgs/development/compilers/llvm/15/lldb/default.nix +++ b/pkgs/development/compilers/llvm/15/lldb/default.nix @@ -20,6 +20,7 @@ , Cocoa , lit , makeWrapper +, darwin , enableManpages ? false , lua5_3 }: @@ -44,7 +45,21 @@ stdenv.mkDerivation (rec { substitute '${./resource-dir.patch}' "$out" --subst-var clangLibDir '') ./gnu-install-dirs.patch - ]; + ] + # This is a stopgap solution if/until the macOS SDK used for x86_64 is + # updated. + # + # The older 10.12 SDK used on x86_64 as of this writing has a `mach/machine.h` + # header that does not define `CPU_SUBTYPE_ARM64E` so we replace the one use + # of this preprocessor symbol in `lldb` with its expansion. + # + # See here for some context: + # https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272129132 + ++ lib.optional ( + stdenv.targetPlatform.isDarwin + && !stdenv.targetPlatform.isAarch64 + && (lib.versionOlder darwin.apple_sdk.sdk.version "11.0") + ) ./cpu_subtype_arm64e_replacement.patch; outputs = [ "out" "lib" "dev" ]; @@ -67,7 +82,24 @@ stdenv.mkDerivation (rec { bootstrap_cmds Carbon Cocoa - ]; + ] + # The older libSystem used on x86_64 macOS is missing the + # `` header which `lldb` uses. + # + # We copy this header over from macOS 10.12 SDK. + # + # See here for context: + # https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272129132 + ++ lib.optional ( + stdenv.targetPlatform.isDarwin + && !stdenv.targetPlatform.isAarch64 + ) ( + runCommand "bsm-audit-session-header" { } '' + install -Dm444 \ + "${lib.getDev darwin.apple_sdk.sdk}/include/bsm/audit_session.h" \ + "$out/include/bsm/audit_session.h" + '' + ); hardeningDisable = [ "format" ]; From 3207be5e423c9918e157ef7632f2840d1042247c Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 15 Jan 2023 15:17:55 -0800 Subject: [PATCH 14/30] llvmPackages_15.lldb: fix the build on `i686` as detailed within, adding `asm/ptrace.h` leads to `asm/ptrace-abi.h` being included which defines preprocessor symbols that clash with identifiers used in the LLVM headers (`FS` and `CS` only defined on i686) (cherry picked from commit b4ee532f360090c3ed3277e7224763bd6429b412) --- pkgs/development/compilers/llvm/15/lldb/procfs.patch | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/lldb/procfs.patch b/pkgs/development/compilers/llvm/15/lldb/procfs.patch index a798216aa62c4..7b200e86505ca 100644 --- a/pkgs/development/compilers/llvm/15/lldb/procfs.patch +++ b/pkgs/development/compilers/llvm/15/lldb/procfs.patch @@ -1,14 +1,20 @@ --- a/source/Plugins/Process/Linux/Procfs.h +++ b/source/Plugins/Process/Linux/Procfs.h -@@ -10,6 +10,7 @@ +@@ -10,6 +10,13 @@ // sys/procfs.h on Android/Linux for all supported architectures. #include +#include ++ ++// on i686 preprocessor symbols with these register names are defined as ++// numeric constants; these symbols clash with identifier names used in ++// `llvm/Support/VirtualFileSystem.h` and `llvm/ADT/SmallVector.h` ++#undef FS ++#undef CS #include "lldb/lldb-types.h" -@@ -17,23 +18,13 @@ +@@ -17,23 +24,13 @@ #include From 1860e402038920aaa43eb5627ac95fdb2736277e Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Fri, 7 Oct 2022 22:45:21 -0500 Subject: [PATCH 15/30] llvmPackages_15.lldb: fix the manpages (cherry picked from commit 19d1571ee46eca979011db5010b9d4fcc2731cd8) --- pkgs/development/compilers/llvm/15/default.nix | 9 ++++----- pkgs/development/compilers/llvm/15/lldb/default.nix | 7 +++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix index 8825f860c6161..b729616843d27 100644 --- a/pkgs/development/compilers/llvm/15/default.nix +++ b/pkgs/development/compilers/llvm/15/default.nix @@ -88,11 +88,10 @@ let python3 = pkgs.python3; # don't use python-boot }); - # Needs package for spinhx-automodapi: https://github.com/astropy/sphinx-automodapi - # lldb-manpages = lowPrio (tools.lldb.override { - # enableManpages = true; - # python3 = pkgs.python3; # don't use python-boot - # }); + lldb-manpages = lowPrio (tools.lldb.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); # pick clang appropriate for package set we are targeting clang = diff --git a/pkgs/development/compilers/llvm/15/lldb/default.nix b/pkgs/development/compilers/llvm/15/lldb/default.nix index 1ceca3813fa4e..2b1b377abe5a9 100644 --- a/pkgs/development/compilers/llvm/15/lldb/default.nix +++ b/pkgs/development/compilers/llvm/15/lldb/default.nix @@ -116,6 +116,13 @@ stdenv.mkDerivation (rec { "-DLLVM_ENABLE_SPHINX=ON" "-DSPHINX_OUTPUT_MAN=ON" "-DSPHINX_OUTPUT_HTML=OFF" + + # docs reference `automodapi` but it's not added to the extensions list when + # only building the manpages: + # https://github.com/llvm/llvm-project/blob/af6ec9200b09039573d85e349496c4f5b17c3d7f/lldb/docs/conf.py#L54 + # + # so, we just ignore the resulting errors + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" ] ++ lib.optionals doCheck [ "-DLLDB_TEST_C_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" "-DLLDB_TEST_CXX_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++" From 5aea6702a60dff912614b2159f82bb2af51075d1 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Wed, 5 Oct 2022 10:21:58 -0500 Subject: [PATCH 16/30] llvmPackages_15: switch to using `ninja` (cherry picked from commit 912056c71ec2dc4f09ef6f2ab82f943f8aa69c2b) --- pkgs/development/compilers/llvm/15/clang/default.nix | 8 +++----- .../compilers/llvm/15/compiler-rt/default.nix | 4 ++-- pkgs/development/compilers/llvm/15/default.nix | 6 +++--- .../development/compilers/llvm/15/libcxx/default.nix | 6 +++--- .../compilers/llvm/15/libcxxabi/default.nix | 4 ++-- .../compilers/llvm/15/libunwind/default.nix | 3 ++- pkgs/development/compilers/llvm/15/lld/default.nix | 3 ++- pkgs/development/compilers/llvm/15/lldb/default.nix | 7 +++---- pkgs/development/compilers/llvm/15/llvm/default.nix | 12 ++++-------- .../development/compilers/llvm/15/openmp/default.nix | 3 ++- 10 files changed, 26 insertions(+), 30 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/clang/default.nix b/pkgs/development/compilers/llvm/15/clang/default.nix index d10c358ae1974..6102947b1afd8 100644 --- a/pkgs/development/compilers/llvm/15/clang/default.nix +++ b/pkgs/development/compilers/llvm/15/clang/default.nix @@ -1,6 +1,6 @@ { lib, stdenv, llvm_meta , monorepoSrc, runCommand -, substituteAll, cmake, libxml2, libllvm, version, python3 +, substituteAll, cmake, ninja, libxml2, libllvm, version, python3 , buildLlvmTools , fixDarwinDylibNames , enableManpages ? false @@ -20,7 +20,7 @@ let sourceRoot = "${src.name}/${pname}"; - nativeBuildInputs = [ cmake python3 ] + nativeBuildInputs = [ cmake ninja python3 ] ++ lib.optional enableManpages python3.pkgs.sphinx ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; @@ -114,9 +114,7 @@ let } // lib.optionalAttrs enableManpages { pname = "clang-manpages"; - buildPhase = '' - make docs-clang-man - ''; + ninjaFlags = [ "docs-clang-man" ]; installPhase = '' mkdir -p $out/share/man/man1 diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/default.nix b/pkgs/development/compilers/llvm/15/compiler-rt/default.nix index fbfff9ad10fd7..bc7195b836a1a 100644 --- a/pkgs/development/compilers/llvm/15/compiler-rt/default.nix +++ b/pkgs/development/compilers/llvm/15/compiler-rt/default.nix @@ -1,6 +1,6 @@ { lib, stdenv, llvm_meta, version , monorepoSrc, runCommand -, cmake, python3, xcbuild, libllvm, libcxxabi, libxcrypt +, cmake, ninja, python3, xcbuild, libllvm, libcxxabi, libxcrypt , doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD }: @@ -27,7 +27,7 @@ stdenv.mkDerivation { inherit src; sourceRoot = "${src.name}/${baseName}"; - nativeBuildInputs = [ cmake python3 libllvm.dev ] + nativeBuildInputs = [ cmake ninja python3 libllvm.dev ] ++ lib.optional stdenv.isDarwin xcbuild.xcrun; buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix index b729616843d27..3a48a5b0e00ae 100644 --- a/pkgs/development/compilers/llvm/15/default.nix +++ b/pkgs/development/compilers/llvm/15/default.nix @@ -1,4 +1,4 @@ -{ lowPrio, newScope, pkgs, lib, stdenv, stdenvNoCC, cmake +{ lowPrio, newScope, pkgs, lib, stdenv, stdenvNoCC, cmake, ninja , gccForLibs, preLibcCrossHeaders , libxml2, python3, isl, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith , buildLlvmTools # tools, but from the previous stage, for cross @@ -41,7 +41,7 @@ let }; tools = lib.makeExtensible (tools: let - callPackage = newScope (tools // { inherit stdenv cmake libxml2 python3 isl release_version version monorepoSrc buildLlvmTools; }); + callPackage = newScope (tools // { inherit stdenv cmake ninja libxml2 python3 isl release_version version monorepoSrc buildLlvmTools; }); mkExtraBuildCommands0 = cc: '' rsrc="$out/resource-root" mkdir "$rsrc" @@ -220,7 +220,7 @@ let }); libraries = lib.makeExtensible (libraries: let - callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python3 isl release_version version monorepoSrc; }); + callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake ninja libxml2 python3 isl release_version version monorepoSrc; }); in { compiler-rt-libc = callPackage ./compiler-rt { diff --git a/pkgs/development/compilers/llvm/15/libcxx/default.nix b/pkgs/development/compilers/llvm/15/libcxx/default.nix index b4d973f0b073f..94374c8a312df 100644 --- a/pkgs/development/compilers/llvm/15/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/15/libcxx/default.nix @@ -1,6 +1,6 @@ { lib, stdenv, llvm_meta , monorepoSrc, runCommand -, cmake, python3, fixDarwinDylibNames, version +, cmake, ninja, python3, fixDarwinDylibNames, version , cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi , libcxxabi, libcxxrt , enableShared ? !stdenv.hostPlatform.isStatic @@ -59,7 +59,7 @@ stdenv.mkDerivation rec { patchShebangs utils/cat_files.py ''; - nativeBuildInputs = [ cmake python3 ] + nativeBuildInputs = [ cmake ninja python3 ] ++ lib.optional stdenv.isDarwin fixDarwinDylibNames; buildInputs = lib.optionals (!headersOnly) [ cxxabi ]; @@ -88,7 +88,7 @@ stdenv.mkDerivation rec { "-DCMAKE_CXX_COMPILER_WORKS=ON" ]; - buildFlags = lib.optional headersOnly "generate-cxx-headers"; + ninjaFlags = lib.optional headersOnly "generate-cxx-headers"; installTargets = lib.optional headersOnly "install-cxx-headers"; passthru = { diff --git a/pkgs/development/compilers/llvm/15/libcxxabi/default.nix b/pkgs/development/compilers/llvm/15/libcxxabi/default.nix index ea9f7cb0772ee..cb5fa44f07009 100644 --- a/pkgs/development/compilers/llvm/15/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/15/libcxxabi/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, llvm_meta, cmake, python3 +{ lib, stdenv, llvm_meta, cmake, ninja, python3 , monorepoSrc, runCommand, fetchpatch , cxx-headers, libunwind, version , enableShared ? !stdenv.hostPlatform.isStatic @@ -52,7 +52,7 @@ stdenv.mkDerivation rec { cd ../runtimes ''; - nativeBuildInputs = [ cmake python3 ]; + nativeBuildInputs = [ cmake ninja python3 ]; buildInputs = lib.optional (!stdenv.isDarwin && !stdenv.hostPlatform.isWasm) libunwind; cmakeFlags = [ diff --git a/pkgs/development/compilers/llvm/15/libunwind/default.nix b/pkgs/development/compilers/llvm/15/libunwind/default.nix index 0b59fff1357e1..dd14e2acaf869 100644 --- a/pkgs/development/compilers/llvm/15/libunwind/default.nix +++ b/pkgs/development/compilers/llvm/15/libunwind/default.nix @@ -1,6 +1,7 @@ { lib, stdenv, llvm_meta, version , monorepoSrc, runCommand , cmake +, ninja , python3 , enableShared ? !stdenv.hostPlatform.isStatic }: @@ -41,7 +42,7 @@ stdenv.mkDerivation rec { outputs = [ "out" "dev" ]; - nativeBuildInputs = [ cmake python3 ]; + nativeBuildInputs = [ cmake ninja python3 ]; cmakeFlags = [ "-DLLVM_ENABLE_RUNTIMES=libunwind" diff --git a/pkgs/development/compilers/llvm/15/lld/default.nix b/pkgs/development/compilers/llvm/15/lld/default.nix index fea7bf227bf8a..e8bca769de5fa 100644 --- a/pkgs/development/compilers/llvm/15/lld/default.nix +++ b/pkgs/development/compilers/llvm/15/lld/default.nix @@ -2,6 +2,7 @@ , buildLlvmTools , monorepoSrc, runCommand , cmake +, ninja , libxml2 , libllvm , version @@ -27,7 +28,7 @@ stdenv.mkDerivation rec { ./gnu-install-dirs.patch ]; - nativeBuildInputs = [ cmake ]; + nativeBuildInputs = [ cmake ninja ]; buildInputs = [ libllvm libxml2 ]; cmakeFlags = [ diff --git a/pkgs/development/compilers/llvm/15/lldb/default.nix b/pkgs/development/compilers/llvm/15/lldb/default.nix index 2b1b377abe5a9..15bcb40c3b437 100644 --- a/pkgs/development/compilers/llvm/15/lldb/default.nix +++ b/pkgs/development/compilers/llvm/15/lldb/default.nix @@ -2,6 +2,7 @@ , runCommand , monorepoSrc , cmake +, ninja , zlib , ncurses , swig @@ -64,7 +65,7 @@ stdenv.mkDerivation (rec { outputs = [ "out" "lib" "dev" ]; nativeBuildInputs = [ - cmake python3 which swig lit makeWrapper lua5_3 + cmake ninja python3 which swig lit makeWrapper lua5_3 ] ++ lib.optionals enableManpages [ python3.pkgs.sphinx python3.pkgs.recommonmark ]; @@ -159,9 +160,7 @@ stdenv.mkDerivation (rec { } // lib.optionalAttrs enableManpages { pname = "lldb-manpages"; - buildPhase = '' - make docs-lldb-man - ''; + ninjaFlags = [ "docs-lldb-man" ]; propagatedBuildInputs = []; diff --git a/pkgs/development/compilers/llvm/15/llvm/default.nix b/pkgs/development/compilers/llvm/15/llvm/default.nix index 558c9a4828c3f..8eba6a717e7cb 100644 --- a/pkgs/development/compilers/llvm/15/llvm/default.nix +++ b/pkgs/development/compilers/llvm/15/llvm/default.nix @@ -4,6 +4,7 @@ , runCommand , fetchpatch , cmake +, ninja , python3 , libffi , libbfd @@ -49,7 +50,7 @@ in stdenv.mkDerivation (rec { outputs = [ "out" "lib" "dev" "python" ]; - nativeBuildInputs = [ cmake python3 ] + nativeBuildInputs = [ cmake ninja python3 ] ++ optionals enableManpages [ python3.pkgs.sphinx python3.pkgs.recommonmark ]; buildInputs = [ libxml2 libffi ] @@ -245,15 +246,10 @@ in stdenv.mkDerivation (rec { } // lib.optionalAttrs enableManpages { pname = "llvm-manpages"; - buildPhase = '' - make docs-llvm-man - ''; - propagatedBuildInputs = []; - installPhase = '' - make -C docs install - ''; + ninjaFlags = [ "docs-llvm-man" ]; + installTargets = [ "install-docs-llvm-man" ]; postPatch = null; postInstall = null; diff --git a/pkgs/development/compilers/llvm/15/openmp/default.nix b/pkgs/development/compilers/llvm/15/openmp/default.nix index 7c2ab76c52583..52aeb4bd9800f 100644 --- a/pkgs/development/compilers/llvm/15/openmp/default.nix +++ b/pkgs/development/compilers/llvm/15/openmp/default.nix @@ -4,6 +4,7 @@ , monorepoSrc , runCommand , cmake +, ninja , llvm , targetLlvm , lit @@ -33,7 +34,7 @@ stdenv.mkDerivation rec { outputs = [ "out" "dev" ]; - nativeBuildInputs = [ cmake perl pkg-config lit ]; + nativeBuildInputs = [ cmake ninja perl pkg-config lit ]; buildInputs = [ (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) ]; From 3fdc84cfbfc983fb0a3d0934de8c14c422a1ebb5 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Wed, 5 Oct 2022 10:22:48 -0500 Subject: [PATCH 17/30] llvmPackages_15: expand the `NIX_BUILD_CORES` arg passed to lit at configure time this previously worked because, when using Make, this variable was expanded at build time (cherry picked from commit 4d3857d6ed9c85cfe4180dcef37d6bfc1df032d5) --- pkgs/development/compilers/llvm/15/llvm/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/compilers/llvm/15/llvm/default.nix b/pkgs/development/compilers/llvm/15/llvm/default.nix index 8eba6a717e7cb..0b7a1bd552258 100644 --- a/pkgs/development/compilers/llvm/15/llvm/default.nix +++ b/pkgs/development/compilers/llvm/15/llvm/default.nix @@ -103,7 +103,7 @@ in stdenv.mkDerivation (rec { preConfigure = '' # Workaround for configure flags that need to have spaces cmakeFlagsArray+=( - -DLLVM_LIT_ARGS='-svj''${NIX_BUILD_CORES} --no-progress-bar' + -DLLVM_LIT_ARGS="-svj''${NIX_BUILD_CORES} --no-progress-bar" ) ''; From f3943882105f0d4bea563b0c75329d3efda50244 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 8 Jan 2023 04:18:43 -0800 Subject: [PATCH 18/30] llvmPackages_15.llvm: enable polly by default this comment has a more complete history: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r1064089830 in short: polly was disabled in the llvm 11 -> llvm 12 copy, mostly by accident most of the Polly install dirs patch has been upstreamed; one change remains (cherry picked from commit 2a58596dd2484924730ea43110966fe16d2abba7) --- .../development/compilers/llvm/15/default.nix | 6 +- .../compilers/llvm/15/llvm/default.nix | 5 +- .../llvm/15/llvm/gnu-install-dirs-polly.patch | 91 +------------------ 3 files changed, 10 insertions(+), 92 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix index 3a48a5b0e00ae..b72dc3f18281a 100644 --- a/pkgs/development/compilers/llvm/15/default.nix +++ b/pkgs/development/compilers/llvm/15/default.nix @@ -1,6 +1,6 @@ { lowPrio, newScope, pkgs, lib, stdenv, stdenvNoCC, cmake, ninja , gccForLibs, preLibcCrossHeaders -, libxml2, python3, isl, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith +, libxml2, python3, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith , buildLlvmTools # tools, but from the previous stage, for cross , targetLlvmLibraries # libraries, but from the next stage, for cross , targetLlvm @@ -41,7 +41,7 @@ let }; tools = lib.makeExtensible (tools: let - callPackage = newScope (tools // { inherit stdenv cmake ninja libxml2 python3 isl release_version version monorepoSrc buildLlvmTools; }); + callPackage = newScope (tools // { inherit stdenv cmake ninja libxml2 python3 release_version version monorepoSrc buildLlvmTools; }); mkExtraBuildCommands0 = cc: '' rsrc="$out/resource-root" mkdir "$rsrc" @@ -220,7 +220,7 @@ let }); libraries = lib.makeExtensible (libraries: let - callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake ninja libxml2 python3 isl release_version version monorepoSrc; }); + callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake ninja libxml2 python3 release_version version monorepoSrc; }); in { compiler-rt-libc = callPackage ./compiler-rt { diff --git a/pkgs/development/compilers/llvm/15/llvm/default.nix b/pkgs/development/compilers/llvm/15/llvm/default.nix index 0b7a1bd552258..b4a441753b939 100644 --- a/pkgs/development/compilers/llvm/15/llvm/default.nix +++ b/pkgs/development/compilers/llvm/15/llvm/default.nix @@ -23,7 +23,7 @@ # broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 # broken for the armv7l builder && !stdenv.hostPlatform.isAarch -, enablePolly ? false +, enablePolly ? true } @args: let @@ -43,7 +43,8 @@ in stdenv.mkDerivation (rec { cp -r ${monorepoSrc}/${pname} "$out" cp -r ${monorepoSrc}/third-party "$out" '' + lib.optionalString enablePolly '' - cp -r ${monorepoSrc}/polly "$out/llvm/tools" + chmod u+w "$out/${pname}/tools" + cp -r ${monorepoSrc}/polly "$out/${pname}/tools" ''); sourceRoot = "${src.name}/${pname}"; diff --git a/pkgs/development/compilers/llvm/15/llvm/gnu-install-dirs-polly.patch b/pkgs/development/compilers/llvm/15/llvm/gnu-install-dirs-polly.patch index 98e998e65a961..b01363e98aa00 100644 --- a/pkgs/development/compilers/llvm/15/llvm/gnu-install-dirs-polly.patch +++ b/pkgs/development/compilers/llvm/15/llvm/gnu-install-dirs-polly.patch @@ -1,77 +1,7 @@ -diff --git a/tools/polly/CMakeLists.txt b/tools/polly/CMakeLists.txt -index ca7c04c565bb..6a6155806ffa 100644 ---- a/tools/polly/CMakeLists.txt -+++ b/tools/polly/CMakeLists.txt -@@ -3,6 +3,8 @@ if (NOT DEFINED LLVM_MAIN_SRC_DIR) - project(Polly) - cmake_minimum_required(VERSION 3.13.4) - -+ include(GNUInstallDirs) -+ - # Where is LLVM installed? - find_package(LLVM CONFIG REQUIRED) - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) -@@ -122,13 +124,13 @@ include_directories( - - if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) - install(DIRECTORY include/ -- DESTINATION include -+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - FILES_MATCHING - PATTERN "*.h" - ) - - install(DIRECTORY ${POLLY_BINARY_DIR}/include/ -- DESTINATION include -+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - FILES_MATCHING - PATTERN "*.h" - PATTERN "CMakeFiles" EXCLUDE -diff --git a/tools/polly/cmake/CMakeLists.txt b/tools/polly/cmake/CMakeLists.txt -index 7cc129ba2e90..137be25e4b80 100644 ---- a/tools/polly/cmake/CMakeLists.txt -+++ b/tools/polly/cmake/CMakeLists.txt -@@ -79,18 +79,18 @@ file(GENERATE - - # Generate PollyConfig.cmake for the install tree. - unset(POLLY_EXPORTS) --set(POLLY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") -+set(POLLY_INSTALL_PREFIX "") - set(POLLY_CONFIG_LLVM_CMAKE_DIR "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") --set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") --set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}") -+set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") -+set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") - if (POLLY_BUNDLED_ISL) - set(POLLY_CONFIG_INCLUDE_DIRS -- "${POLLY_INSTALL_PREFIX}/include" -- "${POLLY_INSTALL_PREFIX}/include/polly" -+ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}" -+ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}/polly" - ) - else() - set(POLLY_CONFIG_INCLUDE_DIRS -- "${POLLY_INSTALL_PREFIX}/include" -+ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_INCLUDEDIR}" - ${ISL_INCLUDE_DIRS} - ) - endif() -@@ -100,12 +100,12 @@ endif() - foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS) - get_target_property(tgt_type ${tgt} TYPE) - if (tgt_type STREQUAL "EXECUTABLE") -- set(tgt_prefix "bin/") -+ set(tgt_prefix "${CMAKE_INSTALL_BINDIR}/") - else() -- set(tgt_prefix "lib/") -+ set(tgt_prefix "${CMAKE_INSTALL_LIBDIR}/") - endif() - -- set(tgt_path "${CMAKE_INSTALL_PREFIX}/${tgt_prefix}$") -+ set(tgt_path "${tgt_prefix}$") - file(RELATIVE_PATH tgt_path ${POLLY_CONFIG_CMAKE_DIR} ${tgt_path}) - - if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY") +This is the one remaining Polly install dirs related change that hasn't made it +into upstream yet; previously this patch file also included: +https://reviews.llvm.org/D117541 + diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake index 518a09b45a42..bd9d6f5542ad 100644 --- a/tools/polly/cmake/polly_macros.cmake @@ -87,16 +17,3 @@ index 518a09b45a42..bd9d6f5542ad 100644 endif() set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) endmacro(add_polly_library) -diff --git a/tools/polly/lib/External/CMakeLists.txt b/tools/polly/lib/External/CMakeLists.txt -index e3a5683fccdc..293b482eb28a 100644 ---- a/tools/polly/lib/External/CMakeLists.txt -+++ b/tools/polly/lib/External/CMakeLists.txt -@@ -290,7 +290,7 @@ if (POLLY_BUNDLED_ISL) - install(DIRECTORY - ${ISL_SOURCE_DIR}/include/ - ${ISL_BINARY_DIR}/include/ -- DESTINATION include/polly -+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/polly - FILES_MATCHING - PATTERN "*.h" - PATTERN "CMakeFiles" EXCLUDE From a50d0b6466dfb89cfbf065c857bc61be0dcd4a16 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Wed, 5 Oct 2022 10:24:18 -0500 Subject: [PATCH 19/30] llvmPackages_15.llvm: add in a missing check dep (cherry picked from commit 6d0c87602fe3281571f0bfaf1fe53822026d1da1) --- .../compilers/llvm/15/llvm/default.nix | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/llvm/default.nix b/pkgs/development/compilers/llvm/15/llvm/default.nix index b4a441753b939..4cb93b84dae71 100644 --- a/pkgs/development/compilers/llvm/15/llvm/default.nix +++ b/pkgs/development/compilers/llvm/15/llvm/default.nix @@ -17,6 +17,7 @@ , which , buildLlvmTools , debugVersion ? false +, doCheck ? true , enableManpages ? false , enableSharedLibraries ? !stdenv.hostPlatform.isStatic , enablePFM ? stdenv.isLinux /* PFM only supports Linux */ @@ -33,6 +34,29 @@ let shortVersion = with lib; concatStringsSep "." (take 1 (splitString "." release_version)); + # Ordinarily we would just the `doCheck` and `checkDeps` functionality + # `mkDerivation` gives us to manage our test dependencies (instead of breaking + # out `doCheck` as a package level attribute). + # + # Unfortunately `lit` does not forward `$PYTHONPATH` to children processes, in + # particular the children it uses to do feature detection. + # + # This means that python deps we add to `checkDeps` (which the python + # interpreter is made aware of via `$PYTHONPATH` – populated by the python + # setup hook) are not picked up by `lit` which causes it to skip tests. + # + # Adding `python3.withPackages (ps: [ ... ])` to `checkDeps` also doesn't work + # because this package is shadowed in `$PATH` by the regular `python3` + # package. + # + # So, we "manually" assemble one python derivation for the package to depend + # on, taking into account whether checks are enabled or not: + python = if doCheck then + let + checkDeps = ps: with ps; [ psutil ]; + in python3.withPackages checkDeps + else python3; + in stdenv.mkDerivation (rec { pname = "llvm"; inherit version; @@ -51,7 +75,7 @@ in stdenv.mkDerivation (rec { outputs = [ "out" "lib" "dev" "python" ]; - nativeBuildInputs = [ cmake ninja python3 ] + nativeBuildInputs = [ cmake ninja python ] ++ optionals enableManpages [ python3.pkgs.sphinx python3.pkgs.recommonmark ]; buildInputs = [ libxml2 libffi ] @@ -59,7 +83,9 @@ in stdenv.mkDerivation (rec { propagatedBuildInputs = [ ncurses zlib ]; - nativeCheckInputs = [ which ]; + nativeCheckInputs = [ + which + ] ++ lib.optional stdenv.isDarwin sysctl; patches = [ ./gnu-install-dirs.patch From 2084262da0ac010bf102cfe0bda4ad5055dd53ff Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 8 Jan 2023 03:47:47 -0800 Subject: [PATCH 20/30] llvmPackages_15.llvm: run the tests on macOS there are a few parts to this: - adding darwin specific check deps - working around referencing LLVM dylibs during the checkPhase in a way that supports darwin + previously we just set `$LD_LIBRARY_PATH` and/or made some strategic symlinks + now we have LLVM's `lit` config set the appropriate env vars as needed (as is done for other LLVM subprojects) + in retrospect switching to `installCheckPhase` might have been the better move.. - patching `lit` to deal with `$DYLD_LIBRARY_PATH` being purged for new "protected" processes more details within. (cherry picked from commit c7231c0b6d8e8a5dc622844780f3ed6f37b06692) --- .../compilers/llvm/15/llvm/default.nix | 69 +++++++++++----- ...-script-runner-set-dyld-library-path.patch | 26 ++++++ .../llvm-lit-cfg-add-libs-to-dylib-path.patch | 79 +++++++++++++++++++ ...polly-lit-cfg-add-libs-to-dylib-path.patch | 24 ++++++ 4 files changed, 180 insertions(+), 18 deletions(-) create mode 100644 pkgs/development/compilers/llvm/15/llvm/lit-shell-script-runner-set-dyld-library-path.patch create mode 100644 pkgs/development/compilers/llvm/15/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch create mode 100644 pkgs/development/compilers/llvm/15/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch diff --git a/pkgs/development/compilers/llvm/15/llvm/default.nix b/pkgs/development/compilers/llvm/15/llvm/default.nix index 4cb93b84dae71..3bf1ff7cb9142 100644 --- a/pkgs/development/compilers/llvm/15/llvm/default.nix +++ b/pkgs/development/compilers/llvm/15/llvm/default.nix @@ -15,9 +15,11 @@ , release_version , zlib , which +, sysctl , buildLlvmTools , debugVersion ? false -, doCheck ? true +, doCheck ? (!stdenv.isx86_32 /* TODO: why */) && (!stdenv.hostPlatform.isMusl) + && (stdenv.hostPlatform == stdenv.buildPlatform) , enableManpages ? false , enableSharedLibraries ? !stdenv.hostPlatform.isStatic , enablePFM ? stdenv.isLinux /* PFM only supports Linux */ @@ -89,7 +91,53 @@ in stdenv.mkDerivation (rec { patches = [ ./gnu-install-dirs.patch - ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; + + # Running the tests involves invoking binaries (like `opt`) that depend on + # the LLVM dylibs and reference them by absolute install path (i.e. their + # nix store path). + # + # Because we have not yet run the install phase (we're running these tests + # as part of `checkPhase` instead of `installCheckPhase`) these absolute + # paths do not exist yet; to work around this we point the loader (`ld` on + # unix, `dyld` on macOS) at the `lib` directory which will later become this + # package's `lib` output. + # + # Previously we would just set `LD_LIBRARY_PATH` to include the build `lib` + # dir but: + # - this doesn't generalize well to other platforms; `lit` doesn't forward + # `DYLD_LIBRARY_PATH` (macOS): + # + https://github.com/llvm/llvm-project/blob/0d89963df354ee309c15f67dc47c8ab3cb5d0fb2/llvm/utils/lit/lit/TestingConfig.py#L26 + # - even if `lit` forwarded this env var, we actually cannot set + # `DYLD_LIBRARY_PATH` in the child processes `lit` launches because + # `DYLD_LIBRARY_PATH` (and `DYLD_FALLBACK_LIBRARY_PATH`) is cleared for + # "protected processes" (i.e. the python interpreter that runs `lit`): + # https://stackoverflow.com/a/35570229 + # - other LLVM subprojects deal with this issue by having their `lit` + # configuration set these env vars for us; it makes sense to do the same + # for LLVM: + # + https://github.com/llvm/llvm-project/blob/4c106cfdf7cf7eec861ad3983a3dd9a9e8f3a8ae/clang-tools-extra/test/Unit/lit.cfg.py#L22-L31 + # + # !!! TODO: look into upstreaming this patch + ./llvm-lit-cfg-add-libs-to-dylib-path.patch + + # `lit` has a mode where it executes run lines as a shell script which is + # constructs; this is problematic for macOS because it means that there's + # another process in between `lit` and the binaries being tested. As noted + # above, this means that `DYLD_LIBRARY_PATH` is cleared which means that our + # tests fail with dyld errors. + # + # To get around this we patch `lit` to reintroduce `DYLD_LIBRARY_PATH`, when + # present in the test configuration. + # + # It's not clear to me why this isn't an issue for LLVM developers running + # on macOS (nothing about this _seems_ nix specific).. + ./lit-shell-script-runner-set-dyld-library-path.patch + ] ++ lib.optionals enablePolly [ + ./gnu-install-dirs-polly.patch + + # Just like the `llvm-lit-cfg` patch, but for `polly`. + ./polly-lit-cfg-add-libs-to-dylib-path.patch + ]; postPatch = optionalString stdenv.isDarwin '' substituteInPlace cmake/modules/AddLLVM.cmake \ @@ -134,12 +182,6 @@ in stdenv.mkDerivation (rec { ) ''; - # hacky fix: created binaries need to be run before installation - preBuild = '' - mkdir -p $out/ - ln -sv $PWD/lib $out - ''; - # E.g. mesa.drivers use the build-id as a cache key (see #93946): LDFLAGS = optionalString (enableSharedLibraries && !stdenv.isDarwin) "-Wl,--build-id=sha1"; @@ -217,14 +259,6 @@ in stdenv.mkDerivation (rec { ) ]; - postBuild = '' - rm -fR $out - ''; - - preCheck = '' - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib - ''; - postInstall = '' mkdir -p $python/share mv $out/share/opt-viewer $python/share/opt-viewer @@ -243,8 +277,7 @@ in stdenv.mkDerivation (rec { cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native ''; - doCheck = stdenv.isLinux && (!stdenv.isx86_32) && (!stdenv.hostPlatform.isMusl) - && (stdenv.hostPlatform == stdenv.buildPlatform); + inherit doCheck; checkTarget = "check-all"; diff --git a/pkgs/development/compilers/llvm/15/llvm/lit-shell-script-runner-set-dyld-library-path.patch b/pkgs/development/compilers/llvm/15/llvm/lit-shell-script-runner-set-dyld-library-path.patch new file mode 100644 index 0000000000000..32f1d13a9dc23 --- /dev/null +++ b/pkgs/development/compilers/llvm/15/llvm/lit-shell-script-runner-set-dyld-library-path.patch @@ -0,0 +1,26 @@ +diff --git a/utils/lit/lit/TestRunner.py b/utils/lit/lit/TestRunner.py +index 0242e0b75af3..d732011306f7 100644 +--- a/utils/lit/lit/TestRunner.py ++++ b/utils/lit/lit/TestRunner.py +@@ -1029,6 +1029,12 @@ def executeScript(test, litConfig, tmpBase, commands, cwd): + f.write('@echo off\n') + f.write('\n@if %ERRORLEVEL% NEQ 0 EXIT\n'.join(commands)) + else: ++ # This env var is *purged* when invoking subprocesses so we have to ++ # manually set it from within the bash script in order for the commands ++ # in run lines to see this var: ++ if "DYLD_LIBRARY_PATH" in test.config.environment: ++ f.write(f'export DYLD_LIBRARY_PATH="{test.config.environment["DYLD_LIBRARY_PATH"]}"\n') ++ + for i, ln in enumerate(commands): + match = re.match(kPdbgRegex, ln) + if match: +@@ -1363,7 +1369,7 @@ def applySubstitutions(script, substitutions, conditions={}, + return processed + + process = processLine if recursion_limit is None else processLineToFixedPoint +- ++ + return [unescapePercents(process(ln)) for ln in script] + + diff --git a/pkgs/development/compilers/llvm/15/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch b/pkgs/development/compilers/llvm/15/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch new file mode 100644 index 0000000000000..d824516c0a16c --- /dev/null +++ b/pkgs/development/compilers/llvm/15/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch @@ -0,0 +1,79 @@ +diff --git a/test/Unit/lit.cfg.py b/test/Unit/lit.cfg.py +index 81e8dc04acea..479ff95681e2 100644 +--- a/test/Unit/lit.cfg.py ++++ b/test/Unit/lit.cfg.py +@@ -3,6 +3,7 @@ + # Configuration file for the 'lit' test runner. + + import os ++import platform + import subprocess + + import lit.formats +@@ -55,3 +56,26 @@ if sys.platform in ['win32', 'cygwin'] and os.path.isdir(config.shlibdir): + # Win32 may use %SYSTEMDRIVE% during file system shell operations, so propogate. + if sys.platform == 'win32' and 'SYSTEMDRIVE' in os.environ: + config.environment['SYSTEMDRIVE'] = os.environ['SYSTEMDRIVE'] ++ ++# Add the LLVM dynamic libs to the platform-specific loader search path env var: ++# ++# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify.. ++def find_shlibpath_var(): ++ if platform.system() in ['Linux', 'FreeBSD', 'NetBSD', 'OpenBSD', 'SunOS']: ++ yield 'LD_LIBRARY_PATH' ++ elif platform.system() == 'Darwin': ++ yield 'DYLD_LIBRARY_PATH' ++ elif platform.system() == 'Windows': ++ yield 'PATH' ++ elif platform.system() == 'AIX': ++ yield 'LIBPATH' ++ ++for shlibpath_var in find_shlibpath_var(): ++ shlibpath = os.path.pathsep.join( ++ (config.shlibdir, ++ config.environment.get(shlibpath_var, ''))) ++ config.environment[shlibpath_var] = shlibpath ++ break ++else: ++ lit_config.warning("unable to inject shared library path on '{}'" ++ .format(platform.system())) +diff --git a/test/lit.cfg.py b/test/lit.cfg.py +index 75a38b4c5dad..856fc75c9d74 100644 +--- a/test/lit.cfg.py ++++ b/test/lit.cfg.py +@@ -42,6 +42,26 @@ llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True) + llvm_config.with_system_environment( + ['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP']) + ++# Add the LLVM dynamic libs to the platform-specific loader search path env var: ++# ++# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify.. ++def find_shlibpath_var(): ++ if platform.system() in ['Linux', 'FreeBSD', 'NetBSD', 'OpenBSD', 'SunOS']: ++ yield 'LD_LIBRARY_PATH' ++ elif platform.system() == 'Darwin': ++ yield 'DYLD_LIBRARY_PATH' ++ elif platform.system() == 'Windows': ++ yield 'PATH' ++ elif platform.system() == 'AIX': ++ yield 'LIBPATH' ++ ++for shlibpath_var in find_shlibpath_var(): ++ shlibpath = config.llvm_shlib_dir ++ llvm_config.with_environment(shlibpath_var, shlibpath, append_path = True) ++ break ++else: ++ lit_config.warning("unable to inject shared library path on '{}'" ++ .format(platform.system())) + + # Set up OCAMLPATH to include newly built OCaml libraries. + top_ocaml_lib = os.path.join(config.llvm_lib_dir, 'ocaml') +@@ -318,7 +338,7 @@ def have_cxx_shared_library(): + + try: + readobj_cmd = subprocess.Popen( +- [readobj_exe, '--needed-libs', readobj_exe], stdout=subprocess.PIPE) ++ [readobj_exe, '--needed-libs', readobj_exe], stdout=subprocess.PIPE, env=config.environment) + except OSError: + print('could not exec llvm-readobj') + return False diff --git a/pkgs/development/compilers/llvm/15/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch b/pkgs/development/compilers/llvm/15/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch new file mode 100644 index 0000000000000..1354ad267314a --- /dev/null +++ b/pkgs/development/compilers/llvm/15/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch @@ -0,0 +1,24 @@ +diff --git a/tools/polly/test/lit.cfg b/tools/polly/test/lit.cfg +index 41e3a589c61e..09f3b17498b0 100644 +--- a/tools/polly/test/lit.cfg ++++ b/tools/polly/test/lit.cfg +@@ -36,9 +36,17 @@ base_paths = [config.llvm_tools_dir, config.environment['PATH']] + path = os.path.pathsep.join(base_paths + config.extra_paths) + config.environment['PATH'] = path + ++# (Copied from polly/test/Unit/lit.cfg) ++if platform.system() == 'Darwin': ++ shlibpath_var = 'DYLD_LIBRARY_PATH' ++elif platform.system() == 'Windows': ++ shlibpath_var = 'PATH' ++else: ++ shlibpath_var = 'LD_LIBRARY_PATH' ++ + path = os.path.pathsep.join((config.llvm_libs_dir, +- config.environment.get('LD_LIBRARY_PATH',''))) +-config.environment['LD_LIBRARY_PATH'] = path ++ config.environment.get(shlibpath_var,''))) ++config.environment[shlibpath_var] = path + + llvm_config.use_default_substitutions() + From 4d44e1dab67f3cca077b8a789b7263afbaf608c2 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 8 Jan 2023 04:31:14 -0800 Subject: [PATCH 21/30] llvmPackages_15.llvm: adjust a path, skip an xfail test on darwin (cherry picked from commit 0ee52512f0fd4f5b675ba9f742a300b50adf27d3) --- pkgs/development/compilers/llvm/15/llvm/default.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkgs/development/compilers/llvm/15/llvm/default.nix b/pkgs/development/compilers/llvm/15/llvm/default.nix index 3bf1ff7cb9142..775270b29b63c 100644 --- a/pkgs/development/compilers/llvm/15/llvm/default.nix +++ b/pkgs/development/compilers/llvm/15/llvm/default.nix @@ -4,6 +4,7 @@ , runCommand , fetchpatch , cmake +, darwin , ninja , python3 , libffi @@ -143,6 +144,15 @@ in stdenv.mkDerivation (rec { substituteInPlace cmake/modules/AddLLVM.cmake \ --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" + + # As of LLVM 15, marked as XFAIL on arm64 macOS but lit doesn't seem to pick + # this up: https://github.com/llvm/llvm-project/blob/c344d97a125b18f8fed0a64aace73c49a870e079/llvm/test/MC/ELF/cfi-version.ll#L7 + rm test/MC/ELF/cfi-version.ll + + # This test tries to call `sw_vers` by absolute path (`/usr/bin/sw_vers`) + # thus fails under the sandbox: + substituteInPlace unittests/Support/Host.cpp \ + --replace '/usr/bin/sw_vers' "${(builtins.toString darwin.DarwinTools) + "/bin/sw_vers" }" '' + '' # FileSystem permissions tests fail with various special bits substituteInPlace unittests/Support/CMakeLists.txt \ From 2e996b95d39d034352debe631ac8b31198563985 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Fri, 27 Jan 2023 11:26:14 -0800 Subject: [PATCH 22/30] llvmPackages_15.llvm: fix the tests on `x86_64-darwin` Details within but ultimately there isn't a satisfying resolution for any of the three test failures we were seeing and all three deserve further exploration. For the `sw_vers` macOS version issue in particular, it's possible to observe the nixpkgs provided `CoreFoundation` vs system `CoreFoundation` for `x86_64` and `aarch64` like so (on a host running macOS `13.0.1`): ```console $ nix-shell -p darwin.DarwinTools --system aarch64-darwin --command "sw_vers" ProductName: macOS ProductVersion: 13.0.1 BuildVersion: 22A400 $ nix-shell -p darwin.DarwinTools --system x86_64-darwin --command "sw_vers" ProductName: Mac OS X ProductVersion: 10.16 BuildVersion: 22A400 ``` Where `/System/Library/CoreServices/SystemVersion.plist` has: ```console $ cat /System/Library/CoreServices/SystemVersion.plist | grep ProductVersion -A 1 ProductVersion 13.0.1 ``` Further: ```console $ nix-shell -p darwin.DarwinTools --system aarch64-darwin --command 'otool -L $(which sw_vers)' /nix/store/nb2q33ak2zif49ndcpc6m823z0vhmy8y-DarwinTools-1/bin/sw_vers: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1770.255.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.60.1) $ nix-shell -p darwin.DarwinTools --system x86_64-darwin --command 'otool -L $(which sw_vers)' /nix/store/88v4kjvgwl71byfpvd0baviiq7l5appc-DarwinTools-1/bin/sw_vers: @rpath/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1454.90.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.60.2) ``` For the `x86_64` `sw_vers` binary we can see rpath: ```console $ nix-shell -p darwin.DarwinTools --system x86_64-darwin --command 'otool -l $(which sw_vers)' | grep LC_RPATH -A 2 -B 1 Load command 13 cmd LC_RPATH cmdsize 120 path /nix/store/zvr4wypbgskhhw9cawfn7mmxfa75nh8f-swift-corefoundation-unstable-2018-09-14/Library/Frameworks (offset 12) ``` And we can confirm that the nixpkgs provided `CoreFoundation` is what ultimately gets loaded: ```console $ nix-shell -p darwin.DarwinTools --system x86_64-darwin --command 'DYLD_PRINT_LIBRARIES=1 sw_vers' dyld[16215]: /nix/store/88v4kjvgwl71byfpvd0baviiq7l5appc-DarwinTools-1/bin/sw_vers dyld[16215]: /nix/store/zvr4wypbgskhhw9cawfn7mmxfa75nh8f-swift-corefoundation-unstable-2018-09-14/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation dyld[16215]: /nix/store/xd2a4xh8kdwq0j67hzgw720npdw5hzkk-ICU-66108/lib/libicucore.A.dylib ``` ```bash nix-diff \ $(nix path-info nixpkgs#legacyPackages.aarch64-darwin.darwin.DarwinTools --derivation) \ $(nix path-info nixpkgs#legacyPackages.x86_64-darwin.darwin.DarwinTools --derivation) ``` doesn't show any _obvious_ discrepancies (cherry picked from commit eafb8fbd3215f0fe6b1d4a0360a9c4f761677179) --- .../compilers/llvm/15/llvm/default.nix | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/pkgs/development/compilers/llvm/15/llvm/default.nix b/pkgs/development/compilers/llvm/15/llvm/default.nix index 775270b29b63c..3a307cc22ac82 100644 --- a/pkgs/development/compilers/llvm/15/llvm/default.nix +++ b/pkgs/development/compilers/llvm/15/llvm/default.nix @@ -150,9 +150,58 @@ in stdenv.mkDerivation (rec { rm test/MC/ELF/cfi-version.ll # This test tries to call `sw_vers` by absolute path (`/usr/bin/sw_vers`) - # thus fails under the sandbox: + # and thus fails under the sandbox: substituteInPlace unittests/Support/Host.cpp \ --replace '/usr/bin/sw_vers' "${(builtins.toString darwin.DarwinTools) + "/bin/sw_vers" }" + '' + optionalString (stdenv.isDarwin && stdenv.hostPlatform.isx86) '' + # This test tries to call the intrinsics `@llvm.roundeven.f32` and + # `@llvm.roundeven.f64` which seem to (incorrectly?) lower to `roundevenf` + # and `roundeven` on x86_64 macOS. + # + # However these functions are glibc specific so the test fails: + # - https://www.gnu.org/software/gnulib/manual/html_node/roundevenf.html + # - https://www.gnu.org/software/gnulib/manual/html_node/roundeven.html + # + # TODO(@rrbutani): this seems to run fine on `aarch64-darwin`, why does it + # pass there? + substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \ + --replace "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \ + --replace "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" "" + + # This test fails on darwin x86_64 because `sw_vers` reports a different + # macOS version than what LLVM finds by reading + # `/System/Library/CoreServices/SystemVersion.plist` (which is passed into + # the sandbox on macOS). + # + # The `sw_vers` provided by nixpkgs reports the macOS version associated + # with the `CoreFoundation` framework with which it was built. Because + # nixpkgs pins the SDK for `aarch64-darwin` and `x86_64-darwin` what + # `sw_vers` reports is not guaranteed to match the macOS version of the host + # that's building this derivation. + # + # Astute readers will note that we only _patch_ this test on aarch64-darwin + # (to use the nixpkgs provided `sw_vers`) instead of disabling it outright. + # So why does this test pass on aarch64? + # + # Well, it seems that `sw_vers` on aarch64 actually links against the _host_ + # CoreFoundation framework instead of the nixpkgs provided one. + # + # Not entirely sure what the right fix is here. I'm assuming aarch64 + # `sw_vers` doesn't intentionally link against the host `CoreFoundation` + # (still digging into how this ends up happening, will follow up) but that + # aside I think the more pertinent question is: should we be patching LLVM's + # macOS version detection logic to use `sw_vers` instead of reading host + # paths? This *is* a way in which details about builder machines can creep + # into the artifacts that are produced, affecting reproducibility, but it's + # not clear to me when/where/for what this even gets used in LLVM. + # + # TODO(@rrbutani): fix/follow-up + substituteInPlace unittests/Support/Host.cpp \ + --replace "getMacOSHostVersion" "DISABLED_getMacOSHostVersion" + + # This test fails with a `dysmutil` crash; have not yet dug into what's + # going on here (TODO(@rrbutani)). + rm test/tools/dsymutil/ARM/obfuscated.test '' + '' # FileSystem permissions tests fail with various special bits substituteInPlace unittests/Support/CMakeLists.txt \ From 67a5ccc22f7cb3ce4e3215c196ae9233d25d1f5b Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 8 Jan 2023 06:27:52 -0800 Subject: [PATCH 23/30] llvmPackages_15.llvm: disable some RISC-V ZBP tests on arm32 see this thread for context: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999790443 Co-authored-by: misuzu (cherry picked from commit 5e5ed7d8161e465fd086a74029e86c53b262a9d1) --- pkgs/development/compilers/llvm/15/llvm/default.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/development/compilers/llvm/15/llvm/default.nix b/pkgs/development/compilers/llvm/15/llvm/default.nix index 3a307cc22ac82..81efbf56100ab 100644 --- a/pkgs/development/compilers/llvm/15/llvm/default.nix +++ b/pkgs/development/compilers/llvm/15/llvm/default.nix @@ -227,6 +227,12 @@ in stdenv.mkDerivation (rec { rm test/tools/gold/X86/split-dwarf.ll rm test/tools/llvm-dwarfdump/X86/prettyprint_types.s rm test/tools/llvm-dwarfdump/X86/simplified-template-names.s + + # !!! Note: these tests are removed in LLVM 16. + # + # See here for context: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999790443 + rm test/CodeGen/RISCV/rv32zbp.ll + rm test/CodeGen/RISCV/rv64zbp.ll '' + optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' # Seems to require certain floating point hardware (NEON?) rm test/ExecutionEngine/frem.ll From 6730215db8f2055219ea4fbd12d1b43426aac9dc Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 15 Jan 2023 13:01:22 -0800 Subject: [PATCH 24/30] llvmPackages_15.llvm: specify some deps explicitly to fix cross-compilation The two scenarios described within where splicing doesn't handle selecting the right package for us are observable in the following (nix repl session): ``` > np = import { system = "x86_64-linux"; crossSystem = { config = "aarch64-linux"; }; } > np.__splicedPackages.hello ? __spliced true > np.__splicedPackages.python3Packages.psutil ? __spliced true > np.__splicedPackages.python3.pkgs.psutil ? __spliced false > (np.__splicedPackages.python3.withPackages (ps: with ps; [psutil])) ? __spliced false ``` See: #211340 (cherry picked from commit 3436075b2a7466a36dbc5687bbb98c6ab748308d) --- pkgs/development/compilers/llvm/15/llvm/default.nix | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/llvm/default.nix b/pkgs/development/compilers/llvm/15/llvm/default.nix index 81efbf56100ab..40fb105cdc523 100644 --- a/pkgs/development/compilers/llvm/15/llvm/default.nix +++ b/pkgs/development/compilers/llvm/15/llvm/default.nix @@ -7,6 +7,7 @@ , darwin , ninja , python3 +, python3Packages , libffi , libbfd , libpfm @@ -55,9 +56,12 @@ let # So, we "manually" assemble one python derivation for the package to depend # on, taking into account whether checks are enabled or not: python = if doCheck then + # Note that we _explicitly_ ask for a python interpreter for our host + # platform here; the splicing that would ordinarily take care of this for + # us does not seem to work once we use `withPackages`. let checkDeps = ps: with ps; [ psutil ]; - in python3.withPackages checkDeps + in pkgsBuildBuild.targetPackages.python3.withPackages checkDeps else python3; in stdenv.mkDerivation (rec { @@ -79,7 +83,11 @@ in stdenv.mkDerivation (rec { outputs = [ "out" "lib" "dev" "python" ]; nativeBuildInputs = [ cmake ninja python ] - ++ optionals enableManpages [ python3.pkgs.sphinx python3.pkgs.recommonmark ]; + ++ optionals enableManpages [ + # Note: we intentionally use `python3Packages` instead of `python3.pkgs`; + # splicing does *not* work with the latter. (TODO: fix) + python3Packages.sphinx python3Packages.recommonmark + ]; buildInputs = [ libxml2 libffi ] ++ optional enablePFM libpfm; # exegesis From 13d396e7f3da681a1538b010abb7f9fa1445662e Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Fri, 27 Jan 2023 12:44:45 -0800 Subject: [PATCH 25/30] llvmPackages_15.clang: drop the C++ std version `-DCMAKE_CXX_FLAG` Context: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r1085220705 (cherry picked from commit 404ef6b6c92f342047b0cac79ae211189c8d09ff) --- pkgs/development/compilers/llvm/15/clang/default.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/development/compilers/llvm/15/clang/default.nix b/pkgs/development/compilers/llvm/15/clang/default.nix index 6102947b1afd8..faf3452c6a4ed 100644 --- a/pkgs/development/compilers/llvm/15/clang/default.nix +++ b/pkgs/development/compilers/llvm/15/clang/default.nix @@ -28,7 +28,6 @@ let cmakeFlags = [ "-DCLANG_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/clang" - "-DCMAKE_CXX_FLAGS=-std=c++14" "-DCLANGD_BUILD_XPC=OFF" "-DLLVM_ENABLE_RTTI=ON" ] ++ lib.optionals enableManpages [ From cd567ce2bcb4e4181ba0902e85f52553c6b212b7 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 15 Jan 2023 12:54:39 -0800 Subject: [PATCH 26/30] llvmPackages_15.openmp: add a missing darwin check dependency the tests still don't all pass so `doCheck` is still disabled (cherry picked from commit 8f16b4be50aed6d9497f0bfa1f4456f869b4994d) --- pkgs/development/compilers/llvm/15/openmp/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/development/compilers/llvm/15/openmp/default.nix b/pkgs/development/compilers/llvm/15/openmp/default.nix index 52aeb4bd9800f..d51335436ad23 100644 --- a/pkgs/development/compilers/llvm/15/openmp/default.nix +++ b/pkgs/development/compilers/llvm/15/openmp/default.nix @@ -11,6 +11,7 @@ , clang-unwrapped , perl , pkg-config +, xcbuild , version }: @@ -39,6 +40,8 @@ stdenv.mkDerivation rec { (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) ]; + nativeCheckInputs = lib.optional stdenv.hostPlatform.isDarwin xcbuild.xcrun; + # Unsup:Pass:XFail:Fail # 26:267:16:8 doCheck = false; From ee64ddd0ea1edac3806f082a3df47bb392aad95c Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Fri, 7 Oct 2022 22:47:47 -0500 Subject: [PATCH 27/30] llvmPackages_15: misc fixes, notes (cherry picked from commit f8cbbdd05b167185fdcabd5f494daa02215667b3) --- pkgs/development/compilers/llvm/15/clang/default.nix | 3 --- pkgs/development/compilers/llvm/15/lldb/default.nix | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/clang/default.nix b/pkgs/development/compilers/llvm/15/clang/default.nix index faf3452c6a4ed..b0671150a7bd9 100644 --- a/pkgs/development/compilers/llvm/15/clang/default.nix +++ b/pkgs/development/compilers/llvm/15/clang/default.nix @@ -57,9 +57,6 @@ let sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' \ -e 's/Args.hasArg(options::OPT_nostdlibinc)/true/' \ lib/Driver/ToolChains/*.cpp - - # Patch for standalone doc building - sed -i '1s,^,find_package(Sphinx REQUIRED)\n,' docs/CMakeLists.txt '' + lib.optionalString stdenv.hostPlatform.isMusl '' sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp ''; diff --git a/pkgs/development/compilers/llvm/15/lldb/default.nix b/pkgs/development/compilers/llvm/15/lldb/default.nix index 15bcb40c3b437..4b50b79cf613b 100644 --- a/pkgs/development/compilers/llvm/15/lldb/default.nix +++ b/pkgs/development/compilers/llvm/15/lldb/default.nix @@ -26,6 +26,9 @@ , lua5_3 }: +# TODO: we build the python bindings but don't expose them as a python package +# TODO: expose the vscode extension? + stdenv.mkDerivation (rec { pname = "lldb"; inherit version; From ace2aa8deb772feba478b0e066f86f1f5878983a Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Fri, 27 Jan 2023 12:58:58 -0800 Subject: [PATCH 28/30] llvmPackages_15: update licenses Context: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r1073157093 All the subprojects seem to be uniformly licensed under NCSA and the LLVM license now (with the exception of openmp which has an additional Intel license that doesn't seem to be in SPDX?); see: - https://github.com/llvm/llvm-project/blob/llvmorg-15.0.7/compiler-rt/LICENSE.TXT - https://github.com/llvm/llvm-project/blob/llvmorg-15.0.7/libcxx/LICENSE.TXT - https://github.com/llvm/llvm-project/blob/llvmorg-15.0.7/libcxxabi/LICENSE.TXT - https://github.com/llvm/llvm-project/blob/llvmorg-15.0.7/openmp/LICENSE.TXT (cherry picked from commit 386aba3115176b11eb49a0606e9dd17506273776) --- pkgs/development/compilers/llvm/15/compiler-rt/default.nix | 3 --- pkgs/development/compilers/llvm/15/default.nix | 2 +- pkgs/development/compilers/llvm/15/libcxx/default.nix | 3 --- pkgs/development/compilers/llvm/15/libcxxabi/default.nix | 3 --- pkgs/development/compilers/llvm/15/openmp/default.nix | 3 --- 5 files changed, 1 insertion(+), 13 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/default.nix b/pkgs/development/compilers/llvm/15/compiler-rt/default.nix index bc7195b836a1a..722a5bd90cbd6 100644 --- a/pkgs/development/compilers/llvm/15/compiler-rt/default.nix +++ b/pkgs/development/compilers/llvm/15/compiler-rt/default.nix @@ -152,8 +152,5 @@ stdenv.mkDerivation { implementations of run-time libraries for dynamic testing tools such as AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. ''; - # "All of the code in the compiler-rt project is dual licensed under the MIT - # license and the UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; }; } diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix index b72dc3f18281a..08647a736f1ac 100644 --- a/pkgs/development/compilers/llvm/15/default.nix +++ b/pkgs/development/compilers/llvm/15/default.nix @@ -35,7 +35,7 @@ let }; llvm_meta = { - license = lib.licenses.ncsa; + license = with lib.licenses; [ ncsa llvm-exception ]; maintainers = lib.teams.llvm.members; platforms = lib.platforms.all; }; diff --git a/pkgs/development/compilers/llvm/15/libcxx/default.nix b/pkgs/development/compilers/llvm/15/libcxx/default.nix index 94374c8a312df..7762df29386ef 100644 --- a/pkgs/development/compilers/llvm/15/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/15/libcxx/default.nix @@ -103,8 +103,5 @@ stdenv.mkDerivation rec { libc++ is an implementation of the C++ standard library, targeting C++11, C++14 and above. ''; - # "All of the code in libc++ is dual licensed under the MIT license and the - # UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; }; } diff --git a/pkgs/development/compilers/llvm/15/libcxxabi/default.nix b/pkgs/development/compilers/llvm/15/libcxxabi/default.nix index cb5fa44f07009..fd99f4553c0cc 100644 --- a/pkgs/development/compilers/llvm/15/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/15/libcxxabi/default.nix @@ -100,9 +100,6 @@ stdenv.mkDerivation rec { longDescription = '' libc++abi is a new implementation of low level support for a standard C++ library. ''; - # "All of the code in libc++abi is dual licensed under the MIT license and - # the UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; maintainers = llvm_meta.maintainers ++ [ lib.maintainers.vlstill ]; }; } diff --git a/pkgs/development/compilers/llvm/15/openmp/default.nix b/pkgs/development/compilers/llvm/15/openmp/default.nix index d51335436ad23..8047cb1122dee 100644 --- a/pkgs/development/compilers/llvm/15/openmp/default.nix +++ b/pkgs/development/compilers/llvm/15/openmp/default.nix @@ -67,8 +67,5 @@ stdenv.mkDerivation rec { "clang -fopenmp" must be linked before it can run and the library that supports offload to target devices. ''; - # "All of the code is dual licensed under the MIT license and the UIUC - # License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; }; } From f2583cbd766a6870fe97e0a8a4dc1e569cbd2066 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Fri, 27 Jan 2023 14:51:12 -0800 Subject: [PATCH 29/30] llvmPackages_15.llvm: add checks for the LLVM version this is in preparation for the next commit which exposes the release information and monorepo source as overridable args (which makes it easier for users to use their own LLVM in nixpkgs) this commit only adds a check in the `llvm` package's postConfigure that makes sure the LLVM source provided matches the version we were given; the actual machinery (functionally just a cosmetic change; causes no rebuilds) is in the next commit (cherry picked from commit 8afa321b8ac7a52c479c5226364c48c544038c06) --- .../compilers/llvm/15/llvm/default.nix | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pkgs/development/compilers/llvm/15/llvm/default.nix b/pkgs/development/compilers/llvm/15/llvm/default.nix index 40fb105cdc523..e0b79a9acfefc 100644 --- a/pkgs/development/compilers/llvm/15/llvm/default.nix +++ b/pkgs/development/compilers/llvm/15/llvm/default.nix @@ -255,6 +255,38 @@ in stdenv.mkDerivation (rec { ) ''; + # Defensive check: some paths (that we make symlinks to) depend on the release + # version, for example: + # - https://github.com/llvm/llvm-project/blob/406bde9a15136254f2b10d9ef3a42033b3cb1b16/clang/lib/Headers/CMakeLists.txt#L185 + # + # So we want to sure that the version in the source matches the release + # version we were given. + # + # We do this check here, in the LLVM build, because it happens early. + postConfigure = let + v = lib.versions; + major = v.major release_version; + minor = v.minor release_version; + patch = v.patch release_version; + in '' + # $1: part, $2: expected + check_version() { + part="''${1^^}" + part="$(cat include/llvm/Config/llvm-config.h | grep "#define LLVM_VERSION_''${part} " | cut -d' ' -f3)" + + if [[ "$part" != "$2" ]]; then + echo >&2 \ + "mismatch in the $1 version! we have version ${release_version}" \ + "and expected the $1 version to be '$2'; the source has '$part' instead" + exit 3 + fi + } + + check_version major ${major} + check_version minor ${minor} + check_version patch ${patch} + ''; + # E.g. mesa.drivers use the build-id as a cache key (see #93946): LDFLAGS = optionalString (enableSharedLibraries && !stdenv.isDarwin) "-Wl,--build-id=sha1"; From 7270892f01c32183cb3cd46a09e7692080a79c41 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Fri, 27 Jan 2023 14:51:38 -0800 Subject: [PATCH 30/30] llvmPackages_15: expose the release information and monorepo source as overridable args this makes it easier for users to use their own LLVM in nixpkgs (cherry picked from commit d231d18e4aa5e1d00f86b4f484f9e4344538e3ea) --- .../development/compilers/llvm/15/default.nix | 71 ++++++++++++++++--- 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix index 08647a736f1ac..db98f2854a093 100644 --- a/pkgs/development/compilers/llvm/15/default.nix +++ b/pkgs/development/compilers/llvm/15/default.nix @@ -16,24 +16,73 @@ then null else pkgs.bintools , darwin +# LLVM release information; specify one of these but not both: +, gitRelease ? null + # i.e.: + # { + # version = /* i.e. "15.0.0" */; + # rev = /* commit SHA */; + # rev-version = /* human readable version; i.e. "unstable-2022-26-07" */; + # sha256 = /* checksum for this release, can omit if specifying your own `monorepoSrc` */; + # } +, officialRelease ? { version = "15.0.7"; sha256 = "sha256-wjuZQyXQ/jsmvy6y1aksCcEDXGBjuhpgngF3XQJ/T4s="; } + # i.e.: + # { + # version = /* i.e. "15.0.0" */; + # candidate = /* optional; if specified, should be: "rcN" */ + # sha256 = /* checksum for this release, can omit if specifying your own `monorepoSrc` */; + # } +# By default, we'll try to fetch a release from `github:llvm/llvm-project` +# corresponding to the `gitRelease` or `officialRelease` specified. +# +# You can provide your own LLVM source by specifying this arg but then it's up +# to you to make sure that the LLVM repo given matches the release configuration +# specified. +, monorepoSrc ? null }: +assert let + int = a: if a then 1 else 0; + xor = a: b: ((builtins.bitXor (int a) (int b)) == 1); +in + lib.assertMsg + (xor + (gitRelease != null) + (officialRelease != null)) + ("must specify `gitRelease` or `officialRelease`" + + (lib.optionalString (gitRelease != null) " — not both")); let - release_version = "15.0.7"; - candidate = ""; # empty or "rcN" - dash-candidate = lib.optionalString (candidate != "") "-${candidate}"; - rev = ""; # When using a Git commit - rev-version = ""; # When using a Git commit - version = if rev != "" then rev-version else "${release_version}${dash-candidate}"; - targetConfig = stdenv.targetPlatform.config; - - monorepoSrc = fetchFromGitHub { + monorepoSrc' = monorepoSrc; +in let + releaseInfo = if gitRelease != null then rec { + original = gitRelease; + release_version = original.version; + version = gitRelease.rev-version; + } else rec { + original = officialRelease; + release_version = original.version; + version = if original ? candidate then + "${release_version}-${original.candidate}" + else + release_version; + }; + + monorepoSrc = if monorepoSrc' != null then + monorepoSrc' + else let + sha256 = releaseInfo.original.sha256; + rev = if gitRelease != null then + gitRelease.rev + else + "llvmorg-${releaseInfo.version}"; + in fetchFromGitHub { owner = "llvm"; repo = "llvm-project"; - rev = if rev != "" then rev else "llvmorg-${version}"; - sha256 = "sha256-wjuZQyXQ/jsmvy6y1aksCcEDXGBjuhpgngF3XQJ/T4s="; + inherit rev sha256; }; + inherit (releaseInfo) release_version version; + llvm_meta = { license = with lib.licenses; [ ncsa llvm-exception ]; maintainers = lib.teams.llvm.members;