Merge pull request #296284 from ExpidusOS/feat/llvm-18

llvmPackages_18: init

authored by a-n-n-a-l-e-e and committed by GitHub 6fb20db6 95d5f0bb

+2037 -171
+1
maintainers/team-list.nix
··· 560 lovek323 561 qyliss 562 raitobezarius 563 rrbutani 564 sternenseemann 565 ];
··· 560 lovek323 561 qyliss 562 raitobezarius 563 + RossComputerGuy 564 rrbutani 565 sternenseemann 566 ];
+139
pkgs/development/compilers/llvm/18/clang/default.nix
···
··· 1 + { lib, stdenv, llvm_meta 2 + , monorepoSrc, runCommand 3 + , substituteAll, cmake, ninja, libxml2, libllvm, version, python3 4 + , buildLlvmTools 5 + , fixDarwinDylibNames 6 + , enableManpages ? false 7 + }: 8 + 9 + let 10 + self = stdenv.mkDerivation (finalAttrs: rec { 11 + pname = "clang"; 12 + inherit version; 13 + 14 + src = runCommand "${pname}-src-${version}" {} '' 15 + mkdir -p "$out" 16 + cp -r ${monorepoSrc}/cmake "$out" 17 + cp -r ${monorepoSrc}/${pname} "$out" 18 + cp -r ${monorepoSrc}/clang-tools-extra "$out" 19 + ''; 20 + 21 + sourceRoot = "${src.name}/${pname}"; 22 + 23 + nativeBuildInputs = [ cmake ninja python3 ] 24 + ++ lib.optional (lib.versionAtLeast version "18" && enableManpages) python3.pkgs.myst-parser 25 + ++ lib.optional enableManpages python3.pkgs.sphinx 26 + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; 27 + 28 + buildInputs = [ libxml2 libllvm ]; 29 + 30 + cmakeFlags = [ 31 + "-DCLANG_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/clang" 32 + "-DCLANGD_BUILD_XPC=OFF" 33 + "-DLLVM_ENABLE_RTTI=ON" 34 + "-DLLVM_INCLUDE_TESTS=OFF" 35 + ] ++ lib.optionals enableManpages [ 36 + "-DCLANG_INCLUDE_DOCS=ON" 37 + "-DLLVM_ENABLE_SPHINX=ON" 38 + "-DSPHINX_OUTPUT_MAN=ON" 39 + "-DSPHINX_OUTPUT_HTML=OFF" 40 + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" 41 + ] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ 42 + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" 43 + "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" 44 + # Added in LLVM15: 45 + # `clang-tidy-confusable-chars-gen`: https://github.com/llvm/llvm-project/commit/c3574ef739fbfcc59d405985a3a4fa6f4619ecdb 46 + # `clang-pseudo-gen`: https://github.com/llvm/llvm-project/commit/cd2292ef824591cc34cc299910a3098545c840c7 47 + "-DCLANG_TIDY_CONFUSABLE_CHARS_GEN=${buildLlvmTools.libclang.dev}/bin/clang-tidy-confusable-chars-gen" 48 + "-DCLANG_PSEUDO_GEN=${buildLlvmTools.libclang.dev}/bin/clang-pseudo-gen" 49 + ]; 50 + 51 + patches = [ 52 + ./purity.patch 53 + # https://reviews.llvm.org/D51899 54 + ./gnu-install-dirs.patch 55 + ../../common/clang/add-nostdlibinc-flag.patch 56 + (substituteAll { 57 + src = ../../common/clang/clang-at-least-16-LLVMgold-path.patch; 58 + libllvmLibdir = "${libllvm.lib}/lib"; 59 + }) 60 + ]; 61 + 62 + postPatch = '' 63 + (cd tools && ln -s ../../clang-tools-extra extra) 64 + '' + lib.optionalString stdenv.hostPlatform.isMusl '' 65 + sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp 66 + ''; 67 + 68 + outputs = [ "out" "lib" "dev" "python" ]; 69 + 70 + postInstall = '' 71 + ln -sv $out/bin/clang $out/bin/cpp 72 + 73 + # Move libclang to 'lib' output 74 + moveToOutput "lib/libclang.*" "$lib" 75 + moveToOutput "lib/libclang-cpp.*" "$lib" 76 + substituteInPlace $dev/lib/cmake/clang/ClangTargets-release.cmake \ 77 + --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \ 78 + --replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp." 79 + 80 + mkdir -p $python/bin $python/share/clang/ 81 + mv $out/bin/{git-clang-format,scan-view} $python/bin 82 + if [ -e $out/bin/set-xcode-analyzer ]; then 83 + mv $out/bin/set-xcode-analyzer $python/bin 84 + fi 85 + mv $out/share/clang/*.py $python/share/clang 86 + rm $out/bin/c-index-test 87 + patchShebangs $python/bin 88 + 89 + mkdir -p $dev/bin 90 + cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen,clang-pseudo-gen} $dev/bin 91 + ''; 92 + 93 + passthru = { 94 + inherit libllvm; 95 + isClang = true; 96 + hardeningUnsupportedFlags = [ 97 + "fortify3" 98 + ]; 99 + hardeningUnsupportedFlagsByTargetPlatform = targetPlatform: 100 + lib.optional (!(targetPlatform.isx86_64 || targetPlatform.isAarch64)) "zerocallusedregs" 101 + ++ (finalAttrs.passthru.hardeningUnsupportedFlags or []); 102 + }; 103 + 104 + meta = llvm_meta // { 105 + homepage = "https://clang.llvm.org/"; 106 + description = "A C language family frontend for LLVM"; 107 + longDescription = '' 108 + The Clang project provides a language front-end and tooling 109 + infrastructure for languages in the C language family (C, C++, Objective 110 + C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. 111 + It aims to deliver amazingly fast compiles, extremely useful error and 112 + warning messages and to provide a platform for building great source 113 + level tools. The Clang Static Analyzer and clang-tidy are tools that 114 + automatically find bugs in your code, and are great examples of the sort 115 + of tools that can be built using the Clang frontend as a library to 116 + parse C/C++ code. 117 + ''; 118 + mainProgram = "clang"; 119 + }; 120 + } // lib.optionalAttrs enableManpages { 121 + pname = "clang-manpages"; 122 + 123 + ninjaFlags = [ "docs-clang-man" ]; 124 + 125 + installPhase = '' 126 + mkdir -p $out/share/man/man1 127 + # Manually install clang manpage 128 + cp docs/man/*.1 $out/share/man/man1/ 129 + ''; 130 + 131 + outputs = [ "out" ]; 132 + 133 + doCheck = false; 134 + 135 + meta = llvm_meta // { 136 + description = "man page for Clang ${version}"; 137 + }; 138 + }); 139 + in self
+71
pkgs/development/compilers/llvm/18/clang/gnu-install-dirs.patch
···
··· 1 + diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake 2 + index 75b0080f6715..c895b884cd27 100644 3 + --- a/cmake/modules/AddClang.cmake 4 + +++ b/cmake/modules/AddClang.cmake 5 + @@ -119,8 +119,8 @@ macro(add_clang_library name) 6 + install(TARGETS ${lib} 7 + COMPONENT ${lib} 8 + ${export_to_clangtargets} 9 + - LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} 10 + - ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} 11 + + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" 12 + + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" 13 + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") 14 + 15 + if (NOT LLVM_ENABLE_IDE) 16 + diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt 17 + index f2b0c5cddcbb..52f37fc368ce 100644 18 + --- a/lib/Headers/CMakeLists.txt 19 + +++ b/lib/Headers/CMakeLists.txt 20 + @@ -473,6 +473,7 @@ add_header_target("windows-resource-headers" ${windows_only_files}) 21 + add_header_target("utility-resource-headers" ${utility_files}) 22 + 23 + get_clang_resource_dir(header_install_dir SUBDIR include) 24 + +set(header_install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION_MAJOR}/include) 25 + 26 + ############################################################# 27 + # Install rules for the catch-all clang-resource-headers target 28 + diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt 29 + index 4f23065a2472..6a0f55991e24 100644 30 + --- a/tools/libclang/CMakeLists.txt 31 + +++ b/tools/libclang/CMakeLists.txt 32 + @@ -234,7 +234,7 @@ foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS}) 33 + COMPONENT 34 + libclang-python-bindings 35 + DESTINATION 36 + - "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") 37 + + "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") 38 + endforeach() 39 + if(NOT LLVM_ENABLE_IDE) 40 + add_custom_target(libclang-python-bindings) 41 + diff --git a/tools/scan-build-py/CMakeLists.txt b/tools/scan-build-py/CMakeLists.txt 42 + index 3aca22c0b0a8..3115353e3fe3 100644 43 + --- a/tools/scan-build-py/CMakeLists.txt 44 + +++ b/tools/scan-build-py/CMakeLists.txt 45 + @@ -88,7 +88,7 @@ foreach(lib ${LibScanbuild}) 46 + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libscanbuild/${lib}) 47 + list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libscanbuild/${lib}) 48 + install(FILES lib/libscanbuild/${lib} 49 + - DESTINATION lib${CLANG_LIBDIR_SUFFIX}/libscanbuild 50 + + DESTINATION "${CMAKE_INSTALL_LIBDIR}/libscanbuild" 51 + COMPONENT scan-build-py) 52 + endforeach() 53 + 54 + @@ -106,7 +106,7 @@ foreach(resource ${LibScanbuildResources}) 55 + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libscanbuild/resources/${resource}) 56 + list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libscanbuild/resources/${resource}) 57 + install(FILES lib/libscanbuild/resources/${resource} 58 + - DESTINATION lib${CLANG_LIBDIR_SUFFIX}/libscanbuild/resources 59 + + DESTINATION "${CMAKE_INSTALL_LIBDIR}/libscanbuild/resources" 60 + COMPONENT scan-build-py) 61 + endforeach() 62 + 63 + @@ -122,7 +122,7 @@ foreach(lib ${LibEar}) 64 + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libear/${lib}) 65 + list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libear/${lib}) 66 + install(FILES lib/libear/${lib} 67 + - DESTINATION lib${CLANG_LIBDIR_SUFFIX}/libear 68 + + DESTINATION "${CMAKE_INSTALL_LIBDIR}/libear" 69 + COMPONENT scan-build-py) 70 + endforeach() 71 +
+25
pkgs/development/compilers/llvm/18/clang/purity.patch
···
··· 1 + From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001 2 + From: Will Dietz <w@wdtz.org> 3 + Date: Thu, 18 May 2017 11:56:12 -0500 4 + Subject: [PATCH] "purity" patch for 5.0 5 + 6 + --- 7 + lib/Driver/ToolChains/Gnu.cpp | 3 --- 8 + 1 file changed, 3 deletions(-) 9 + 10 + diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp 11 + index fe3c0191bb..c6a482bece 100644 12 + --- a/lib/Driver/ToolChains/Gnu.cpp 13 + +++ b/lib/Driver/ToolChains/Gnu.cpp 14 + @@ -446,9 +446,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, 15 + ToolChain.isPIEDefault(Args)); 16 + if (IsPIE) 17 + CmdArgs.push_back("-pie"); 18 + - CmdArgs.push_back("-dynamic-linker"); 19 + - CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) + 20 + - ToolChain.getDynamicLinker(Args))); 21 + } 22 + } 23 + 24 + -- 25 + 2.11.0
+21
pkgs/development/compilers/llvm/18/compiler-rt/X86-support-extension.patch
···
··· 1 + diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt 2 + index 3a66dd9c3fb..7efc85d9f9f 100644 3 + --- a/lib/builtins/CMakeLists.txt 4 + +++ b/lib/builtins/CMakeLists.txt 5 + @@ -348,4 +348,8 @@ if (NOT MSVC) 6 + 7 + + set(i486_SOURCES ${i386_SOURCES}) 8 + + set(i586_SOURCES ${i386_SOURCES}) 9 + + set(i686_SOURCES ${i386_SOURCES}) 10 + + 11 + if (WIN32) 12 + set(i386_SOURCES 13 + ${i386_SOURCES} 14 + @@ -723,6 +723,7 @@ else () 15 + endif() 16 + 17 + foreach (arch ${BUILTIN_SUPPORTED_ARCH}) 18 + + message("arch: ${arch}") 19 + if (CAN_TARGET_${arch}) 20 + # For ARM archs, exclude any VFP builtins if VFP is not supported 21 + if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$")
+71
pkgs/development/compilers/llvm/18/compiler-rt/darwin-targetconditionals.patch
···
··· 1 + diff --git a/lib/sanitizer_common/sanitizer_mac.cpp b/lib/sanitizer_common/sanitizer_mac.cpp 2 + --- a/lib/sanitizer_common/sanitizer_mac.cpp 3 + +++ b/lib/sanitizer_common/sanitizer_mac.cpp 4 + @@ -613,9 +613,15 @@ HandleSignalMode GetHandleSignalMode(int signum) { 5 + // Offset example: 6 + // XNU 17 -- macOS 10.13 -- iOS 11 -- tvOS 11 -- watchOS 4 7 + constexpr u16 GetOSMajorKernelOffset() { 8 + - if (TARGET_OS_OSX) return 4; 9 + - if (TARGET_OS_IOS || TARGET_OS_TV) return 6; 10 + - if (TARGET_OS_WATCH) return 13; 11 + +#if TARGET_OS_OSX 12 + + return 4; 13 + +#endif 14 + +#if TARGET_OS_IOS || TARGET_OS_TV 15 + + return 6; 16 + +#endif 17 + +#if TARGET_OS_WATCH 18 + + return 13; 19 + +#endif 20 + } 21 + 22 + using VersStr = char[64]; 23 + @@ -627,13 +633,13 @@ static uptr ApproximateOSVersionViaKernelVersion(VersStr vers) { 24 + u16 os_major = kernel_major - offset; 25 + 26 + const char *format = "%d.0"; 27 + - if (TARGET_OS_OSX) { 28 + - if (os_major >= 16) { // macOS 11+ 29 + - os_major -= 5; 30 + - } else { // macOS 10.15 and below 31 + - format = "10.%d"; 32 + - } 33 + +#if TARGET_OS_OSX 34 + + if (os_major >= 16) { // macOS 11+ 35 + + os_major -= 5; 36 + + } else { // macOS 10.15 and below 37 + + format = "10.%d"; 38 + } 39 + +#endif 40 + return internal_snprintf(vers, sizeof(VersStr), format, os_major); 41 + } 42 + 43 + @@ -681,15 +687,14 @@ void ParseVersion(const char *vers, u16 *major, u16 *minor) { 44 + // Aligned versions example: 45 + // macOS 10.15 -- iOS 13 -- tvOS 13 -- watchOS 6 46 + static void MapToMacos(u16 *major, u16 *minor) { 47 + - if (TARGET_OS_OSX) 48 + - return; 49 + - 50 + - if (TARGET_OS_IOS || TARGET_OS_TV) 51 + +#if !TARGET_OS_OSX 52 + +#if TARGET_OS_IOS || TARGET_OS_TV 53 + *major += 2; 54 + - else if (TARGET_OS_WATCH) 55 + +#elif TARGET_OS_WATCH 56 + *major += 9; 57 + - else 58 + +#else 59 + UNREACHABLE("unsupported platform"); 60 + +#endif 61 + 62 + if (*major >= 16) { // macOS 11+ 63 + *major -= 5; 64 + @@ -697,6 +702,7 @@ static void MapToMacos(u16 *major, u16 *minor) { 65 + *minor = *major; 66 + *major = 10; 67 + } 68 + +#endif 69 + } 70 + 71 + static MacosVersion GetMacosAlignedVersionInternal() {
+157
pkgs/development/compilers/llvm/18/compiler-rt/default.nix
···
··· 1 + { lib, stdenv, llvm_meta, version 2 + , monorepoSrc, runCommand 3 + , cmake, ninja, python3, xcbuild, libllvm, linuxHeaders, libxcrypt 4 + , doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD 5 + }: 6 + 7 + let 8 + 9 + useLLVM = stdenv.hostPlatform.useLLVM or false; 10 + bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; 11 + haveLibc = stdenv.cc.libc != null; 12 + isDarwinStatic = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic; 13 + inherit (stdenv.hostPlatform) isMusl; 14 + 15 + baseName = "compiler-rt"; 16 + 17 + src = runCommand "${baseName}-src-${version}" {} '' 18 + mkdir -p "$out" 19 + cp -r ${monorepoSrc}/cmake "$out" 20 + cp -r ${monorepoSrc}/${baseName} "$out" 21 + ''; 22 + in 23 + 24 + stdenv.mkDerivation { 25 + pname = baseName + lib.optionalString (haveLibc) "-libc"; 26 + inherit version; 27 + 28 + inherit src; 29 + sourceRoot = "${src.name}/${baseName}"; 30 + 31 + nativeBuildInputs = [ cmake ninja python3 libllvm.dev ] 32 + ++ lib.optional stdenv.isDarwin xcbuild.xcrun; 33 + buildInputs = 34 + lib.optional (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isRiscV) linuxHeaders; 35 + 36 + env.NIX_CFLAGS_COMPILE = toString ([ 37 + "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" 38 + ] ++ lib.optionals (!haveLibc) [ 39 + # The compiler got stricter about this, and there is a usellvm patch below 40 + # which patches out the assert include causing an implicit definition of 41 + # assert. It would be nicer to understand why compiler-rt thinks it should 42 + # be able to #include <assert.h> in the first place; perhaps it's in the 43 + # wrong, or perhaps there is a way to provide an assert.h. 44 + "-Wno-error=implicit-function-declaration" 45 + ]); 46 + 47 + cmakeFlags = [ 48 + "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" 49 + "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" 50 + "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" 51 + ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [ 52 + "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" 53 + ] ++ lib.optionals (useLLVM || bareMetal || isMusl || isDarwinStatic) [ 54 + "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" 55 + "-DCOMPILER_RT_BUILD_XRAY=OFF" 56 + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" 57 + "-DCOMPILER_RT_BUILD_MEMPROF=OFF" 58 + "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary 59 + ] ++ lib.optionals (useLLVM || bareMetal) [ 60 + "-DCOMPILER_RT_BUILD_PROFILE=OFF" 61 + ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal || isDarwinStatic ) [ 62 + "-DCMAKE_CXX_COMPILER_WORKS=ON" 63 + ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ 64 + "-DCMAKE_C_COMPILER_WORKS=ON" 65 + "-DCOMPILER_RT_BAREMETAL_BUILD=ON" 66 + "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" 67 + ] ++ lib.optionals (useLLVM && !haveLibc) [ 68 + "-DCMAKE_C_FLAGS=-nodefaultlibs" 69 + ] ++ lib.optionals (useLLVM) [ 70 + "-DCOMPILER_RT_BUILD_BUILTINS=ON" 71 + #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program 72 + "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" 73 + ] ++ lib.optionals (bareMetal) [ 74 + "-DCOMPILER_RT_OS_DIR=baremetal" 75 + ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ 76 + "-DCMAKE_LIPO=${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}lipo" 77 + "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" 78 + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" 79 + "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" 80 + 81 + # `COMPILER_RT_DEFAULT_TARGET_ONLY` does not apply to Darwin: 82 + # https://github.com/llvm/llvm-project/blob/27ef42bec80b6c010b7b3729ed0528619521a690/compiler-rt/cmake/base-config-ix.cmake#L153 83 + "-DCOMPILER_RT_ENABLE_IOS=OFF" 84 + ]; 85 + 86 + outputs = [ "out" "dev" ]; 87 + 88 + patches = [ 89 + ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config 90 + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the 91 + # extra `/`. 92 + ./normalize-var.patch 93 + # See: https://github.com/NixOS/nixpkgs/pull/186575 94 + ../../common/compiler-rt/darwin-plistbuddy-workaround.patch 95 + # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 96 + # ../../common/compiler-rt/armv7l-15.patch 97 + ]; 98 + 99 + # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks 100 + # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra 101 + # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd 102 + # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by 103 + # a flag and turn the flag off during the stdenv build. 104 + postPatch = lib.optionalString (!stdenv.isDarwin) '' 105 + substituteInPlace cmake/builtin-config-ix.cmake \ 106 + --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' 107 + '' + lib.optionalString stdenv.isDarwin '' 108 + substituteInPlace cmake/config-ix.cmake \ 109 + --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' 110 + '' + lib.optionalString (useLLVM && !haveLibc) '' 111 + substituteInPlace lib/builtins/aarch64/sme-libc-routines.c \ 112 + --replace "<stdlib.h>" "<stddef.h>" 113 + substituteInPlace lib/builtins/int_util.c \ 114 + --replace "#include <stdlib.h>" "" 115 + substituteInPlace lib/builtins/clear_cache.c \ 116 + --replace "#include <assert.h>" "" 117 + substituteInPlace lib/builtins/cpu_model${lib.optionalString (lib.versionAtLeast version "18") "/x86"}.c \ 118 + --replace "#include <assert.h>" "" 119 + ''; 120 + 121 + # Hack around weird upsream RPATH bug 122 + postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin) '' 123 + ln -s "$out/lib"/*/* "$out/lib" 124 + '' + lib.optionalString (useLLVM && stdenv.hostPlatform.isLinux) '' 125 + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o 126 + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o 127 + # Note the history of crt{begin,end}S in previous versions of llvm in nixpkg: 128 + # The presence of crtbegin_shared has been added and removed; it's possible 129 + # people have added/removed it to get it working on their platforms. 130 + # Try each in turn for now. 131 + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbeginS.o 132 + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtendS.o 133 + ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o 134 + ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o 135 + '' + lib.optionalString doFakeLibgcc '' 136 + ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a 137 + ''; 138 + 139 + meta = llvm_meta // { 140 + homepage = "https://compiler-rt.llvm.org/"; 141 + description = "Compiler runtime libraries"; 142 + longDescription = '' 143 + The compiler-rt project provides highly tuned implementations of the 144 + low-level code generator support routines like "__fixunsdfdi" and other 145 + calls generated when a target doesn't have a short sequence of native 146 + instructions to implement a core IR operation. It also provides 147 + implementations of run-time libraries for dynamic testing tools such as 148 + AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. 149 + ''; 150 + # "All of the code in the compiler-rt project is dual licensed under the MIT 151 + # license and the UIUC License (a BSD-like license)": 152 + license = with lib.licenses; [ mit ncsa ]; 153 + # compiler-rt requires a Clang stdenv on 32-bit RISC-V: 154 + # https://reviews.llvm.org/D43106#1019077 155 + broken = stdenv.hostPlatform.isRiscV32 && !stdenv.cc.isClang; 156 + }; 157 + }
+16
pkgs/development/compilers/llvm/18/compiler-rt/normalize-var.patch
···
··· 1 + diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake 2 + index 4c85551d7766..297d7a47c54b 100644 3 + --- a/cmake/Modules/CompilerRTUtils.cmake 4 + +++ b/cmake/Modules/CompilerRTUtils.cmake 5 + @@ -328,8 +328,9 @@ macro(load_llvm_config) 6 + endif() 7 + endif() 8 + 9 + - set(LLVM_LIBRARY_OUTPUT_INTDIR 10 + - ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) 11 + + get_filename_component(LLVM_LIBRARY_OUTPUT_INTDIR 12 + + ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX} 13 + + REALPATH) 14 + 15 + set(LLVM_MAIN_SRC_DIR "${LLVM_MAIN_SRC_DIR_DEFAULT}" CACHE PATH "Path to LLVM source tree") 16 + message(STATUS "LLVM_MAIN_SRC_DIR: \"${LLVM_MAIN_SRC_DIR}\"")
+329
pkgs/development/compilers/llvm/18/default.nix
···
··· 1 + { lowPrio, newScope, pkgs, lib, stdenv, cmake, ninja 2 + , preLibcCrossHeaders 3 + , libxml2, python3, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith 4 + , buildLlvmTools # tools, but from the previous stage, for cross 5 + , targetLlvmLibraries # libraries, but from the next stage, for cross 6 + , targetLlvm 7 + # This is the default binutils, but with *this* version of LLD rather 8 + # than the default LLVM verion's, if LLD is the choice. We use these for 9 + # the `useLLVM` bootstrapping below. 10 + , bootBintoolsNoLibc ? 11 + if stdenv.targetPlatform.linker == "lld" 12 + then null 13 + else pkgs.bintoolsNoLibc 14 + , bootBintools ? 15 + if stdenv.targetPlatform.linker == "lld" 16 + then null 17 + else pkgs.bintools 18 + , darwin 19 + # LLVM release information; specify one of these but not both: 20 + , gitRelease ? null 21 + # i.e.: 22 + # { 23 + # version = /* i.e. "15.0.0" */; 24 + # rev = /* commit SHA */; 25 + # rev-version = /* human readable version; i.e. "unstable-2022-26-07" */; 26 + # sha256 = /* checksum for this release, can omit if specifying your own `monorepoSrc` */; 27 + # } 28 + , officialRelease ? { version = "18.1.1"; sha256 = "sha256-qAPNvEpztJjPz+kr5KcZz4iUTErsD8iXLURKl3yZoC8="; } 29 + # i.e.: 30 + # { 31 + # version = /* i.e. "15.0.0" */; 32 + # candidate = /* optional; if specified, should be: "rcN" */ 33 + # sha256 = /* checksum for this release, can omit if specifying your own `monorepoSrc` */; 34 + # } 35 + # By default, we'll try to fetch a release from `github:llvm/llvm-project` 36 + # corresponding to the `gitRelease` or `officialRelease` specified. 37 + # 38 + # You can provide your own LLVM source by specifying this arg but then it's up 39 + # to you to make sure that the LLVM repo given matches the release configuration 40 + # specified. 41 + , monorepoSrc ? null 42 + }: 43 + 44 + assert let 45 + int = a: if a then 1 else 0; 46 + xor = a: b: ((builtins.bitXor (int a) (int b)) == 1); 47 + in 48 + lib.assertMsg 49 + (xor 50 + (gitRelease != null) 51 + (officialRelease != null)) 52 + ("must specify `gitRelease` or `officialRelease`" + 53 + (lib.optionalString (gitRelease != null) " — not both")); 54 + let 55 + monorepoSrc' = monorepoSrc; 56 + in let 57 + inherit (import ../common/common-let.nix { inherit lib gitRelease officialRelease; }) releaseInfo; 58 + 59 + inherit (releaseInfo) release_version version; 60 + 61 + inherit (import ../common/common-let.nix { inherit lib fetchFromGitHub release_version gitRelease officialRelease monorepoSrc'; }) llvm_meta monorepoSrc; 62 + 63 + tools = lib.makeExtensible (tools: let 64 + callPackage = newScope (tools // { inherit stdenv cmake ninja libxml2 python3 release_version version monorepoSrc buildLlvmTools; }); 65 + major = lib.versions.major release_version; 66 + mkExtraBuildCommands0 = cc: '' 67 + rsrc="$out/resource-root" 68 + mkdir "$rsrc" 69 + ln -s "${cc.lib}/lib/clang/${major}/include" "$rsrc" 70 + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags 71 + ''; 72 + mkExtraBuildCommands = cc: mkExtraBuildCommands0 cc + '' 73 + ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" 74 + ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share" 75 + ''; 76 + 77 + bintoolsNoLibc' = 78 + if bootBintoolsNoLibc == null 79 + then tools.bintoolsNoLibc 80 + else bootBintoolsNoLibc; 81 + bintools' = 82 + if bootBintools == null 83 + then tools.bintools 84 + else bootBintools; 85 + 86 + in { 87 + 88 + libllvm = callPackage ./llvm { 89 + inherit llvm_meta; 90 + }; 91 + 92 + # `llvm` historically had the binaries. When choosing an output explicitly, 93 + # we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get* 94 + llvm = tools.libllvm; 95 + 96 + libclang = callPackage ./clang { 97 + inherit llvm_meta; 98 + }; 99 + 100 + clang-unwrapped = tools.libclang; 101 + 102 + llvm-manpages = lowPrio (tools.libllvm.override { 103 + enableManpages = true; 104 + python3 = pkgs.python3; # don't use python-boot 105 + }); 106 + 107 + clang-manpages = lowPrio (tools.libclang.override { 108 + enableManpages = true; 109 + python3 = pkgs.python3; # don't use python-boot 110 + }); 111 + 112 + lldb-manpages = lowPrio (tools.lldb.override { 113 + enableManpages = true; 114 + python3 = pkgs.python3; # don't use python-boot 115 + }); 116 + 117 + # pick clang appropriate for package set we are targeting 118 + clang = 119 + /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM 120 + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang 121 + else tools.libcxxClang; 122 + 123 + libstdcxxClang = wrapCCWith rec { 124 + cc = tools.clang-unwrapped; 125 + # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper. 126 + libcxx = null; 127 + extraPackages = [ 128 + targetLlvmLibraries.compiler-rt 129 + ]; 130 + extraBuildCommands = mkExtraBuildCommands cc; 131 + }; 132 + 133 + libcxxClang = wrapCCWith rec { 134 + cc = tools.clang-unwrapped; 135 + libcxx = targetLlvmLibraries.libcxx; 136 + extraPackages = [ 137 + targetLlvmLibraries.compiler-rt 138 + ]; 139 + extraBuildCommands = mkExtraBuildCommands cc; 140 + }; 141 + 142 + lld = callPackage ./lld { 143 + inherit llvm_meta; 144 + }; 145 + 146 + mlir = callPackage ../common/mlir { 147 + inherit llvm_meta; 148 + }; 149 + 150 + lldb = callPackage ../common/lldb.nix { 151 + src = callPackage ({ runCommand }: runCommand "lldb-src-${version}" {} '' 152 + mkdir -p "$out" 153 + cp -r ${monorepoSrc}/cmake "$out" 154 + cp -r ${monorepoSrc}/lldb "$out" 155 + '') { }; 156 + patches = 157 + [ 158 + # FIXME: do we need this? ./procfs.patch 159 + ../common/lldb/gnu-install-dirs.patch 160 + ] 161 + # This is a stopgap solution if/until the macOS SDK used for x86_64 is 162 + # updated. 163 + # 164 + # The older 10.12 SDK used on x86_64 as of this writing has a `mach/machine.h` 165 + # header that does not define `CPU_SUBTYPE_ARM64E` so we replace the one use 166 + # of this preprocessor symbol in `lldb` with its expansion. 167 + # 168 + # See here for some context: 169 + # https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272129132 170 + ++ lib.optional ( 171 + stdenv.targetPlatform.isDarwin 172 + && !stdenv.targetPlatform.isAarch64 173 + && (lib.versionOlder darwin.apple_sdk.sdk.version "11.0") 174 + ) ./lldb/cpu_subtype_arm64e_replacement.patch; 175 + inherit llvm_meta; 176 + }; 177 + 178 + # Below, is the LLVM bootstrapping logic. It handles building a 179 + # fully LLVM toolchain from scratch. No GCC toolchain should be 180 + # pulled in. As a consequence, it is very quick to build different 181 + # targets provided by LLVM and we can also build for what GCC 182 + # doesn’t support like LLVM. Probably we should move to some other 183 + # file. 184 + 185 + bintools-unwrapped = callPackage ../common/bintools.nix { }; 186 + 187 + bintoolsNoLibc = wrapBintoolsWith { 188 + bintools = tools.bintools-unwrapped; 189 + libc = preLibcCrossHeaders; 190 + }; 191 + 192 + bintools = wrapBintoolsWith { 193 + bintools = tools.bintools-unwrapped; 194 + }; 195 + 196 + clangUseLLVM = wrapCCWith rec { 197 + cc = tools.clang-unwrapped; 198 + libcxx = targetLlvmLibraries.libcxx; 199 + bintools = bintools'; 200 + extraPackages = [ 201 + targetLlvmLibraries.compiler-rt 202 + ] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [ 203 + targetLlvmLibraries.libunwind 204 + ]; 205 + extraBuildCommands = mkExtraBuildCommands cc; 206 + nixSupport.cc-cflags = 207 + [ "-rtlib=compiler-rt" 208 + "-Wno-unused-command-line-argument" 209 + "-B${targetLlvmLibraries.compiler-rt}/lib" 210 + ] 211 + ++ lib.optional (!stdenv.targetPlatform.isWasm) "--unwindlib=libunwind" 212 + ++ lib.optional 213 + (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) 214 + "-lunwind" 215 + ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; 216 + nixSupport.cc-ldflags = lib.optionals (!stdenv.targetPlatform.isWasm) [ "-L${targetLlvmLibraries.libunwind}/lib" ]; 217 + }; 218 + 219 + clangNoLibcxx = wrapCCWith rec { 220 + cc = tools.clang-unwrapped; 221 + libcxx = null; 222 + bintools = bintools'; 223 + extraPackages = [ 224 + targetLlvmLibraries.compiler-rt 225 + ]; 226 + extraBuildCommands = mkExtraBuildCommands cc; 227 + nixSupport.cc-cflags = 228 + [ 229 + "-rtlib=compiler-rt" 230 + "-B${targetLlvmLibraries.compiler-rt}/lib" 231 + "-nostdlib++" 232 + ] 233 + ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; 234 + }; 235 + 236 + clangNoLibc = wrapCCWith rec { 237 + cc = tools.clang-unwrapped; 238 + libcxx = null; 239 + bintools = bintoolsNoLibc'; 240 + extraPackages = [ 241 + targetLlvmLibraries.compiler-rt 242 + ]; 243 + extraBuildCommands = mkExtraBuildCommands cc; 244 + nixSupport.cc-cflags = 245 + [ 246 + "-rtlib=compiler-rt" 247 + "-B${targetLlvmLibraries.compiler-rt}/lib" 248 + ] 249 + ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; 250 + }; 251 + 252 + clangNoCompilerRt = wrapCCWith rec { 253 + cc = tools.clang-unwrapped; 254 + libcxx = null; 255 + bintools = bintoolsNoLibc'; 256 + extraPackages = [ ]; 257 + extraBuildCommands = mkExtraBuildCommands0 cc; 258 + nixSupport.cc-cflags = 259 + [ 260 + "-nostartfiles" 261 + ] 262 + ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; 263 + }; 264 + 265 + clangNoCompilerRtWithLibc = wrapCCWith (rec { 266 + cc = tools.clang-unwrapped; 267 + libcxx = null; 268 + bintools = bintools'; 269 + extraPackages = [ ]; 270 + extraBuildCommands = mkExtraBuildCommands0 cc; 271 + } // lib.optionalAttrs stdenv.targetPlatform.isWasm { 272 + nixSupport.cc-cflags = [ "-fno-exceptions" ]; 273 + }); 274 + 275 + # Has to be in tools despite mostly being a library, 276 + # because we use a native helper executable from a 277 + # non-cross build in cross builds. 278 + libclc = callPackage ../common/libclc.nix { 279 + inherit buildLlvmTools; 280 + }; 281 + }); 282 + 283 + libraries = lib.makeExtensible (libraries: let 284 + callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake ninja libxml2 python3 release_version version monorepoSrc; }); 285 + in { 286 + 287 + compiler-rt-libc = callPackage ./compiler-rt { 288 + inherit llvm_meta; 289 + stdenv = if stdenv.hostPlatform.useLLVM or false || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic) 290 + then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc 291 + else stdenv; 292 + }; 293 + 294 + compiler-rt-no-libc = callPackage ./compiler-rt { 295 + inherit llvm_meta; 296 + stdenv = if stdenv.hostPlatform.useLLVM or false 297 + then overrideCC stdenv buildLlvmTools.clangNoCompilerRt 298 + else stdenv; 299 + }; 300 + 301 + # N.B. condition is safe because without useLLVM both are the same. 302 + compiler-rt = if stdenv.hostPlatform.isAndroid || stdenv.hostPlatform.isDarwin 303 + then libraries.compiler-rt-libc 304 + else libraries.compiler-rt-no-libc; 305 + 306 + stdenv = overrideCC stdenv buildLlvmTools.clang; 307 + 308 + libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; 309 + 310 + # `libcxx` requires a fairly modern C++ compiler, 311 + # so: we use the clang from this LLVM package set instead of the regular 312 + # stdenv's compiler. 313 + libcxx = callPackage ./libcxx { 314 + inherit llvm_meta; 315 + stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; 316 + }; 317 + 318 + libunwind = callPackage ./libunwind { 319 + inherit llvm_meta; 320 + stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; 321 + }; 322 + 323 + openmp = callPackage ./openmp { 324 + inherit llvm_meta targetLlvm; 325 + }; 326 + }); 327 + noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ]; 328 + 329 + in { inherit tools libraries release_version; } // (noExtend libraries) // (noExtend tools)
+31
pkgs/development/compilers/llvm/18/libcxx/0001-darwin-10.12-mbstate_t-fix.patch
···
··· 1 + From 9c1cb26c1dd3f92d1c1177e548107d2cd3c5e616 Mon Sep 17 00:00:00 2001 2 + From: annalee <150648636+a-n-n-a-l-e-e@users.noreply.github.com> 3 + Date: Fri, 23 Feb 2024 22:58:58 +0000 4 + Subject: [PATCH] darwin 10.12 mbstate_t fix 5 + 6 + https://github.com/llvm/llvm-project/issues/64226 7 + 8 + removes space from 9 + https://github.com/macports/macports-ports/raw/acd8acb171f1658596ed1cf25da48d5b932e2d19/lang/llvm-17/files/0042-mbstate_t-not-defined.patch 10 + so it applies cleanly 11 + --- 12 + libcxx/include/__mbstate_t.h | 3 +++ 13 + 1 file changed, 3 insertions(+) 14 + 15 + diff --git a/libcxx/include/__mbstate_t.h b/libcxx/include/__mbstate_t.h 16 + index bfa6d61..5f51112 100644 17 + --- a/libcxx/include/__mbstate_t.h 18 + +++ b/libcxx/include/__mbstate_t.h 19 + @@ -42,6 +42,9 @@ 20 + #elif __has_include(<bits/types/mbstate_t.h>) 21 + # include <bits/types/mbstate_t.h> // works on most Unixes 22 + #elif __has_include(<sys/_types/_mbstate_t.h>) 23 + +# if __has_include(<machine/_types.h>) 24 + +# include <machine/_types.h> 25 + +# endif 26 + # include <sys/_types/_mbstate_t.h> // works on Darwin 27 + #elif !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) && __has_include_next(<wchar.h>) 28 + # include_next <wchar.h> // fall back to the C standard provider of mbstate_t 29 + -- 30 + 2.43.0 31 +
+130
pkgs/development/compilers/llvm/18/libcxx/default.nix
···
··· 1 + { lib, stdenv, llvm_meta 2 + , monorepoSrc, runCommand 3 + , cmake, lndir, ninja, python3, fixDarwinDylibNames, version 4 + , cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else null 5 + , libcxxrt, libunwind 6 + , enableShared ? !stdenv.hostPlatform.isStatic 7 + }: 8 + 9 + # external cxxabi is not supported on Darwin as the build will not link libcxx 10 + # properly and not re-export the cxxabi symbols into libcxx 11 + # https://github.com/NixOS/nixpkgs/issues/166205 12 + # https://github.com/NixOS/nixpkgs/issues/269548 13 + assert cxxabi == null || !stdenv.hostPlatform.isDarwin; 14 + let 15 + basename = "libcxx"; 16 + cxxabiName = "lib${if cxxabi == null then "cxxabi" else cxxabi.libName}"; 17 + runtimes = [ "libcxx" ] ++ lib.optional (cxxabi == null) "libcxxabi"; 18 + 19 + # Note: useLLVM is likely false for Darwin but true under pkgsLLVM 20 + useLLVM = stdenv.hostPlatform.useLLVM or false; 21 + 22 + cxxabiCMakeFlags = [ 23 + "-DLIBCXXABI_USE_LLVM_UNWINDER=OFF" 24 + ] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ 25 + "-DLIBCXXABI_ADDITIONAL_LIBRARIES=unwind" 26 + "-DLIBCXXABI_USE_COMPILER_RT=ON" 27 + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ 28 + "-DLIBCXXABI_ENABLE_THREADS=OFF" 29 + "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" 30 + ] ++ lib.optionals (!enableShared) [ 31 + "-DLIBCXXABI_ENABLE_SHARED=OFF" 32 + ]; 33 + 34 + cxxCMakeFlags = [ 35 + "-DLIBCXX_CXX_ABI=${cxxabiName}" 36 + ] ++ lib.optionals (cxxabi != null) [ 37 + "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${lib.getDev cxxabi}/include" 38 + ] ++ lib.optionals (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [ 39 + "-DLIBCXX_HAS_MUSL_LIBC=1" 40 + ] ++ lib.optionals (lib.versionAtLeast version "18" && !useLLVM && stdenv.hostPlatform.libc == "glibc" && !stdenv.hostPlatform.isStatic) [ 41 + "-DLIBCXX_ADDITIONAL_LIBRARIES=gcc_s" 42 + ] ++ lib.optionals useLLVM [ 43 + "-DLIBCXX_USE_COMPILER_RT=ON" 44 + # There's precedent for this in llvm-project/libcxx/cmake/caches. 45 + # In a monorepo build you might do the following in the libcxxabi build: 46 + # -DLLVM_ENABLE_PROJECTS=libcxxabi;libunwinder 47 + # -DLIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY=On 48 + # libcxx appears to require unwind and doesn't pull it in via other means. 49 + "-DLIBCXX_ADDITIONAL_LIBRARIES=unwind" 50 + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ 51 + "-DLIBCXX_ENABLE_THREADS=OFF" 52 + "-DLIBCXX_ENABLE_FILESYSTEM=OFF" 53 + "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" 54 + ] ++ lib.optionals (!enableShared) [ 55 + "-DLIBCXX_ENABLE_SHARED=OFF" 56 + ]; 57 + 58 + cmakeFlags = [ 59 + "-DLLVM_ENABLE_RUNTIMES=${lib.concatStringsSep ";" runtimes}" 60 + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ 61 + "-DCMAKE_C_COMPILER_WORKS=ON" 62 + "-DCMAKE_CXX_COMPILER_WORKS=ON" 63 + "-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker 64 + ] ++ cxxCMakeFlags 65 + ++ lib.optionals (cxxabi == null) cxxabiCMakeFlags; 66 + 67 + in 68 + 69 + stdenv.mkDerivation rec { 70 + pname = basename; 71 + inherit version cmakeFlags; 72 + 73 + src = runCommand "${pname}-src-${version}" {} ('' 74 + mkdir -p "$out/llvm" 75 + cp -r ${monorepoSrc}/cmake "$out" 76 + cp -r ${monorepoSrc}/libcxx "$out" 77 + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" 78 + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" 79 + cp -r ${monorepoSrc}/third-party "$out" 80 + cp -r ${monorepoSrc}/runtimes "$out" 81 + '' + lib.optionalString (cxxabi == null) '' 82 + cp -r ${monorepoSrc}/libcxxabi "$out" 83 + ''); 84 + 85 + outputs = [ "out" "dev" ]; 86 + 87 + patches = lib.optionals (stdenv.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13") [ 88 + # https://github.com/llvm/llvm-project/issues/64226 89 + ./0001-darwin-10.12-mbstate_t-fix.patch 90 + ]; 91 + 92 + postPatch = '' 93 + cd runtimes 94 + ''; 95 + 96 + preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' 97 + patchShebangs utils/cat_files.py 98 + ''; 99 + 100 + nativeBuildInputs = [ cmake ninja python3 ] 101 + ++ lib.optional stdenv.isDarwin fixDarwinDylibNames 102 + ++ lib.optional (cxxabi != null) lndir; 103 + 104 + buildInputs = [ cxxabi ] 105 + ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ libunwind ]; 106 + 107 + # libc++.so is a linker script which expands to multiple libraries, 108 + # libc++.so.1 and libc++abi.so or the external cxxabi. ld-wrapper doesn't 109 + # support linker scripts so the external cxxabi needs to be symlinked in 110 + postInstall = lib.optionalString (cxxabi != null) '' 111 + lndir ${lib.getDev cxxabi}/include ''${!outputDev}/include/c++/v1 112 + lndir ${lib.getLib cxxabi}/lib ''${!outputLib}/lib 113 + ''; 114 + 115 + passthru = { 116 + isLLVM = true; 117 + }; 118 + 119 + meta = llvm_meta // { 120 + homepage = "https://libcxx.llvm.org/"; 121 + description = "C++ standard library"; 122 + longDescription = '' 123 + libc++ is an implementation of the C++ standard library, targeting C++11, 124 + C++14 and above. 125 + ''; 126 + # "All of the code in libc++ is dual licensed under the MIT license and the 127 + # UIUC License (a BSD-like license)": 128 + license = with lib.licenses; [ mit ncsa ]; 129 + }; 130 + }
+54
pkgs/development/compilers/llvm/18/libunwind/default.nix
···
··· 1 + { lib, stdenv, llvm_meta, version 2 + , monorepoSrc, runCommand 3 + , cmake 4 + , ninja 5 + , python3 6 + , enableShared ? !stdenv.hostPlatform.isStatic 7 + }: 8 + 9 + stdenv.mkDerivation rec { 10 + pname = "libunwind"; 11 + inherit version; 12 + 13 + # I am not so comfortable giving libc++ and friends the whole monorepo as 14 + # requested, so I filter it to what is needed. 15 + src = runCommand "${pname}-src-${version}" {} '' 16 + mkdir -p "$out" 17 + cp -r ${monorepoSrc}/cmake "$out" 18 + cp -r ${monorepoSrc}/${pname} "$out" 19 + mkdir -p "$out/libcxx" 20 + cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx" 21 + cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx" 22 + mkdir -p "$out/llvm" 23 + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" 24 + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" 25 + cp -r ${monorepoSrc}/runtimes "$out" 26 + ''; 27 + 28 + sourceRoot = "${src.name}/runtimes"; 29 + 30 + postInstall = lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin) '' 31 + # libcxxabi wants to link to libunwind_shared.so (?). 32 + ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so 33 + ''; 34 + 35 + outputs = [ "out" "dev" ]; 36 + 37 + nativeBuildInputs = [ cmake ninja python3 ]; 38 + 39 + cmakeFlags = [ 40 + "-DLLVM_ENABLE_RUNTIMES=libunwind" 41 + ] ++ lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF"; 42 + 43 + meta = llvm_meta // { 44 + # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst 45 + homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library"; 46 + description = "LLVM's unwinder library"; 47 + longDescription = '' 48 + The unwind library provides a family of _Unwind_* functions implementing 49 + the language-neutral stack unwinding portion of the Itanium C++ ABI (Level 50 + I). It is a dependency of the C++ ABI library, and sometimes is a 51 + dependency of other runtimes. 52 + ''; 53 + }; 54 + }
+57
pkgs/development/compilers/llvm/18/lld/default.nix
···
··· 1 + { lib, stdenv, llvm_meta 2 + , buildLlvmTools 3 + , monorepoSrc, runCommand 4 + , cmake 5 + , ninja 6 + , libxml2 7 + , libllvm 8 + , version 9 + }: 10 + 11 + stdenv.mkDerivation rec { 12 + pname = "lld"; 13 + inherit version; 14 + 15 + # Blank llvm dir just so relative path works 16 + src = runCommand "${pname}-src-${version}" {} '' 17 + mkdir -p "$out" 18 + cp -r ${monorepoSrc}/cmake "$out" 19 + cp -r ${monorepoSrc}/${pname} "$out" 20 + mkdir -p "$out/libunwind" 21 + cp -r ${monorepoSrc}/libunwind/include "$out/libunwind" 22 + mkdir -p "$out/llvm" 23 + ''; 24 + 25 + sourceRoot = "${src.name}/${pname}"; 26 + 27 + nativeBuildInputs = [ cmake ninja ]; 28 + buildInputs = [ libllvm libxml2 ]; 29 + 30 + patches = [ 31 + ./gnu-install-dirs.patch 32 + ]; 33 + 34 + cmakeFlags = [ 35 + "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/lld" 36 + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ 37 + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" 38 + ]; 39 + 40 + # Musl's default stack size is too small for lld to be able to link Firefox. 41 + LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152"; 42 + 43 + outputs = [ "out" "lib" "dev" ]; 44 + 45 + meta = llvm_meta // { 46 + homepage = "https://lld.llvm.org/"; 47 + description = "The LLVM linker (unwrapped)"; 48 + longDescription = '' 49 + LLD is a linker from the LLVM project that is a drop-in replacement for 50 + system linkers and runs much faster than them. It also provides features 51 + that are useful for toolchain developers. 52 + The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and 53 + WebAssembly in descending order of completeness. Internally, LLD consists 54 + of several different linkers. 55 + ''; 56 + }; 57 + }
+15
pkgs/development/compilers/llvm/18/lld/gnu-install-dirs.patch
···
··· 1 + diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake 2 + index d3924f7243d4..42a7cd62281c 100644 3 + --- a/cmake/modules/AddLLD.cmake 4 + +++ b/cmake/modules/AddLLD.cmake 5 + @@ -18,8 +18,8 @@ macro(add_lld_library name) 6 + install(TARGETS ${name} 7 + COMPONENT ${name} 8 + ${export_to_lldtargets} 9 + - LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} 10 + - ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} 11 + + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" 12 + + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" 13 + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") 14 + 15 + if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES)
+12
pkgs/development/compilers/llvm/18/lldb/cpu_subtype_arm64e_replacement.patch
···
··· 1 + diff --git a/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/source/Host/macosx/objcxx/HostInfoMacOSX.mm 2 + --- a/source/Host/macosx/objcxx/HostInfoMacOSX.mm 3 + +++ b/source/Host/macosx/objcxx/HostInfoMacOSX.mm 4 + @@ -233,7 +233,7 @@ void HostInfoMacOSX::ComputeHostArchitectureSupport(ArchSpec &arch_32, 5 + len = sizeof(is_64_bit_capable); 6 + ::sysctlbyname("hw.cpu64bit_capable", &is_64_bit_capable, &len, NULL, 0); 7 + 8 + - if (cputype == CPU_TYPE_ARM64 && cpusubtype == CPU_SUBTYPE_ARM64E) { 9 + + if (cputype == CPU_TYPE_ARM64 && cpusubtype == ((cpu_subtype_t) 2)) { // CPU_SUBTYPE_ARM64E is not available in the macOS 10.12 headers 10 + // The arm64e architecture is a preview. Pretend the host architecture 11 + // is arm64. 12 + cpusubtype = CPU_SUBTYPE_ARM64_ALL;
+46
pkgs/development/compilers/llvm/18/lldb/procfs.patch
···
··· 1 + --- a/source/Plugins/Process/Linux/Procfs.h 2 + +++ b/source/Plugins/Process/Linux/Procfs.h 3 + @@ -10,6 +10,13 @@ 4 + // sys/procfs.h on Android/Linux for all supported architectures. 5 + 6 + #include <sys/ptrace.h> 7 + +#include <asm/ptrace.h> 8 + + 9 + +// on i686 preprocessor symbols with these register names are defined as 10 + +// numeric constants; these symbols clash with identifier names used in 11 + +// `llvm/Support/VirtualFileSystem.h` and `llvm/ADT/SmallVector.h` 12 + +#undef FS 13 + +#undef CS 14 + 15 + #include "lldb/lldb-types.h" 16 + 17 + @@ -17,23 +24,13 @@ 18 + 19 + #include <vector> 20 + 21 + -#ifdef __ANDROID__ 22 + -#if defined(__arm64__) || defined(__aarch64__) 23 + -typedef unsigned long elf_greg_t; 24 + -typedef elf_greg_t 25 + - elf_gregset_t[(sizeof(struct user_pt_regs) / sizeof(elf_greg_t))]; 26 + -typedef struct user_fpsimd_state elf_fpregset_t; 27 + -#ifndef NT_FPREGSET 28 + -#define NT_FPREGSET NT_PRFPREG 29 + -#endif // NT_FPREGSET 30 + -#elif defined(__mips__) 31 + -#ifndef NT_FPREGSET 32 + -#define NT_FPREGSET NT_PRFPREG 33 + -#endif // NT_FPREGSET 34 + -#endif 35 + -#else // __ANDROID__ 36 + +#if !defined(__GLIBC__) && defined(__powerpc__) 37 + +#define pt_regs musl_pt_regs 38 + +#include <sys/procfs.h> 39 + +#undef pt_regs 40 + +#else 41 + #include <sys/procfs.h> 42 + -#endif // __ANDROID__ 43 + +#endif 44 + 45 + namespace lldb_private { 46 + namespace process_linux {
+439
pkgs/development/compilers/llvm/18/llvm/default.nix
···
··· 1 + { lib, stdenv, llvm_meta 2 + , pkgsBuildBuild 3 + , monorepoSrc 4 + , runCommand 5 + , cmake 6 + , darwin 7 + , ninja 8 + , python3 9 + , python3Packages 10 + , libffi 11 + , enableGoldPlugin ? true 12 + , libbfd 13 + , libpfm 14 + , libxml2 15 + , ncurses 16 + , version 17 + , release_version 18 + , zlib 19 + , which 20 + , sysctl 21 + , buildLlvmTools 22 + , debugVersion ? false 23 + , doCheck ? (!stdenv.isx86_32 /* TODO: why */) && (!stdenv.hostPlatform.isMusl) 24 + && (stdenv.hostPlatform == stdenv.buildPlatform) 25 + , enableManpages ? false 26 + , enableSharedLibraries ? !stdenv.hostPlatform.isStatic 27 + , enablePFM ? stdenv.isLinux /* PFM only supports Linux */ 28 + # broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 29 + # broken for the armv7l builder 30 + && !stdenv.hostPlatform.isAarch 31 + , enablePolly ? true 32 + }: 33 + 34 + let 35 + inherit (lib) optional optionals optionalString; 36 + 37 + # Used when creating a version-suffixed symlink of libLLVM.dylib 38 + shortVersion = with lib; 39 + concatStringsSep "." (take 1 (splitString "." release_version)); 40 + 41 + # Ordinarily we would just the `doCheck` and `checkDeps` functionality 42 + # `mkDerivation` gives us to manage our test dependencies (instead of breaking 43 + # out `doCheck` as a package level attribute). 44 + # 45 + # Unfortunately `lit` does not forward `$PYTHONPATH` to children processes, in 46 + # particular the children it uses to do feature detection. 47 + # 48 + # This means that python deps we add to `checkDeps` (which the python 49 + # interpreter is made aware of via `$PYTHONPATH` – populated by the python 50 + # setup hook) are not picked up by `lit` which causes it to skip tests. 51 + # 52 + # Adding `python3.withPackages (ps: [ ... ])` to `checkDeps` also doesn't work 53 + # because this package is shadowed in `$PATH` by the regular `python3` 54 + # package. 55 + # 56 + # So, we "manually" assemble one python derivation for the package to depend 57 + # on, taking into account whether checks are enabled or not: 58 + python = if doCheck then 59 + # Note that we _explicitly_ ask for a python interpreter for our host 60 + # platform here; the splicing that would ordinarily take care of this for 61 + # us does not seem to work once we use `withPackages`. 62 + let 63 + checkDeps = ps: with ps; [ psutil ]; 64 + in pkgsBuildBuild.targetPackages.python3.withPackages checkDeps 65 + else python3; 66 + 67 + in 68 + 69 + stdenv.mkDerivation (rec { 70 + pname = "llvm"; 71 + inherit version; 72 + 73 + src = runCommand "${pname}-src-${version}" {} ('' 74 + mkdir -p "$out" 75 + cp -r ${monorepoSrc}/cmake "$out" 76 + cp -r ${monorepoSrc}/${pname} "$out" 77 + cp -r ${monorepoSrc}/third-party "$out" 78 + '' + lib.optionalString enablePolly '' 79 + chmod u+w "$out/${pname}/tools" 80 + cp -r ${monorepoSrc}/polly "$out/${pname}/tools" 81 + ''); 82 + 83 + sourceRoot = "${src.name}/${pname}"; 84 + 85 + outputs = [ "out" "lib" "dev" "python" ]; 86 + 87 + nativeBuildInputs = [ cmake ninja python ] 88 + ++ optionals enableManpages [ 89 + # Note: we intentionally use `python3Packages` instead of `python3.pkgs`; 90 + # splicing does *not* work with the latter. (TODO: fix) 91 + python3Packages.sphinx 92 + ] ++ optionals (lib.versionOlder version "18" && enableManpages) [ 93 + python3Packages.recommonmark 94 + ] ++ optionals (lib.versionAtLeast version "18" && enableManpages) [ 95 + python3Packages.myst-parser 96 + ]; 97 + 98 + buildInputs = [ libxml2 libffi ] 99 + ++ optional enablePFM libpfm; # exegesis 100 + 101 + propagatedBuildInputs = [ ncurses zlib ]; 102 + 103 + nativeCheckInputs = [ 104 + which 105 + ] ++ lib.optional stdenv.isDarwin sysctl; 106 + 107 + patches = [ 108 + ./gnu-install-dirs.patch 109 + 110 + # Running the tests involves invoking binaries (like `opt`) that depend on 111 + # the LLVM dylibs and reference them by absolute install path (i.e. their 112 + # nix store path). 113 + # 114 + # Because we have not yet run the install phase (we're running these tests 115 + # as part of `checkPhase` instead of `installCheckPhase`) these absolute 116 + # paths do not exist yet; to work around this we point the loader (`ld` on 117 + # unix, `dyld` on macOS) at the `lib` directory which will later become this 118 + # package's `lib` output. 119 + # 120 + # Previously we would just set `LD_LIBRARY_PATH` to include the build `lib` 121 + # dir but: 122 + # - this doesn't generalize well to other platforms; `lit` doesn't forward 123 + # `DYLD_LIBRARY_PATH` (macOS): 124 + # + https://github.com/llvm/llvm-project/blob/0d89963df354ee309c15f67dc47c8ab3cb5d0fb2/llvm/utils/lit/lit/TestingConfig.py#L26 125 + # - even if `lit` forwarded this env var, we actually cannot set 126 + # `DYLD_LIBRARY_PATH` in the child processes `lit` launches because 127 + # `DYLD_LIBRARY_PATH` (and `DYLD_FALLBACK_LIBRARY_PATH`) is cleared for 128 + # "protected processes" (i.e. the python interpreter that runs `lit`): 129 + # https://stackoverflow.com/a/35570229 130 + # - other LLVM subprojects deal with this issue by having their `lit` 131 + # configuration set these env vars for us; it makes sense to do the same 132 + # for LLVM: 133 + # + https://github.com/llvm/llvm-project/blob/4c106cfdf7cf7eec861ad3983a3dd9a9e8f3a8ae/clang-tools-extra/test/Unit/lit.cfg.py#L22-L31 134 + # 135 + # !!! TODO: look into upstreaming this patch 136 + ./llvm-lit-cfg-add-libs-to-dylib-path.patch 137 + 138 + # `lit` has a mode where it executes run lines as a shell script which is 139 + # constructs; this is problematic for macOS because it means that there's 140 + # another process in between `lit` and the binaries being tested. As noted 141 + # above, this means that `DYLD_LIBRARY_PATH` is cleared which means that our 142 + # tests fail with dyld errors. 143 + # 144 + # To get around this we patch `lit` to reintroduce `DYLD_LIBRARY_PATH`, when 145 + # present in the test configuration. 146 + # 147 + # It's not clear to me why this isn't an issue for LLVM developers running 148 + # on macOS (nothing about this _seems_ nix specific).. 149 + ./lit-shell-script-runner-set-dyld-library-path.patch 150 + ] ++ lib.optionals enablePolly [ 151 + ./gnu-install-dirs-polly.patch 152 + 153 + # Just like the `llvm-lit-cfg` patch, but for `polly`. 154 + ./polly-lit-cfg-add-libs-to-dylib-path.patch 155 + ]; 156 + 157 + postPatch = optionalString stdenv.isDarwin '' 158 + substituteInPlace cmake/modules/AddLLVM.cmake \ 159 + --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ 160 + --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" 161 + 162 + # As of LLVM 15, marked as XFAIL on arm64 macOS but lit doesn't seem to pick 163 + # this up: https://github.com/llvm/llvm-project/blob/c344d97a125b18f8fed0a64aace73c49a870e079/llvm/test/MC/ELF/cfi-version.ll#L7 164 + rm test/MC/ELF/cfi-version.ll 165 + 166 + # This test tries to call `sw_vers` by absolute path (`/usr/bin/sw_vers`) 167 + # and thus fails under the sandbox: 168 + substituteInPlace unittests/TargetParser/Host.cpp \ 169 + --replace '/usr/bin/sw_vers' "${(builtins.toString darwin.DarwinTools) + "/bin/sw_vers" }" 170 + 171 + # This test tries to call the intrinsics `@llvm.roundeven.f32` and 172 + # `@llvm.roundeven.f64` which seem to (incorrectly?) lower to `roundevenf` 173 + # and `roundeven` on macOS. 174 + # 175 + # However these functions are glibc specific so the test fails: 176 + # - https://www.gnu.org/software/gnulib/manual/html_node/roundevenf.html 177 + # - https://www.gnu.org/software/gnulib/manual/html_node/roundeven.html 178 + # 179 + substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \ 180 + --replace "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \ 181 + --replace "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" "" 182 + 183 + # fails when run in sandbox 184 + substituteInPlace unittests/Support/VirtualFileSystemTest.cpp \ 185 + --replace "PhysicalFileSystemWorkingDirFailure" "DISABLED_PhysicalFileSystemWorkingDirFailure" 186 + '' + optionalString (stdenv.isDarwin && stdenv.hostPlatform.isx86) '' 187 + # This test fails on darwin x86_64 because `sw_vers` reports a different 188 + # macOS version than what LLVM finds by reading 189 + # `/System/Library/CoreServices/SystemVersion.plist` (which is passed into 190 + # the sandbox on macOS). 191 + # 192 + # The `sw_vers` provided by nixpkgs reports the macOS version associated 193 + # with the `CoreFoundation` framework with which it was built. Because 194 + # nixpkgs pins the SDK for `aarch64-darwin` and `x86_64-darwin` what 195 + # `sw_vers` reports is not guaranteed to match the macOS version of the host 196 + # that's building this derivation. 197 + # 198 + # Astute readers will note that we only _patch_ this test on aarch64-darwin 199 + # (to use the nixpkgs provided `sw_vers`) instead of disabling it outright. 200 + # So why does this test pass on aarch64? 201 + # 202 + # Well, it seems that `sw_vers` on aarch64 actually links against the _host_ 203 + # CoreFoundation framework instead of the nixpkgs provided one. 204 + # 205 + # Not entirely sure what the right fix is here. I'm assuming aarch64 206 + # `sw_vers` doesn't intentionally link against the host `CoreFoundation` 207 + # (still digging into how this ends up happening, will follow up) but that 208 + # aside I think the more pertinent question is: should we be patching LLVM's 209 + # macOS version detection logic to use `sw_vers` instead of reading host 210 + # paths? This *is* a way in which details about builder machines can creep 211 + # into the artifacts that are produced, affecting reproducibility, but it's 212 + # not clear to me when/where/for what this even gets used in LLVM. 213 + # 214 + # TODO(@rrbutani): fix/follow-up 215 + substituteInPlace unittests/TargetParser/Host.cpp \ 216 + --replace "getMacOSHostVersion" "DISABLED_getMacOSHostVersion" 217 + 218 + # This test fails with a `dysmutil` crash; have not yet dug into what's 219 + # going on here (TODO(@rrbutani)). 220 + rm test/tools/dsymutil/ARM/obfuscated.test 221 + '' + '' 222 + # FileSystem permissions tests fail with various special bits 223 + substituteInPlace unittests/Support/CMakeLists.txt \ 224 + --replace "Path.cpp" "" 225 + rm unittests/Support/Path.cpp 226 + substituteInPlace unittests/IR/CMakeLists.txt \ 227 + --replace "PassBuilderCallbacksTest.cpp" "" 228 + rm unittests/IR/PassBuilderCallbacksTest.cpp 229 + rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test 230 + 231 + # Fails in the presence of anti-virus software or other intrusion-detection software that 232 + # modifies the atime when run. See #284056. 233 + rm test/tools/llvm-objcopy/ELF/strip-preserve-atime.test 234 + '' + optionalString stdenv.hostPlatform.isMusl '' 235 + patch -p1 -i ${../../common/llvm/TLI-musl.patch} 236 + substituteInPlace unittests/Support/CMakeLists.txt \ 237 + --replace "add_subdirectory(DynamicLibrary)" "" 238 + rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp 239 + # valgrind unhappy with musl or glibc, but fails w/musl only 240 + rm test/CodeGen/AArch64/wineh4.mir 241 + '' + optionalString stdenv.hostPlatform.isAarch32 '' 242 + # skip failing X86 test cases on 32-bit ARM 243 + rm test/DebugInfo/X86/convert-debugloc.ll 244 + rm test/DebugInfo/X86/convert-inlined.ll 245 + rm test/DebugInfo/X86/convert-linked.ll 246 + rm test/tools/dsymutil/X86/op-convert.test 247 + rm test/tools/gold/X86/split-dwarf.ll 248 + rm test/tools/llvm-dwarfdump/X86/prettyprint_types.s 249 + rm test/tools/llvm-dwarfdump/X86/simplified-template-names.s 250 + rm test/CodeGen/RISCV/attributes.ll 251 + rm test/CodeGen/RISCV/xtheadmempair.ll 252 + '' + optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' 253 + # Seems to require certain floating point hardware (NEON?) 254 + rm test/ExecutionEngine/frem.ll 255 + '' + '' 256 + patchShebangs test/BugPoint/compile-custom.ll.py 257 + ''; 258 + 259 + preConfigure = '' 260 + # Workaround for configure flags that need to have spaces 261 + cmakeFlagsArray+=( 262 + -DLLVM_LIT_ARGS="-svj''${NIX_BUILD_CORES} --no-progress-bar" 263 + ) 264 + ''; 265 + 266 + # Defensive check: some paths (that we make symlinks to) depend on the release 267 + # version, for example: 268 + # - https://github.com/llvm/llvm-project/blob/406bde9a15136254f2b10d9ef3a42033b3cb1b16/clang/lib/Headers/CMakeLists.txt#L185 269 + # 270 + # So we want to sure that the version in the source matches the release 271 + # version we were given. 272 + # 273 + # We do this check here, in the LLVM build, because it happens early. 274 + postConfigure = let 275 + v = lib.versions; 276 + major = v.major release_version; 277 + minor = v.minor release_version; 278 + patch = v.patch release_version; 279 + in '' 280 + # $1: part, $2: expected 281 + check_version() { 282 + part="''${1^^}" 283 + part="$(cat include/llvm/Config/llvm-config.h | grep "#define LLVM_VERSION_''${part} " | cut -d' ' -f3)" 284 + 285 + if [[ "$part" != "$2" ]]; then 286 + echo >&2 \ 287 + "mismatch in the $1 version! we have version ${release_version}" \ 288 + "and expected the $1 version to be '$2'; the source has '$part' instead" 289 + exit 3 290 + fi 291 + } 292 + 293 + check_version major ${major} 294 + check_version minor ${minor} 295 + check_version patch ${patch} 296 + ''; 297 + 298 + # E.g. mesa.drivers use the build-id as a cache key (see #93946): 299 + LDFLAGS = optionalString (enableSharedLibraries && !stdenv.isDarwin) "-Wl,--build-id=sha1"; 300 + 301 + hardeningDisable = [ "trivialautovarinit" ]; 302 + 303 + cmakeBuildType = if debugVersion then "Debug" else "Release"; 304 + 305 + cmakeFlags = with stdenv; let 306 + # These flags influence llvm-config's BuildVariables.inc in addition to the 307 + # general build. We need to make sure these are also passed via 308 + # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native 309 + # will return different results from the cross llvm-config. 310 + # 311 + # Some flags don't need to be repassed because LLVM already does so (like 312 + # CMAKE_BUILD_TYPE), others are irrelevant to the result. 313 + flagsForLlvmConfig = [ 314 + "-DLLVM_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/llvm" 315 + "-DLLVM_ENABLE_RTTI=ON" 316 + ] ++ optionals enableSharedLibraries [ 317 + "-DLLVM_LINK_LLVM_DYLIB=ON" 318 + ]; 319 + in flagsForLlvmConfig ++ [ 320 + "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc 321 + "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" 322 + "-DLLVM_ENABLE_FFI=ON" 323 + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" 324 + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" 325 + "-DLLVM_ENABLE_DUMP=ON" 326 + ] ++ optionals stdenv.hostPlatform.isStatic [ 327 + # Disables building of shared libs, -fPIC is still injected by cc-wrapper 328 + "-DLLVM_ENABLE_PIC=OFF" 329 + "-DLLVM_BUILD_STATIC=ON" 330 + "-DLLVM_LINK_LLVM_DYLIB=off" 331 + # libxml2 needs to be disabled because the LLVM build system ignores its .la 332 + # file and doesn't link zlib as well. 333 + # https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812 334 + "-DLLVM_ENABLE_LIBXML2=OFF" 335 + ] ++ optionals enableManpages [ 336 + "-DLLVM_BUILD_DOCS=ON" 337 + "-DLLVM_ENABLE_SPHINX=ON" 338 + "-DSPHINX_OUTPUT_MAN=ON" 339 + "-DSPHINX_OUTPUT_HTML=OFF" 340 + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" 341 + ] ++ optionals enableGoldPlugin [ 342 + "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" 343 + ] ++ optionals isDarwin [ 344 + "-DLLVM_ENABLE_LIBCXX=ON" 345 + "-DCAN_TARGET_i386=false" 346 + ] ++ optionals ((stdenv.hostPlatform != stdenv.buildPlatform) && !(stdenv.buildPlatform.canExecute stdenv.hostPlatform)) [ 347 + "-DCMAKE_CROSSCOMPILING=True" 348 + "-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen" 349 + ( 350 + let 351 + nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; 352 + nativeBintools = nativeCC.bintools.bintools; 353 + nativeToolchainFlags = [ 354 + "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" 355 + "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" 356 + "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" 357 + "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" 358 + "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" 359 + ]; 360 + # We need to repass the custom GNUInstallDirs values, otherwise CMake 361 + # will choose them for us, leading to wrong results in llvm-config-native 362 + nativeInstallFlags = [ 363 + "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" 364 + "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin" 365 + "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include" 366 + "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" 367 + "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" 368 + ]; 369 + in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" 370 + + lib.concatStringsSep ";" (lib.concatLists [ 371 + flagsForLlvmConfig 372 + nativeToolchainFlags 373 + nativeInstallFlags 374 + ]) 375 + ) 376 + ]; 377 + 378 + postInstall = '' 379 + mkdir -p $python/share 380 + mv $out/share/opt-viewer $python/share/opt-viewer 381 + moveToOutput "bin/llvm-config*" "$dev" 382 + substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ 383 + --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \ 384 + --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" 385 + substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ 386 + --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "'"$lib"'")' 387 + '' 388 + + optionalString (stdenv.isDarwin && enableSharedLibraries) '' 389 + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib 390 + '' 391 + + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' 392 + cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native 393 + ''; 394 + 395 + inherit doCheck; 396 + 397 + checkTarget = "check-all"; 398 + 399 + # For the update script: 400 + passthru.monorepoSrc = monorepoSrc; 401 + 402 + requiredSystemFeatures = [ "big-parallel" ]; 403 + meta = llvm_meta // { 404 + homepage = "https://llvm.org/"; 405 + description = "A collection of modular and reusable compiler and toolchain technologies"; 406 + longDescription = '' 407 + The LLVM Project is a collection of modular and reusable compiler and 408 + toolchain technologies. Despite its name, LLVM has little to do with 409 + traditional virtual machines. The name "LLVM" itself is not an acronym; it 410 + is the full name of the project. 411 + LLVM began as a research project at the University of Illinois, with the 412 + goal of providing a modern, SSA-based compilation strategy capable of 413 + supporting both static and dynamic compilation of arbitrary programming 414 + languages. Since then, LLVM has grown to be an umbrella project consisting 415 + of a number of subprojects, many of which are being used in production by 416 + a wide variety of commercial and open source projects as well as being 417 + widely used in academic research. Code in the LLVM project is licensed 418 + under the "Apache 2.0 License with LLVM exceptions". 419 + ''; 420 + }; 421 + } // lib.optionalAttrs enableManpages { 422 + pname = "llvm-manpages"; 423 + 424 + propagatedBuildInputs = []; 425 + 426 + ninjaFlags = [ "docs-llvm-man" ]; 427 + installTargets = [ "install-docs-llvm-man" ]; 428 + 429 + postPatch = null; 430 + postInstall = null; 431 + 432 + outputs = [ "out" ]; 433 + 434 + doCheck = false; 435 + 436 + meta = llvm_meta // { 437 + description = "man pages for LLVM ${version}"; 438 + }; 439 + })
+13
pkgs/development/compilers/llvm/18/llvm/gnu-install-dirs-polly.patch
···
··· 1 + --- a/tools/polly/cmake/polly_macros.cmake 2024-03-15 17:36:20.550893344 -0700 2 + +++ b/tools/polly/cmake/polly_macros.cmake 2024-03-15 17:37:06.277332960 -0700 3 + @@ -45,8 +45,8 @@ 4 + install(TARGETS ${name} 5 + COMPONENT ${name} 6 + EXPORT LLVMExports 7 + - LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} 8 + - ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) 9 + + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} 10 + + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) 11 + add_llvm_install_targets(install-${name} 12 + COMPONENT ${name}) 13 + endif()
+137
pkgs/development/compilers/llvm/18/llvm/gnu-install-dirs.patch
···
··· 1 + diff --git a/CMakeLists.txt b/CMakeLists.txt 2 + index 471817d68286..c51463304159 100644 3 + --- a/CMakeLists.txt 4 + +++ b/CMakeLists.txt 5 + @@ -1010,7 +1010,7 @@ if (NOT TENSORFLOW_AOT_PATH STREQUAL "") 6 + add_subdirectory(${TENSORFLOW_AOT_PATH}/xla_aot_runtime_src 7 + ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tf_runtime) 8 + install(TARGETS tf_xla_runtime EXPORT LLVMExports 9 + - ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime) 10 + + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime) 11 + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime) 12 + # Once we add more modules, we should handle this more automatically. 13 + if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_INLINERSIZEMODEL) 14 + diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake 15 + index 230620c37027..dd16cab1835e 100644 16 + --- a/cmake/modules/AddLLVM.cmake 17 + +++ b/cmake/modules/AddLLVM.cmake 18 + @@ -876,8 +876,8 @@ macro(add_llvm_library name) 19 + get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella}) 20 + install(TARGETS ${name} 21 + ${export_to_llvmexports} 22 + - LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} 23 + - ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} 24 + + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name} 25 + + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name} 26 + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${name}) 27 + 28 + if (NOT LLVM_ENABLE_IDE) 29 + @@ -2069,7 +2069,7 @@ function(llvm_install_library_symlink name dest type) 30 + set(LLVM_LINK_OR_COPY copy) 31 + endif() 32 + 33 + - set(output_dir lib${LLVM_LIBDIR_SUFFIX}) 34 + + set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) 35 + if(WIN32 AND "${type}" STREQUAL "SHARED") 36 + set(output_dir "${CMAKE_INSTALL_BINDIR}") 37 + endif() 38 + @@ -2344,16 +2344,37 @@ function(llvm_setup_rpath name) 39 + 40 + if (APPLE) 41 + set(_install_name_dir INSTALL_NAME_DIR "@rpath") 42 + - set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) 43 + + set(_install_rpath ${extra_libdir}) 44 + elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND BUILD_SHARED_LIBS) 45 + # $ORIGIN is not interpreted at link time by aix ld. 46 + # Since BUILD_SHARED_LIBS is only recommended for use by developers, 47 + # hardcode the rpath to build/install lib dir first in this mode. 48 + # FIXME: update this when there is better solution. 49 + - set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) 50 + + set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) 51 + elseif(UNIX) 52 + - set(_build_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) 53 + - set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}") 54 + + # Note that we add `extra_libdir` (aka `LLVM_LIBRARY_DIR` in our case) back 55 + + # to `_install_rpath` here. 56 + + # 57 + + # In nixpkgs we do not build and install LLVM alongside rdeps of LLVM (i.e. 58 + + # clang); instead LLVM is its own package and thus lands at its own nix 59 + + # store path. This makes it so that the default relative rpath (`../lib/`) 60 + + # does not point at the LLVM shared objects. 61 + + # 62 + + # More discussion here: 63 + + # - https://github.com/NixOS/nixpkgs/pull/235624#discussion_r1220150329 64 + + # - https://reviews.llvm.org/D146918 (16.0.5+) 65 + + # 66 + + # Note that we leave `extra_libdir` in `_build_rpath`: without FHS there is 67 + + # no potential that this will result in us pulling in the "wrong" LLVM. 68 + + # Adding this to the build rpath means we aren't forced to use 69 + + # `installCheckPhase` instead of `checkPhase` (i.e. binaries in the build 70 + + # dir, pre-install, will have the right rpath for LLVM). 71 + + # 72 + + # As noted in the differential above, an alternative solution is to have 73 + + # all rdeps of nixpkgs' LLVM (that use the AddLLVM.cmake machinery) set 74 + + # `CMAKE_INSTALL_RPATH`. 75 + + set(_build_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) 76 + + set(_install_rpath ${extra_libdir}) 77 + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") 78 + set_property(TARGET ${name} APPEND_STRING PROPERTY 79 + LINK_FLAGS " -Wl,-z,origin ") 80 + diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake 81 + index 891c9e6d618c..8d963f3b0069 100644 82 + --- a/cmake/modules/AddOCaml.cmake 83 + +++ b/cmake/modules/AddOCaml.cmake 84 + @@ -147,9 +147,9 @@ function(add_ocaml_library name) 85 + endforeach() 86 + 87 + if( APPLE ) 88 + - set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") 89 + + set(ocaml_rpath ${LLVM_LIBRARY_DIR}) 90 + elseif( UNIX ) 91 + - set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") 92 + + set(ocaml_rpath ${LLVM_LIBRARY_DIR}) 93 + endif() 94 + list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") 95 + 96 + diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt 97 + index d99af79aa38e..21e794224b99 100644 98 + --- a/cmake/modules/CMakeLists.txt 99 + +++ b/cmake/modules/CMakeLists.txt 100 + @@ -127,7 +127,7 @@ set(LLVM_CONFIG_INCLUDE_DIRS 101 + ) 102 + list(REMOVE_DUPLICATES LLVM_CONFIG_INCLUDE_DIRS) 103 + 104 + -extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "lib\${LLVM_LIBDIR_SUFFIX}") 105 + +extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}") 106 + set(LLVM_CONFIG_LIBRARY_DIRS 107 + "${LLVM_CONFIG_LIBRARY_DIR}" 108 + # FIXME: Should there be other entries here? 109 + diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in 110 + index 370005cd8d7d..7e790bc52111 100644 111 + --- a/tools/llvm-config/BuildVariables.inc.in 112 + +++ b/tools/llvm-config/BuildVariables.inc.in 113 + @@ -23,6 +23,7 @@ 114 + #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" 115 + #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" 116 + #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" 117 + +#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@" 118 + #define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" 119 + #define LLVM_INSTALL_PACKAGE_DIR "@LLVM_INSTALL_PACKAGE_DIR@" 120 + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" 121 + diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp 122 + index e86eb2b44b10..f63e207e792e 100644 123 + --- a/tools/llvm-config/llvm-config.cpp 124 + +++ b/tools/llvm-config/llvm-config.cpp 125 + @@ -366,7 +366,11 @@ int main(int argc, char **argv) { 126 + sys::fs::make_absolute(ActivePrefix, Path); 127 + ActiveBinDir = std::string(Path.str()); 128 + } 129 + - ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; 130 + + { 131 + + SmallString<256> Path(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX); 132 + + sys::fs::make_absolute(ActivePrefix, Path); 133 + + ActiveLibDir = std::string(Path.str()); 134 + + } 135 + { 136 + SmallString<256> Path(LLVM_INSTALL_PACKAGE_DIR); 137 + sys::fs::make_absolute(ActivePrefix, Path);
+12
pkgs/development/compilers/llvm/18/llvm/lit-shell-script-runner-set-dyld-library-path.patch
···
··· 1 + --- a/utils/lit/lit/TestRunner.py 2024-03-15 17:27:53.170780798 -0700 2 + +++ b/utils/lit/lit/TestRunner.py 2024-03-15 17:28:43.277447791 -0700 3 + @@ -1183,6 +1183,9 @@ 4 + f.write("@echo on\n") 5 + f.write("\n@if %ERRORLEVEL% NEQ 0 EXIT\n".join(commands)) 6 + else: 7 + + if "DYLD_LIBRARY_PATH" in test.config.environment: 8 + + f.write(f'export DYLD_LIBRARY_PATH="{test.config.environment["DYLD_LIBRARY_PATH"]}"\n') 9 + + 10 + for i, ln in enumerate(commands): 11 + match = re.fullmatch(kPdbgRegex, ln) 12 + if match:
+80
pkgs/development/compilers/llvm/18/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch
···
··· 1 + diff --git a/test/Unit/lit.cfg.py b/test/Unit/lit.cfg.py 2 + index 81e8dc04acea..479ff95681e2 100644 3 + --- a/test/Unit/lit.cfg.py 4 + +++ b/test/Unit/lit.cfg.py 5 + @@ -3,6 +3,7 @@ 6 + # Configuration file for the 'lit' test runner. 7 + 8 + import os 9 + +import platform 10 + import subprocess 11 + 12 + import lit.formats 13 + @@ -55,3 +56,26 @@ if sys.platform in ["win32", "cygwin"] and os.path.isdir(config.shlibdir): 14 + # Win32 may use %SYSTEMDRIVE% during file system shell operations, so propogate. 15 + if sys.platform == "win32" and "SYSTEMDRIVE" in os.environ: 16 + config.environment["SYSTEMDRIVE"] = os.environ["SYSTEMDRIVE"] 17 + + 18 + +# Add the LLVM dynamic libs to the platform-specific loader search path env var: 19 + +# 20 + +# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify.. 21 + +def find_shlibpath_var(): 22 + + if platform.system() in ["Linux", "FreeBSD", "NetBSD", "OpenBSD", "SunOS"]: 23 + + yield "LD_LIBRARY_PATH" 24 + + elif platform.system() == "Darwin": 25 + + yield "DYLD_LIBRARY_PATH" 26 + + elif platform.system() == "Windows": 27 + + yield "PATH" 28 + + elif platform.system() == "AIX": 29 + + yield "LIBPATH" 30 + + 31 + +for shlibpath_var in find_shlibpath_var(): 32 + + shlibpath = os.path.pathsep.join( 33 + + (config.shlibdir, 34 + + config.environment.get(shlibpath_var, ''))) 35 + + config.environment[shlibpath_var] = shlibpath 36 + + break 37 + +else: 38 + + lit_config.warning("unable to inject shared library path on '{}'" 39 + + .format(platform.system())) 40 + diff --git a/test/lit.cfg.py b/test/lit.cfg.py 41 + index 75a38b4c5dad..856fc75c9d74 100644 42 + --- a/test/lit.cfg.py 43 + +++ b/test/lit.cfg.py 44 + @@ -42,6 +42,26 @@ llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True) 45 + llvm_config.with_system_environment( 46 + ["HOME", "INCLUDE", "LIB", "TMP", "TEMP"]) 47 + 48 + +# Add the LLVM dynamic libs to the platform-specific loader search path env var: 49 + +# 50 + +# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify.. 51 + +def find_shlibpath_var(): 52 + + if platform.system() in ["Linux", "FreeBSD", "NetBSD", "OpenBSD", "SunOS"]: 53 + + yield "LD_LIBRARY_PATH" 54 + + elif platform.system() == "Darwin": 55 + + yield "DYLD_LIBRARY_PATH" 56 + + elif platform.system() == "Windows": 57 + + yield "PATH" 58 + + elif platform.system() == "AIX": 59 + + yield "LIBPATH" 60 + + 61 + +for shlibpath_var in find_shlibpath_var(): 62 + + shlibpath = config.llvm_shlib_dir 63 + + llvm_config.with_environment(shlibpath_var, shlibpath, append_path = True) 64 + + break 65 + +else: 66 + + lit_config.warning("unable to inject shared library path on '{}'" 67 + + .format(platform.system())) 68 + 69 + # Set up OCAMLPATH to include newly built OCaml libraries. 70 + top_ocaml_lib = os.path.join(config.llvm_lib_dir, "ocaml") 71 + @@ -318,7 +338,7 @@ def have_cxx_shared_library(): 72 + 73 + try: 74 + readobj_cmd = subprocess.Popen( 75 + - [readobj_exe, "--needed-libs", readobj_exe], stdout=subprocess.PIPE 76 + + [readobj_exe, "--needed-libs", readobj_exe], stdout=subprocess.PIPE, env=config.environment 77 + ) 78 + except OSError: 79 + print("could not exec llvm-readobj") 80 +
+24
pkgs/development/compilers/llvm/18/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch
···
··· 1 + diff --git a/tools/polly/test/lit.cfg b/tools/polly/test/lit.cfg 2 + index 41e3a589c61e..09f3b17498b0 100644 3 + --- a/tools/polly/test/lit.cfg 4 + +++ b/tools/polly/test/lit.cfg 5 + @@ -36,9 +36,17 @@ base_paths = [config.llvm_tools_dir, config.environment['PATH']] 6 + path = os.path.pathsep.join(base_paths + config.extra_paths) 7 + config.environment['PATH'] = path 8 + 9 + +# (Copied from polly/test/Unit/lit.cfg) 10 + +if platform.system() == 'Darwin': 11 + + shlibpath_var = 'DYLD_LIBRARY_PATH' 12 + +elif platform.system() == 'Windows': 13 + + shlibpath_var = 'PATH' 14 + +else: 15 + + shlibpath_var = 'LD_LIBRARY_PATH' 16 + + 17 + path = os.path.pathsep.join((config.llvm_libs_dir, 18 + - config.environment.get('LD_LIBRARY_PATH',''))) 19 + -config.environment['LD_LIBRARY_PATH'] = path 20 + + config.environment.get(shlibpath_var,''))) 21 + +config.environment[shlibpath_var] = path 22 + 23 + llvm_config.use_default_substitutions() 24 +
+73
pkgs/development/compilers/llvm/18/openmp/default.nix
···
··· 1 + { lib 2 + , stdenv 3 + , llvm_meta 4 + , monorepoSrc 5 + , runCommand 6 + , cmake 7 + , ninja 8 + , llvm 9 + , targetLlvm 10 + , lit 11 + , clang-unwrapped 12 + , perl 13 + , pkg-config 14 + , xcbuild 15 + , version 16 + }: 17 + 18 + stdenv.mkDerivation rec { 19 + pname = "openmp"; 20 + inherit version; 21 + 22 + src = runCommand "${pname}-src-${version}" {} '' 23 + mkdir -p "$out" 24 + cp -r ${monorepoSrc}/cmake "$out" 25 + cp -r ${monorepoSrc}/${pname} "$out" 26 + ''; 27 + 28 + sourceRoot = "${src.name}/${pname}"; 29 + 30 + patches = [ 31 + ./fix-find-tool.patch 32 + ./run-lit-directly.patch 33 + ]; 34 + 35 + outputs = [ "out" "dev" ]; 36 + 37 + nativeBuildInputs = [ cmake ninja perl pkg-config lit ]; 38 + buildInputs = [ 39 + (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) 40 + ]; 41 + 42 + nativeCheckInputs = lib.optional stdenv.hostPlatform.isDarwin xcbuild.xcrun; 43 + 44 + # Unsup:Pass:XFail:Fail 45 + # 26:267:16:8 46 + doCheck = false; 47 + checkTarget = "check-openmp"; 48 + 49 + preCheck = '' 50 + patchShebangs ../tools/archer/tests/deflake.bash 51 + ''; 52 + 53 + cmakeFlags = [ 54 + "-DCLANG_TOOL=${clang-unwrapped}/bin/clang" 55 + "-DOPT_TOOL=${llvm}/bin/opt" 56 + "-DLINK_TOOL=${llvm}/bin/llvm-link" 57 + ]; 58 + 59 + meta = llvm_meta // { 60 + homepage = "https://openmp.llvm.org/"; 61 + description = "Support for the OpenMP language"; 62 + longDescription = '' 63 + The OpenMP subproject of LLVM contains the components required to build an 64 + executable OpenMP program that are outside the compiler itself. 65 + Contains the code for the runtime library against which code compiled by 66 + "clang -fopenmp" must be linked before it can run and the library that 67 + supports offload to target devices. 68 + ''; 69 + # "All of the code is dual licensed under the MIT license and the UIUC 70 + # License (a BSD-like license)": 71 + license = with lib.licenses; [ mit ncsa ]; 72 + }; 73 + }
+17
pkgs/development/compilers/llvm/18/openmp/fix-find-tool.patch
···
··· 1 + diff --git a/libomptarget/DeviceRTL/CMakeLists.txt b/libomptarget/DeviceRTL/CMakeLists.txt 2 + index 630947abec7e..9f032dc7bd3f 100644 3 + --- a/libomptarget/DeviceRTL/CMakeLists.txt 4 + +++ b/libomptarget/DeviceRTL/CMakeLists.txt 5 + @@ -27,10 +27,10 @@ endif() 6 + if (LLVM_DIR) 7 + # Builds that use pre-installed LLVM have LLVM_DIR set. 8 + # A standalone or LLVM_ENABLE_RUNTIMES=openmp build takes this route 9 + - find_program(CLANG_TOOL clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) 10 + + find_program(CLANG_TOOL clang PATHS ${LLVM_TOOLS_BINARY_DIR}) 11 + find_program(PACKAGER_TOOL clang-offload-packager PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) 12 + find_program(LINK_TOOL llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) 13 + - find_program(OPT_TOOL opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) 14 + + find_program(OPT_TOOL opt PATHS ${LLVM_TOOLS_BINARY_DIR}) 15 + if ((NOT CLANG_TOOL) OR (NOT LINK_TOOL) OR (NOT OPT_TOOL) OR (NOT PACKAGER_TOOL)) 16 + libomptarget_say("Not building DeviceRTL. Missing clang: ${CLANG_TOOL}, llvm-link: ${LINK_TOOL}, opt: ${OPT_TOOL}, or clang-offload-packager: ${PACKAGER_TOOL}") 17 + return()
pkgs/development/compilers/llvm/18/openmp/run-lit-directly.patch

This is a binary file and will not be displayed.

-3
pkgs/development/compilers/llvm/git/clang/default.nix
··· 70 postInstall = '' 71 ln -sv $out/bin/clang $out/bin/cpp 72 73 - mkdir -p $lib/lib/clang 74 - mv $lib/lib/${lib.versions.major version} $lib/lib/clang/${lib.versions.major version} 75 - 76 # Move libclang to 'lib' output 77 moveToOutput "lib/libclang.*" "$lib" 78 moveToOutput "lib/libclang-cpp.*" "$lib"
··· 70 postInstall = '' 71 ln -sv $out/bin/clang $out/bin/cpp 72 73 # Move libclang to 'lib' output 74 moveToOutput "lib/libclang.*" "$lib" 75 moveToOutput "lib/libclang-cpp.*" "$lib"
+1 -28
pkgs/development/compilers/llvm/git/clang/gnu-install-dirs.patch
··· 1 - diff --git a/CMakeLists.txt b/CMakeLists.txt 2 - index f7936d72e088..a362fa49b534 100644 3 - --- a/CMakeLists.txt 4 - +++ b/CMakeLists.txt 5 - @@ -31,7 +31,21 @@ if(CLANG_BUILT_STANDALONE) 6 - find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}") 7 - list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}") 8 - 9 - - # Turn into CACHE PATHs for overwritting 10 - + # We can't check LLVM_CONFIG here, because find_package(LLVM ...) also sets 11 - + # LLVM_CONFIG. 12 - + if (NOT LLVM_CONFIG_FOUND) 13 - + # Pull values from LLVMConfig.cmake. We can drop this once the llvm-config 14 - + # path is removed. 15 - + set(INCLUDE_DIRS ${LLVM_INCLUDE_DIRS}) 16 - + set(LLVM_OBJ_DIR "${LLVM_BINARY_DIR}") 17 - + # N.B. this is just a default value, the CACHE PATHs below can be overriden. 18 - + set(MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm") 19 - + set(TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}") 20 - + set(LIBRARY_DIR "${LLVM_LIBRARY_DIR}") 21 - + else() 22 - + set(INCLUDE_DIRS "${LLVM_BINARY_DIR}/include" "${MAIN_INCLUDE_DIR}") 23 - + endif() 24 - + 25 - set(LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed") 26 - set(LLVM_BINARY_DIR "${LLVM_BINARY_DIR}" CACHE PATH "Path to LLVM build tree") 27 - set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" CACHE PATH "Path to LLVM source tree") 28 diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake 29 index 75b0080f6715..c895b884cd27 100644 30 --- a/cmake/modules/AddClang.cmake ··· 48 add_header_target("utility-resource-headers" ${utility_files}) 49 50 get_clang_resource_dir(header_install_dir SUBDIR include) 51 - +set(header_install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${CLANG_VERSION_MAJOR}/include) 52 53 ############################################################# 54 # Install rules for the catch-all clang-resource-headers target
··· 1 diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake 2 index 75b0080f6715..c895b884cd27 100644 3 --- a/cmake/modules/AddClang.cmake ··· 21 add_header_target("utility-resource-headers" ${utility_files}) 22 23 get_clang_resource_dir(header_install_dir SUBDIR include) 24 + +set(header_install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION_MAJOR}/include) 25 26 ############################################################# 27 # Install rules for the catch-all clang-resource-headers target
+2 -3
pkgs/development/compilers/llvm/git/compiler-rt/default.nix
··· 87 88 patches = [ 89 ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config 90 - ./gnu-install-dirs.patch 91 # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the 92 # extra `/`. 93 ./normalize-var.patch 94 - # Prevent a compilation error on darwin 95 - ./darwin-targetconditionals.patch 96 # See: https://github.com/NixOS/nixpkgs/pull/186575 97 ../../common/compiler-rt/darwin-plistbuddy-workaround.patch 98 # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 ··· 111 substituteInPlace cmake/config-ix.cmake \ 112 --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' 113 '' + lib.optionalString (useLLVM && !haveLibc) '' 114 substituteInPlace lib/builtins/int_util.c \ 115 --replace "#include <stdlib.h>" "" 116 substituteInPlace lib/builtins/clear_cache.c \
··· 87 88 patches = [ 89 ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config 90 # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the 91 # extra `/`. 92 ./normalize-var.patch 93 # See: https://github.com/NixOS/nixpkgs/pull/186575 94 ../../common/compiler-rt/darwin-plistbuddy-workaround.patch 95 # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 ··· 108 substituteInPlace cmake/config-ix.cmake \ 109 --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' 110 '' + lib.optionalString (useLLVM && !haveLibc) '' 111 + substituteInPlace lib/builtins/aarch64/sme-libc-routines.c \ 112 + --replace "<stdlib.h>" "<stddef.h>" 113 substituteInPlace lib/builtins/int_util.c \ 114 --replace "#include <stdlib.h>" "" 115 substituteInPlace lib/builtins/clear_cache.c \
-20
pkgs/development/compilers/llvm/git/compiler-rt/gnu-install-dirs.patch
··· 1 - diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake 2 - index 8a6219568b3f..30ee68a47ccf 100644 3 - --- a/cmake/base-config-ix.cmake 4 - +++ b/cmake/base-config-ix.cmake 5 - @@ -100,13 +100,13 @@ endif() 6 - if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) 7 - set(COMPILER_RT_OUTPUT_LIBRARY_DIR 8 - ${COMPILER_RT_OUTPUT_DIR}/lib) 9 - - extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" lib) 10 - + extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}") 11 - set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH 12 - "Path where built compiler-rt libraries should be installed.") 13 - else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) 14 - set(COMPILER_RT_OUTPUT_LIBRARY_DIR 15 - ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) 16 - - extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "lib/${COMPILER_RT_OS_DIR}") 17 - + extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}/${COMPILER_RT_OS_DIR}") 18 - set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH 19 - "Path where built compiler-rt libraries should be installed.") 20 - endif()
···
+8 -3
pkgs/development/compilers/llvm/git/default.nix
··· 17 else pkgs.bintools 18 , darwin 19 # LLVM release information; specify one of these but not both: 20 - , gitRelease ? null 21 # i.e.: 22 # { 23 # version = /* i.e. "15.0.0" */; 24 # rev = /* commit SHA */; 25 - # rev-version = /* human readable version; i.e. "unstable-2022-26-07" */; 26 # sha256 = /* checksum for this release, can omit if specifying your own `monorepoSrc` */; 27 # } 28 - , officialRelease ? { version = "18.1.0-rc4"; sha256 = "sha256-fVpwewbjoPMPslIEZ+WAtaQ+YKc0XWGl8EbP/TbQb8o="; } 29 # i.e.: 30 # { 31 # version = /* i.e. "15.0.0" */;
··· 17 else pkgs.bintools 18 , darwin 19 # LLVM release information; specify one of these but not both: 20 + , gitRelease ? { 21 + version = "19.0.0-git"; 22 + rev = "65058a8d732c3c41664a4dad1a1ae2a504d5c98e"; 23 + rev-version = "19.0.0-unstable-2024-03-16"; 24 + sha256 = "sha256-xV33kx/8OZ2KLtaz25RmudDrlIX7nScauTykf87jyTE="; 25 + } 26 # i.e.: 27 # { 28 # version = /* i.e. "15.0.0" */; 29 # rev = /* commit SHA */; 30 + # rev-version = /* human readable version; i.e. "15.0.0-unstable-2022-07-26" */; 31 # sha256 = /* checksum for this release, can omit if specifying your own `monorepoSrc` */; 32 # } 33 + , officialRelease ? null 34 # i.e.: 35 # { 36 # version = /* i.e. "15.0.0" */;
+5 -17
pkgs/development/compilers/llvm/git/libcxx/default.nix
··· 1 { lib, stdenv, llvm_meta 2 - , monorepoSrc, runCommand, fetchpatch 3 , cmake, lndir, ninja, python3, fixDarwinDylibNames, version 4 , cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else null 5 , libcxxrt, libunwind ··· 19 # Note: useLLVM is likely false for Darwin but true under pkgsLLVM 20 useLLVM = stdenv.hostPlatform.useLLVM or false; 21 22 - cxxabiCMakeFlags = lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ 23 - "-DLIBCXXABI_USE_COMPILER_RT=ON" 24 - "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" 25 - ] ++ lib.optionals (lib.versionAtLeast version "18" && !(useLLVM && !stdenv.hostPlatform.isWasm)) [ 26 "-DLIBCXXABI_USE_LLVM_UNWINDER=OFF" 27 ] ++ lib.optionals stdenv.hostPlatform.isWasm [ 28 "-DLIBCXXABI_ENABLE_THREADS=OFF" 29 "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" ··· 87 patches = lib.optionals (stdenv.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13") [ 88 # https://github.com/llvm/llvm-project/issues/64226 89 ./0001-darwin-10.12-mbstate_t-fix.patch 90 - ] ++ lib.optionals (cxxabi == null && lib.versionAtLeast version "18") [ 91 - # Allow building libcxxabi alone when using LLVM unwinder 92 - (fetchpatch { 93 - url = "https://github.com/llvm/llvm-project/commit/77610dd10454e87bb387040d2b51100a17ac5755.patch"; 94 - revert = true; 95 - hash = "sha256-jFbC3vBY3nKfjknJ7UzaPyoy0iSYdD3+jUmOFeOaVcA="; 96 - }) 97 - (fetchpatch { 98 - url = "https://github.com/llvm/llvm-project/commit/48e5b5ea92674ded69b998cf35724d9012c0f57d.patch"; 99 - revert = true; 100 - hash = "sha256-WN63L4T3GxVozPZb6kx21AgNe4rwwSUOeeryIGsvQYY="; 101 - }) 102 ]; 103 104 postPatch = ''
··· 1 { lib, stdenv, llvm_meta 2 + , monorepoSrc, runCommand 3 , cmake, lndir, ninja, python3, fixDarwinDylibNames, version 4 , cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else null 5 , libcxxrt, libunwind ··· 19 # Note: useLLVM is likely false for Darwin but true under pkgsLLVM 20 useLLVM = stdenv.hostPlatform.useLLVM or false; 21 22 + cxxabiCMakeFlags = [ 23 "-DLIBCXXABI_USE_LLVM_UNWINDER=OFF" 24 + ] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ 25 + "-DLIBCXXABI_ADDITIONAL_LIBRARIES=unwind" 26 + "-DLIBCXXABI_USE_COMPILER_RT=ON" 27 ] ++ lib.optionals stdenv.hostPlatform.isWasm [ 28 "-DLIBCXXABI_ENABLE_THREADS=OFF" 29 "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" ··· 87 patches = lib.optionals (stdenv.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13") [ 88 # https://github.com/llvm/llvm-project/issues/64226 89 ./0001-darwin-10.12-mbstate_t-fix.patch 90 ]; 91 92 postPatch = ''
-9
pkgs/development/compilers/llvm/git/libunwind/default.nix
··· 27 28 sourceRoot = "${src.name}/runtimes"; 29 30 - prePatch = '' 31 - cd ../${pname} 32 - chmod -R u+w . 33 - ''; 34 - 35 - postPatch = '' 36 - cd ../runtimes 37 - ''; 38 - 39 postInstall = lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin) '' 40 # libcxxabi wants to link to libunwind_shared.so (?). 41 ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so
··· 27 28 sourceRoot = "${src.name}/runtimes"; 29 30 postInstall = lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin) '' 31 # libcxxabi wants to link to libunwind_shared.so (?). 32 ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so
+3 -3
pkgs/development/compilers/llvm/git/lld/default.nix
··· 24 25 sourceRoot = "${src.name}/${pname}"; 26 27 patches = [ 28 ./gnu-install-dirs.patch 29 ]; 30 - 31 - nativeBuildInputs = [ cmake ninja ]; 32 - buildInputs = [ libllvm libxml2 ]; 33 34 cmakeFlags = [ 35 "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/lld"
··· 24 25 sourceRoot = "${src.name}/${pname}"; 26 27 + nativeBuildInputs = [ cmake ninja ]; 28 + buildInputs = [ libllvm libxml2 ]; 29 + 30 patches = [ 31 ./gnu-install-dirs.patch 32 ]; 33 34 cmakeFlags = [ 35 "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/lld"
-31
pkgs/development/compilers/llvm/git/lld/gnu-install-dirs.patch
··· 1 - diff --git a/CMakeLists.txt b/CMakeLists.txt 2 - index 3d6225646fe6..9b5d0b15af13 100644 3 - --- a/CMakeLists.txt 4 - +++ b/CMakeLists.txt 5 - @@ -33,10 +33,22 @@ if(LLD_BUILT_STANDALONE) 6 - find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}") 7 - list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}") 8 - 9 - - # Turn into CACHE PATHs for overwriting 10 - - set(LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed") 11 - - set(LLVM_BINARY_DIR "${LLVM_BINARY_DIR}" CACHE PATH "Path to LLVM build tree") 12 - - set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" CACHE PATH "Path to LLVM source tree") 13 - + # We can't check LLVM_CONFIG here, because find_package(LLVM ...) also sets 14 - + # LLVM_CONFIG. 15 - + if (NOT LLVM_CONFIG_FOUND) 16 - + # Pull values from LLVMConfig.cmake. We can drop this once the llvm-config 17 - + # path is removed. 18 - + set(INCLUDE_DIRS ${LLVM_INCLUDE_DIRS}) 19 - + set(LLVM_OBJ_DIR "${LLVM_BINARY_DIR}") 20 - + # N.B. this is just a default value, the CACHE PATHs below can be overridden. 21 - + set(MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm") 22 - + else() 23 - + set(INCLUDE_DIRS "${LLVM_BINARY_DIR}/include" "${MAIN_INCLUDE_DIR}") 24 - + endif() 25 - + 26 - + set(LLVM_INCLUDE_DIRS ${INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed") 27 - + set(LLVM_BINARY_DIR "${LLVM_OBJ_ROOT}" CACHE PATH "Path to LLVM build tree") 28 - + set(LLVM_MAIN_SRC_DIR "${MAIN_SRC_DIR}" CACHE PATH "Path to LLVM source tree") 29 - 30 - find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR} 31 - NO_DEFAULT_PATH) 32 diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake 33 index d3924f7243d4..42a7cd62281c 100644 34 --- a/cmake/modules/AddLLD.cmake
··· 1 diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake 2 index d3924f7243d4..42a7cd62281c 100644 3 --- a/cmake/modules/AddLLD.cmake
+4 -1
pkgs/development/compilers/llvm/git/llvm/default.nix
··· 179 substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \ 180 --replace "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \ 181 --replace "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" "" 182 '' + optionalString (stdenv.isDarwin && stdenv.hostPlatform.isx86) '' 183 # This test fails on darwin x86_64 because `sw_vers` reports a different 184 # macOS version than what LLVM finds by reading ··· 382 --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "'"$lib"'")' 383 '' 384 + optionalString (stdenv.isDarwin && enableSharedLibraries) '' 385 - ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib 386 ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib 387 '' 388 + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
··· 179 substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \ 180 --replace "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \ 181 --replace "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" "" 182 + 183 + # fails when run in sandbox 184 + substituteInPlace unittests/Support/VirtualFileSystemTest.cpp \ 185 + --replace "PhysicalFileSystemWorkingDirFailure" "DISABLED_PhysicalFileSystemWorkingDirFailure" 186 '' + optionalString (stdenv.isDarwin && stdenv.hostPlatform.isx86) '' 187 # This test fails on darwin x86_64 because `sw_vers` reports a different 188 # macOS version than what LLVM finds by reading ··· 386 --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "'"$lib"'")' 387 '' 388 + optionalString (stdenv.isDarwin && enableSharedLibraries) '' 389 ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib 390 '' 391 + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
+3 -9
pkgs/development/compilers/llvm/git/llvm/gnu-install-dirs-polly.patch
··· 1 - This is the one remaining Polly install dirs related change that hasn't made it 2 - into upstream yet; previously this patch file also included: 3 - https://reviews.llvm.org/D117541 4 - 5 - diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake 6 - index 518a09b45a42..bd9d6f5542ad 100644 7 - --- a/tools/polly/cmake/polly_macros.cmake 8 - +++ b/tools/polly/cmake/polly_macros.cmake 9 - @@ -45,8 +45,8 @@ macro(add_polly_library name) 10 install(TARGETS ${name} 11 COMPONENT ${name} 12 EXPORT LLVMExports
··· 1 + --- a/tools/polly/cmake/polly_macros.cmake 2024-03-15 17:36:20.550893344 -0700 2 + +++ b/tools/polly/cmake/polly_macros.cmake 2024-03-15 17:37:06.277332960 -0700 3 + @@ -45,8 +45,8 @@ 4 install(TARGETS ${name} 5 COMPONENT ${name} 6 EXPORT LLVMExports
+5 -5
pkgs/development/compilers/llvm/git/llvm/gnu-install-dirs.patch
··· 40 if (APPLE) 41 set(_install_name_dir INSTALL_NAME_DIR "@rpath") 42 - set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) 43 - + set(_install_rpath "@loader_path/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) 44 elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND BUILD_SHARED_LIBS) 45 # $ORIGIN is not interpreted at link time by aix ld. 46 # Since BUILD_SHARED_LIBS is only recommended for use by developers, ··· 72 + # As noted in the differential above, an alternative solution is to have 73 + # all rdeps of nixpkgs' LLVM (that use the AddLLVM.cmake machinery) set 74 + # `CMAKE_INSTALL_RPATH`. 75 - + set(_build_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) 76 - + set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) 77 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") 78 set_property(TARGET ${name} APPEND_STRING PROPERTY 79 LINK_FLAGS " -Wl,-z,origin ") ··· 86 87 if( APPLE ) 88 - set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") 89 - + set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") 90 elseif( UNIX ) 91 - set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") 92 - + set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") 93 endif() 94 list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") 95
··· 40 if (APPLE) 41 set(_install_name_dir INSTALL_NAME_DIR "@rpath") 42 - set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) 43 + + set(_install_rpath ${extra_libdir}) 44 elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND BUILD_SHARED_LIBS) 45 # $ORIGIN is not interpreted at link time by aix ld. 46 # Since BUILD_SHARED_LIBS is only recommended for use by developers, ··· 72 + # As noted in the differential above, an alternative solution is to have 73 + # all rdeps of nixpkgs' LLVM (that use the AddLLVM.cmake machinery) set 74 + # `CMAKE_INSTALL_RPATH`. 75 + + set(_build_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) 76 + + set(_install_rpath ${extra_libdir}) 77 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") 78 set_property(TARGET ${name} APPEND_STRING PROPERTY 79 LINK_FLAGS " -Wl,-z,origin ") ··· 86 87 if( APPLE ) 88 - set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") 89 + + set(ocaml_rpath ${LLVM_LIBRARY_DIR}) 90 elseif( UNIX ) 91 - set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") 92 + + set(ocaml_rpath ${LLVM_LIBRARY_DIR}) 93 endif() 94 list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") 95
+6 -11
pkgs/development/compilers/llvm/git/llvm/lit-shell-script-runner-set-dyld-library-path.patch
··· 1 - diff --git a/utils/lit/lit/TestRunner.py b/utils/lit/lit/TestRunner.py 2 - index 0242e0b75af3..d732011306f7 100644 3 - --- a/utils/lit/lit/TestRunner.py 4 - +++ b/utils/lit/lit/TestRunner.py 5 - @@ -1029,6 +1029,12 @@ def executeScript(test, litConfig, tmpBase, commands, cwd): 6 - f.write('@echo off\n') 7 - f.write('\n@if %ERRORLEVEL% NEQ 0 EXIT\n'.join(commands)) 8 else: 9 - + # This env var is *purged* when invoking subprocesses so we have to 10 - + # manually set it from within the bash script in order for the commands 11 - + # in run lines to see this var: 12 + if "DYLD_LIBRARY_PATH" in test.config.environment: 13 + f.write(f'export DYLD_LIBRARY_PATH="{test.config.environment["DYLD_LIBRARY_PATH"]}"\n') 14 + 15 for i, ln in enumerate(commands): 16 - match = re.match(kPdbgRegex, ln) 17 if match:
··· 1 + --- a/utils/lit/lit/TestRunner.py 2024-03-15 17:27:53.170780798 -0700 2 + +++ b/utils/lit/lit/TestRunner.py 2024-03-15 17:28:43.277447791 -0700 3 + @@ -1183,6 +1183,9 @@ 4 + f.write("@echo on\n") 5 + f.write("\n@if %ERRORLEVEL% NEQ 0 EXIT\n".join(commands)) 6 else: 7 + if "DYLD_LIBRARY_PATH" in test.config.environment: 8 + f.write(f'export DYLD_LIBRARY_PATH="{test.config.environment["DYLD_LIBRARY_PATH"]}"\n') 9 + 10 for i, ln in enumerate(commands): 11 + match = re.fullmatch(kPdbgRegex, ln) 12 if match:
-1
pkgs/development/compilers/llvm/git/openmp/default.nix
··· 29 30 patches = [ 31 ./fix-find-tool.patch 32 - ./gnu-install-dirs.patch 33 ./run-lit-directly.patch 34 ]; 35
··· 29 30 patches = [ 31 ./fix-find-tool.patch 32 ./run-lit-directly.patch 33 ]; 34
-22
pkgs/development/compilers/llvm/git/openmp/gnu-install-dirs.patch
··· 1 - diff --git a/CMakeLists.txt b/CMakeLists.txt 2 - index b6ddbe90516d..311ab1d50e7f 100644 3 - --- a/CMakeLists.txt 4 - +++ b/CMakeLists.txt 5 - @@ -29,7 +29,7 @@ if (OPENMP_STANDALONE_BUILD) 6 - set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING 7 - "Suffix of lib installation directory, e.g. 64 => lib64") 8 - # Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR. 9 - - set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}" CACHE STRING 10 - + set(OPENMP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}${OPENMP_LIBDIR_SUFFIX}" CACHE STRING 11 - "Path where built OpenMP libraries should be installed.") 12 - 13 - # Group test settings. 14 - @@ -47,7 +47,7 @@ if (OPENMP_STANDALONE_BUILD) 15 - else() 16 - set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR}) 17 - # If building in tree, we honor the same install suffix LLVM uses. 18 - - set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}" CACHE STRING 19 - + set(OPENMP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" CACHE STRING 20 - "Path where built OpenMP libraries should be installed.") 21 - 22 - if (NOT MSVC)
···
+5 -5
pkgs/development/compilers/llvm/update-git.py
··· 43 """Get the current revision of llvmPackages_git.""" 44 with open(DEFAULT_NIX) as f: 45 for line in f: 46 - rev = re.search(r'^ rev = "(.*)";', line) 47 if rev: 48 return rev.group(1) 49 sys.exit(1) ··· 75 print('Updating default.nix...') 76 with fileinput.FileInput(DEFAULT_NIX, inplace=True) as f: 77 for line in f: 78 - if match := re.search(r'^ rev-version = "unstable-(.+)";', line): 79 old_date = match.group(1) 80 - result = re.sub(r'^ release_version = ".+";', f' release_version = "{release_version}";', line) 81 - result = re.sub(r'^ rev = ".*";', f' rev = "{commit["sha"]}";', result) 82 - result = re.sub(r'^ rev-version = ".+";', f' rev-version = "{version}";', result) 83 result = re.sub(r'^ sha256 = ".+";', f' sha256 = "{hash}";', result) 84 print(result, end='') 85 # Commit the result:
··· 43 """Get the current revision of llvmPackages_git.""" 44 with open(DEFAULT_NIX) as f: 45 for line in f: 46 + rev = re.search(r'^ rev = "(.*)";', line) 47 if rev: 48 return rev.group(1) 49 sys.exit(1) ··· 75 print('Updating default.nix...') 76 with fileinput.FileInput(DEFAULT_NIX, inplace=True) as f: 77 for line in f: 78 + if match := re.search(r'^ rev-version = "unstable-(.+)";', line): 79 old_date = match.group(1) 80 + result = re.sub(r'^ version = ".+";', f' version = "{release_version}";', line) 81 + result = re.sub(r'^ rev = ".*";', f' rev = "{commit["sha"]}";', result) 82 + result = re.sub(r'^ rev-version = ".+";', f' rev-version = "{version}";', result) 83 result = re.sub(r'^ sha256 = ".+";', f' sha256 = "{hash}";', result) 84 print(result, end='') 85 # Commit the result:
+25
pkgs/top-level/all-packages.nix
··· 16527 targetLlvm = targetPackages.llvmPackages_17.llvm or llvmPackages_17.llvm; 16528 })); 16529 16530 lorri = callPackage ../tools/misc/lorri { 16531 inherit (darwin.apple_sdk.frameworks) CoreServices Security; 16532 };
··· 16527 targetLlvm = targetPackages.llvmPackages_17.llvm or llvmPackages_17.llvm; 16528 })); 16529 16530 + inherit 16531 + (rec { 16532 + llvmPackages_18 = recurseIntoAttrs (callPackage ../development/compilers/llvm/18 ({ 16533 + inherit (stdenvAdapters) overrideCC; 16534 + buildLlvmTools = buildPackages.llvmPackages_18.tools; 16535 + targetLlvmLibraries = targetPackages.llvmPackages_18.libraries or llvmPackages_18.libraries; 16536 + targetLlvm = targetPackages.llvmPackages_18.llvm or llvmPackages_18.llvm; 16537 + })); 16538 + 16539 + clang_18 = llvmPackages_18.clang; 16540 + lld_18 = llvmPackages_18.lld; 16541 + lldb_18 = llvmPackages_18.lldb; 16542 + llvm_18 = llvmPackages_18.llvm; 16543 + 16544 + clang-tools_18 = callPackage ../development/tools/clang-tools { 16545 + llvmPackages = llvmPackages_18; 16546 + }; 16547 + }) 16548 + llvmPackages_18 16549 + clang_18 16550 + lld_18 16551 + lldb_18 16552 + llvm_18 16553 + clang-tools_18; 16554 + 16555 lorri = callPackage ../tools/misc/lorri { 16556 inherit (darwin.apple_sdk.frameworks) CoreServices Security; 16557 };