diff --git a/pkgs/development/compilers/llvm/common/bintools.nix b/pkgs/development/compilers/llvm/common/bintools.nix index 5cd8ecc251d9c..24af8c618e91e 100644 --- a/pkgs/development/compilers/llvm/common/bintools.nix +++ b/pkgs/development/compilers/llvm/common/bintools.nix @@ -1,50 +1,63 @@ -{ lib, runCommand, stdenv, llvm, lld, version, release_version }: +{ + lib, + runCommand, + stdenv, + llvm, + lld, + version, + release_version, +}: let - targetPrefix = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) "${stdenv.targetPlatform.config}-"; + targetPrefix = lib.optionalString ( + stdenv.hostPlatform != stdenv.targetPlatform + ) "${stdenv.targetPlatform.config}-"; in runCommand "llvm-binutils-${version}" -{ - preferLocalBuild = true; - passthru = { - isLLVM = true; - inherit targetPrefix; - inherit llvm lld; - }; -} - ('' - mkdir -p $out/bin - for prog in ${lld}/bin/*; do - ln -s $prog $out/bin/${targetPrefix}$(basename $prog) - done - for prog in ${llvm}/bin/*; do - ln -sf $prog $out/bin/${targetPrefix}$(basename $prog) - done + { + preferLocalBuild = true; + passthru = { + isLLVM = true; + inherit targetPrefix; + inherit llvm lld; + }; + } + ( + '' + mkdir -p $out/bin + for prog in ${lld}/bin/*; do + ln -s $prog $out/bin/${targetPrefix}$(basename $prog) + done + for prog in ${llvm}/bin/*; do + ln -sf $prog $out/bin/${targetPrefix}$(basename $prog) + done - llvmBin="${llvm}/bin" + llvmBin="${llvm}/bin" - ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}ar - ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}dlltool - ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}ranlib - ln -s $llvmBin/llvm-cxxfilt $out/bin/${targetPrefix}c++filt - ln -s $llvmBin/llvm-dwp $out/bin/${targetPrefix}dwp - ln -s $llvmBin/llvm-nm $out/bin/${targetPrefix}nm - ln -s $llvmBin/llvm-objcopy $out/bin/${targetPrefix}objcopy - ln -s $llvmBin/llvm-objcopy $out/bin/${targetPrefix}strip - ln -s $llvmBin/llvm-objdump $out/bin/${targetPrefix}objdump - ln -s $llvmBin/llvm-readobj $out/bin/${targetPrefix}readelf - ln -s $llvmBin/llvm-size $out/bin/${targetPrefix}size - ln -s $llvmBin/llvm-strings $out/bin/${targetPrefix}strings - ln -s $llvmBin/llvm-symbolizer $out/bin/${targetPrefix}addr2line + ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}ar + ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}dlltool + ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}ranlib + ln -s $llvmBin/llvm-cxxfilt $out/bin/${targetPrefix}c++filt + ln -s $llvmBin/llvm-dwp $out/bin/${targetPrefix}dwp + ln -s $llvmBin/llvm-nm $out/bin/${targetPrefix}nm + ln -s $llvmBin/llvm-objcopy $out/bin/${targetPrefix}objcopy + ln -s $llvmBin/llvm-objcopy $out/bin/${targetPrefix}strip + ln -s $llvmBin/llvm-objdump $out/bin/${targetPrefix}objdump + ln -s $llvmBin/llvm-readobj $out/bin/${targetPrefix}readelf + ln -s $llvmBin/llvm-size $out/bin/${targetPrefix}size + ln -s $llvmBin/llvm-strings $out/bin/${targetPrefix}strings + ln -s $llvmBin/llvm-symbolizer $out/bin/${targetPrefix}addr2line - if [ -e "$llvmBin/llvm-debuginfod" ]; then - ln -s $llvmBin/llvm-debuginfod $out/bin/${targetPrefix}debuginfod - ln -s $llvmBin/llvm-debuginfod-find $out/bin/${targetPrefix}debuginfod-find - fi + if [ -e "$llvmBin/llvm-debuginfod" ]; then + ln -s $llvmBin/llvm-debuginfod $out/bin/${targetPrefix}debuginfod + ln -s $llvmBin/llvm-debuginfod-find $out/bin/${targetPrefix}debuginfod-find + fi - ln -s ${lld}/bin/lld $out/bin/${targetPrefix}ld + ln -s ${lld}/bin/lld $out/bin/${targetPrefix}ld - # Only >=13 show GNU windres compatible in help - '' + lib.optionalString (lib.versionAtLeast release_version "13") '' - ln -s $llvmBin/llvm-rc $out/bin/${targetPrefix}windres - '') + # Only >=13 show GNU windres compatible in help + '' + + lib.optionalString (lib.versionAtLeast release_version "13") '' + ln -s $llvmBin/llvm-rc $out/bin/${targetPrefix}windres + '' + ) diff --git a/pkgs/development/compilers/llvm/common/clang/default.nix b/pkgs/development/compilers/llvm/common/clang/default.nix index 7afa284c25a2d..cdea700b2dded 100644 --- a/pkgs/development/compilers/llvm/common/clang/default.nix +++ b/pkgs/development/compilers/llvm/common/clang/default.nix @@ -1,207 +1,265 @@ -{ lib -, stdenv -, llvm_meta -, patches ? [] -, src ? null -, monorepoSrc ? null -, runCommand -, cmake -, ninja -, libxml2 -, libllvm -, release_version -, version -, python3 -, buildLlvmTools -, fixDarwinDylibNames -, enableManpages ? false -, devExtraCmakeFlags ? [] +{ + lib, + stdenv, + llvm_meta, + patches ? [ ], + src ? null, + monorepoSrc ? null, + runCommand, + cmake, + ninja, + libxml2, + libllvm, + release_version, + version, + python3, + buildLlvmTools, + fixDarwinDylibNames, + enableManpages ? false, + devExtraCmakeFlags ? [ ], }: let pname = "clang"; - src' = if monorepoSrc != null then - runCommand "${pname}-src-${version}" { inherit (monorepoSrc) passthru; } ('' - mkdir -p "$out" - '' + lib.optionalString (lib.versionAtLeast release_version "14") '' - cp -r ${monorepoSrc}/cmake "$out" - '' + '' - cp -r ${monorepoSrc}/${pname} "$out" - cp -r ${monorepoSrc}/clang-tools-extra "$out" - '') else src; - - self = stdenv.mkDerivation (finalAttrs: rec { - inherit pname version patches; - - src = src'; - - sourceRoot = "${src.name}/${pname}"; - - nativeBuildInputs = [ cmake ] - ++ (lib.optional (lib.versionAtLeast release_version "15") ninja) - ++ [ python3 ] - ++ lib.optional (lib.versionAtLeast version "18" && enableManpages) python3.pkgs.myst-parser - ++ lib.optional enableManpages python3.pkgs.sphinx - ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; - - buildInputs = [ libxml2 libllvm ]; - - cmakeFlags = (lib.optionals (lib.versionAtLeast release_version "15") [ - "-DCLANG_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/clang" - ]) ++ [ - "-DCLANGD_BUILD_XPC=OFF" - "-DLLVM_ENABLE_RTTI=ON" - ] ++ lib.optionals (lib.versionAtLeast release_version "17") [ - "-DLLVM_INCLUDE_TESTS=OFF" - ] ++ lib.optionals enableManpages [ - "-DCLANG_INCLUDE_DOCS=ON" - "-DLLVM_ENABLE_SPHINX=ON" - "-DSPHINX_OUTPUT_MAN=ON" - "-DSPHINX_OUTPUT_HTML=OFF" - "-DSPHINX_WARNINGS_AS_ERRORS=OFF" - ] ++ [ - "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.tblgen}/bin/llvm-tblgen" - "-DCLANG_TABLEGEN=${buildLlvmTools.tblgen}/bin/clang-tblgen" - ] ++ lib.optionals (lib.versionAtLeast release_version "15") [ - # Added in LLVM15: - # `clang-tidy-confusable-chars-gen`: https://github.com/llvm/llvm-project/commit/c3574ef739fbfcc59d405985a3a4fa6f4619ecdb - # `clang-pseudo-gen`: https://github.com/llvm/llvm-project/commit/cd2292ef824591cc34cc299910a3098545c840c7 - "-DCLANG_TIDY_CONFUSABLE_CHARS_GEN=${buildLlvmTools.tblgen}/bin/clang-tidy-confusable-chars-gen" - ] ++ lib.optionals (lib.versionOlder release_version "20") [ - # clang-pseudo removed in LLVM20: https://github.com/llvm/llvm-project/commit/ed8f78827895050442f544edef2933a60d4a7935 - "-DCLANG_PSEUDO_GEN=${buildLlvmTools.tblgen}/bin/clang-pseudo-gen" - ] ++ lib.optional (lib.versionAtLeast release_version "20") "-DLLVM_DIR=${libllvm.dev}/lib/cmake/llvm" - ++ devExtraCmakeFlags; - - postPatch = '' - # Make sure clang passes the correct location of libLTO to ld64 - substituteInPlace lib/Driver/ToolChains/Darwin.cpp \ - --replace-fail 'StringRef P = llvm::sys::path::parent_path(D.Dir);' 'StringRef P = "${lib.getLib libllvm}";' - (cd tools && ln -s ../../clang-tools-extra extra) - '' - + lib.optionalString stdenv.hostPlatform.isMusl '' - sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp - ''; - - outputs = [ "out" "lib" "dev" "python" ]; - - postInstall = '' - ln -sv $out/bin/clang $out/bin/cpp - '' + (lib.optionalString (lib.versions.major release_version == "17") '' - - mkdir -p $lib/lib/clang - mv $lib/lib/17 $lib/lib/clang/17 - '') + (lib.optionalString (lib.versionAtLeast release_version "19") '' - mv $out/lib/clang $lib/lib/clang - '') + '' - - # Move libclang to 'lib' output - moveToOutput "lib/libclang.*" "$lib" - moveToOutput "lib/libclang-cpp.*" "$lib" - '' + (if lib.versionOlder release_version "15" then '' - mkdir -p $python/bin $python/share/{clang,scan-view} - '' else '' - mkdir -p $python/bin $python/share/clang/ - '') + '' - mv $out/bin/{git-clang-format,scan-view} $python/bin - if [ -e $out/bin/set-xcode-analyzer ]; then - mv $out/bin/set-xcode-analyzer $python/bin - fi - mv $out/share/clang/*.py $python/share/clang - '' + (lib.optionalString (lib.versionOlder release_version "15") '' - mv $out/share/scan-view/*.py $python/share/scan-view - '') + '' - rm $out/bin/c-index-test - patchShebangs $python/bin - - mkdir -p $dev/bin - '' + (if lib.versionOlder release_version "15" then '' - cp bin/clang-tblgen $dev/bin - '' else if lib.versionOlder release_version "20" then '' - cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen,clang-pseudo-gen} $dev/bin - '' else '' - cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen} $dev/bin - ''); - - passthru = { - inherit libllvm; - isClang = true; - hardeningUnsupportedFlagsByTargetPlatform = targetPlatform: - [ "fortify3" ] - ++ lib.optional ( - (lib.versionOlder release_version "7") - || !targetPlatform.isLinux - || !targetPlatform.isx86_64 - ) "shadowstack" - ++ lib.optional ( - (lib.versionOlder release_version "8") - || !targetPlatform.isAarch64 - || !targetPlatform.isLinux - ) "pacret" - ++ lib.optional ( - (lib.versionOlder release_version "11") - || (targetPlatform.isAarch64 && (lib.versionOlder release_version "18.1")) - || (targetPlatform.isFreeBSD && (lib.versionOlder release_version "15")) - || !(targetPlatform.isLinux || targetPlatform.isFreeBSD) - || !( - targetPlatform.isx86 - || targetPlatform.isPower64 - || targetPlatform.isS390x - || targetPlatform.isAarch64 - ) - ) "stackclashprotection" - ++ lib.optional ( - (lib.versionOlder release_version "15") - || !(targetPlatform.isx86_64 || targetPlatform.isAarch64) - ) "zerocallusedregs" - ++ (finalAttrs.passthru.hardeningUnsupportedFlags or []); - }; - - meta = llvm_meta // { - homepage = "https://clang.llvm.org/"; - description = "C language family frontend for LLVM"; - longDescription = '' - The Clang project provides a language front-end and tooling - infrastructure for languages in the C language family (C, C++, Objective - C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. - It aims to deliver amazingly fast compiles, extremely useful error and - warning messages and to provide a platform for building great source - level tools. The Clang Static Analyzer and clang-tidy are tools that - automatically find bugs in your code, and are great examples of the sort - of tools that can be built using the Clang frontend as a library to - parse C/C++ code. - ''; - mainProgram = "clang"; - }; - } // lib.optionalAttrs enableManpages ({ - pname = "clang-manpages"; - - installPhase = '' - mkdir -p $out/share/man/man1 - # Manually install clang manpage - cp docs/man/*.1 $out/share/man/man1/ - ''; - - outputs = [ "out" ]; - - doCheck = false; - - meta = llvm_meta // { - description = "man page for Clang ${version}"; - }; - } // (if lib.versionOlder release_version "15" then { - buildPhase = '' - make docs-clang-man - ''; - } else { - ninjaFlags = [ "docs-clang-man" ]; - })) - // (lib.optionalAttrs (lib.versionAtLeast release_version "15") { - env = lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform && !stdenv.hostPlatform.useLLVM) { - # The following warning is triggered with (at least) gcc >= - # 12, but appears to occur only for cross compiles. - NIX_CFLAGS_COMPILE = "-Wno-maybe-uninitialized"; - }; - })); -in self + src' = + if monorepoSrc != null then + runCommand "${pname}-src-${version}" { inherit (monorepoSrc) passthru; } ( + '' + mkdir -p "$out" + '' + + lib.optionalString (lib.versionAtLeast release_version "14") '' + cp -r ${monorepoSrc}/cmake "$out" + '' + + '' + cp -r ${monorepoSrc}/${pname} "$out" + cp -r ${monorepoSrc}/clang-tools-extra "$out" + '' + ) + else + src; + + self = stdenv.mkDerivation ( + finalAttrs: + rec { + inherit pname version patches; + + src = src'; + + sourceRoot = "${src.name}/${pname}"; + + nativeBuildInputs = + [ cmake ] + ++ (lib.optional (lib.versionAtLeast release_version "15") ninja) + ++ [ python3 ] + ++ lib.optional (lib.versionAtLeast version "18" && enableManpages) python3.pkgs.myst-parser + ++ lib.optional enableManpages python3.pkgs.sphinx + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ + libxml2 + libllvm + ]; + + cmakeFlags = + (lib.optionals (lib.versionAtLeast release_version "15") [ + "-DCLANG_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/clang" + ]) + ++ [ + "-DCLANGD_BUILD_XPC=OFF" + "-DLLVM_ENABLE_RTTI=ON" + ] + ++ lib.optionals (lib.versionAtLeast release_version "17") [ + "-DLLVM_INCLUDE_TESTS=OFF" + ] + ++ lib.optionals enableManpages [ + "-DCLANG_INCLUDE_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] + ++ [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.tblgen}/bin/llvm-tblgen" + "-DCLANG_TABLEGEN=${buildLlvmTools.tblgen}/bin/clang-tblgen" + ] + ++ lib.optionals (lib.versionAtLeast release_version "15") [ + # Added in LLVM15: + # `clang-tidy-confusable-chars-gen`: https://github.com/llvm/llvm-project/commit/c3574ef739fbfcc59d405985a3a4fa6f4619ecdb + # `clang-pseudo-gen`: https://github.com/llvm/llvm-project/commit/cd2292ef824591cc34cc299910a3098545c840c7 + "-DCLANG_TIDY_CONFUSABLE_CHARS_GEN=${buildLlvmTools.tblgen}/bin/clang-tidy-confusable-chars-gen" + ] + ++ lib.optionals (lib.versionOlder release_version "20") [ + # clang-pseudo removed in LLVM20: https://github.com/llvm/llvm-project/commit/ed8f78827895050442f544edef2933a60d4a7935 + "-DCLANG_PSEUDO_GEN=${buildLlvmTools.tblgen}/bin/clang-pseudo-gen" + ] + ++ lib.optional (lib.versionAtLeast release_version "20") "-DLLVM_DIR=${libllvm.dev}/lib/cmake/llvm" + ++ devExtraCmakeFlags; + + postPatch = + '' + # Make sure clang passes the correct location of libLTO to ld64 + substituteInPlace lib/Driver/ToolChains/Darwin.cpp \ + --replace-fail 'StringRef P = llvm::sys::path::parent_path(D.Dir);' 'StringRef P = "${lib.getLib libllvm}";' + (cd tools && ln -s ../../clang-tools-extra extra) + '' + + lib.optionalString stdenv.hostPlatform.isMusl '' + sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp + ''; + + outputs = [ + "out" + "lib" + "dev" + "python" + ]; + + postInstall = + '' + ln -sv $out/bin/clang $out/bin/cpp + '' + + (lib.optionalString (lib.versions.major release_version == "17") '' + + mkdir -p $lib/lib/clang + mv $lib/lib/17 $lib/lib/clang/17 + '') + + (lib.optionalString (lib.versionAtLeast release_version "19") '' + mv $out/lib/clang $lib/lib/clang + '') + + '' + + # Move libclang to 'lib' output + moveToOutput "lib/libclang.*" "$lib" + moveToOutput "lib/libclang-cpp.*" "$lib" + '' + + ( + if lib.versionOlder release_version "15" then + '' + mkdir -p $python/bin $python/share/{clang,scan-view} + '' + else + '' + mkdir -p $python/bin $python/share/clang/ + '' + ) + + '' + mv $out/bin/{git-clang-format,scan-view} $python/bin + if [ -e $out/bin/set-xcode-analyzer ]; then + mv $out/bin/set-xcode-analyzer $python/bin + fi + mv $out/share/clang/*.py $python/share/clang + '' + + (lib.optionalString (lib.versionOlder release_version "15") '' + mv $out/share/scan-view/*.py $python/share/scan-view + '') + + '' + rm $out/bin/c-index-test + patchShebangs $python/bin + + mkdir -p $dev/bin + '' + + ( + if lib.versionOlder release_version "15" then + '' + cp bin/clang-tblgen $dev/bin + '' + else if lib.versionOlder release_version "20" then + '' + cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen,clang-pseudo-gen} $dev/bin + '' + else + '' + cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen} $dev/bin + '' + ); + + passthru = { + inherit libllvm; + isClang = true; + hardeningUnsupportedFlagsByTargetPlatform = + targetPlatform: + [ "fortify3" ] + ++ lib.optional ( + (lib.versionOlder release_version "7") || !targetPlatform.isLinux || !targetPlatform.isx86_64 + ) "shadowstack" + ++ lib.optional ( + (lib.versionOlder release_version "8") || !targetPlatform.isAarch64 || !targetPlatform.isLinux + ) "pacret" + ++ lib.optional ( + (lib.versionOlder release_version "11") + || (targetPlatform.isAarch64 && (lib.versionOlder release_version "18.1")) + || (targetPlatform.isFreeBSD && (lib.versionOlder release_version "15")) + || !(targetPlatform.isLinux || targetPlatform.isFreeBSD) + || !( + targetPlatform.isx86 + || targetPlatform.isPower64 + || targetPlatform.isS390x + || targetPlatform.isAarch64 + ) + ) "stackclashprotection" + ++ lib.optional ( + (lib.versionOlder release_version "15") || !(targetPlatform.isx86_64 || targetPlatform.isAarch64) + ) "zerocallusedregs" + ++ (finalAttrs.passthru.hardeningUnsupportedFlags or [ ]); + }; + + meta = llvm_meta // { + homepage = "https://clang.llvm.org/"; + description = "C language family frontend for LLVM"; + longDescription = '' + The Clang project provides a language front-end and tooling + infrastructure for languages in the C language family (C, C++, Objective + C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. + It aims to deliver amazingly fast compiles, extremely useful error and + warning messages and to provide a platform for building great source + level tools. The Clang Static Analyzer and clang-tidy are tools that + automatically find bugs in your code, and are great examples of the sort + of tools that can be built using the Clang frontend as a library to + parse C/C++ code. + ''; + mainProgram = "clang"; + }; + } + // lib.optionalAttrs enableManpages ( + { + pname = "clang-manpages"; + + installPhase = '' + mkdir -p $out/share/man/man1 + # Manually install clang manpage + cp docs/man/*.1 $out/share/man/man1/ + ''; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man page for Clang ${version}"; + }; + } + // ( + if lib.versionOlder release_version "15" then + { + buildPhase = '' + make docs-clang-man + ''; + } + else + { + ninjaFlags = [ "docs-clang-man" ]; + } + ) + ) + // (lib.optionalAttrs (lib.versionAtLeast release_version "15") { + env = + lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform && !stdenv.hostPlatform.useLLVM) + { + # The following warning is triggered with (at least) gcc >= + # 12, but appears to occur only for cross compiles. + NIX_CFLAGS_COMPILE = "-Wno-maybe-uninitialized"; + }; + }) + ); +in +self diff --git a/pkgs/development/compilers/llvm/common/common-let.nix b/pkgs/development/compilers/llvm/common/common-let.nix index a33d8db3ad489..e616a1c4d3672 100644 --- a/pkgs/development/compilers/llvm/common/common-let.nix +++ b/pkgs/development/compilers/llvm/common/common-let.nix @@ -1,48 +1,52 @@ -{ lib -, fetchFromGitHub ? null -, release_version ? null -, gitRelease ? null -, officialRelease ? null -, monorepoSrc' ? null -, version ? null, +{ + lib, + fetchFromGitHub ? null, + release_version ? null, + gitRelease ? null, + officialRelease ? null, + monorepoSrc' ? null, + version ? null, }@args: rec { llvm_meta = { - license = with lib.licenses; [ ncsa ] ++ - # Contributions after June 1st, 2024 are only licensed under asl20-llvm: - # https://github.com/llvm/llvm-project/pull/92394 - lib.optional (lib.versionAtLeast release_version "19") asl20-llvm; + license = + with lib.licenses; + [ ncsa ] + ++ + # Contributions after June 1st, 2024 are only licensed under asl20-llvm: + # https://github.com/llvm/llvm-project/pull/92394 + lib.optional (lib.versionAtLeast release_version "19") asl20-llvm; maintainers = lib.teams.llvm.members; # See llvm/cmake/config-ix.cmake. platforms = - lib.platforms.aarch64 ++ - lib.platforms.arm ++ - lib.platforms.mips ++ - lib.platforms.power ++ - lib.platforms.s390x ++ - lib.platforms.wasi ++ - lib.platforms.x86 ++ - lib.optionals (lib.versionAtLeast release_version "7") lib.platforms.riscv ++ - lib.optionals (lib.versionAtLeast release_version "14") lib.platforms.m68k ++ - lib.optionals (lib.versionAtLeast release_version "16") lib.platforms.loongarch64; + lib.platforms.aarch64 + ++ lib.platforms.arm + ++ lib.platforms.mips + ++ lib.platforms.power + ++ lib.platforms.s390x + ++ lib.platforms.wasi + ++ lib.platforms.x86 + ++ lib.optionals (lib.versionAtLeast release_version "7") lib.platforms.riscv + ++ lib.optionals (lib.versionAtLeast release_version "14") lib.platforms.m68k + ++ lib.optionals (lib.versionAtLeast release_version "16") lib.platforms.loongarch64; }; releaseInfo = - if gitRelease != null then rec { - original = gitRelease; - release_version = args.version or original.version; - version = gitRelease.rev-version; - } else rec { - original = officialRelease; - release_version = args.version or original.version; - version = - if original ? candidate then - "${release_version}-${original.candidate}" - else - release_version; - }; + if gitRelease != null then + rec { + original = gitRelease; + release_version = args.version or original.version; + version = gitRelease.rev-version; + } + else + rec { + original = officialRelease; + release_version = args.version or original.version; + version = + if original ? candidate then "${release_version}-${original.candidate}" else release_version; + }; monorepoSrc = if monorepoSrc' != null then @@ -50,11 +54,7 @@ rec { else let sha256 = releaseInfo.original.sha256; - rev = - if gitRelease != null then - gitRelease.rev - else - "llvmorg-${releaseInfo.version}"; + rev = if gitRelease != null then gitRelease.rev else "llvmorg-${releaseInfo.version}"; in fetchFromGitHub rec { owner = "llvm"; diff --git a/pkgs/development/compilers/llvm/common/compiler-rt/default.nix b/pkgs/development/compilers/llvm/common/compiler-rt/default.nix index f72af0f085567..cd821dbe717ba 100644 --- a/pkgs/development/compilers/llvm/common/compiler-rt/default.nix +++ b/pkgs/development/compilers/llvm/common/compiler-rt/default.nix @@ -1,34 +1,35 @@ -{ lib -, stdenv -, llvm_meta -, release_version -, version -, patches ? [] -, src ? null -, monorepoSrc ? null -, runCommand -, cmake -, ninja -, python3 -, libllvm -, jq -, libcxx -, linuxHeaders -, freebsd -, libxcrypt - -# Some platforms have switched to using compiler-rt, but still want a -# libgcc.a for ABI compat purposes. The use case would be old code that -# expects to link `-lgcc` but doesn't care exactly what its contents -# are, so long as it provides some builtins. -, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD - -# In recent releases, the compiler-rt build seems to produce -# many `libclang_rt*` libraries, but not a single unified -# `libcompiler_rt` library, at least under certain configurations. Some -# platforms stil expect this, however, so we symlink one into place. -, forceLinkCompilerRt ? stdenv.hostPlatform.isOpenBSD -, devExtraCmakeFlags ? [] +{ + lib, + stdenv, + llvm_meta, + release_version, + version, + patches ? [ ], + src ? null, + monorepoSrc ? null, + runCommand, + cmake, + ninja, + python3, + libllvm, + jq, + libcxx, + linuxHeaders, + freebsd, + libxcrypt, + + # Some platforms have switched to using compiler-rt, but still want a + # libgcc.a for ABI compat purposes. The use case would be old code that + # expects to link `-lgcc` but doesn't care exactly what its contents + # are, so long as it provides some builtins. + doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD, + + # In recent releases, the compiler-rt build seems to produce + # many `libclang_rt*` libraries, but not a single unified + # `libcompiler_rt` library, at least under certain configurations. Some + # platforms stil expect this, however, so we symlink one into place. + forceLinkCompilerRt ? stdenv.hostPlatform.isOpenBSD, + devExtraCmakeFlags ? [ ], }: let @@ -39,21 +40,31 @@ let # TODO: Make this account for GCC having libstdcxx, which will help # use clean up the `cmakeFlags` rats nest below. haveLibcxx = stdenv.cc.libcxx != null; - isDarwinStatic = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic && lib.versionAtLeast release_version "16"; + isDarwinStatic = + stdenv.hostPlatform.isDarwin + && stdenv.hostPlatform.isStatic + && lib.versionAtLeast release_version "16"; inherit (stdenv.hostPlatform) isMusl isAarch64 isWindows; noSanitizers = !haveLibc || bareMetal || isMusl || isDarwinStatic || isWindows; baseName = "compiler-rt"; pname = baseName + lib.optionalString (haveLibc) "-libc"; - src' = if monorepoSrc != null then - runCommand "${baseName}-src-${version}" { inherit (monorepoSrc) passthru; } ('' - mkdir -p "$out" - '' + lib.optionalString (lib.versionAtLeast release_version "14") '' - cp -r ${monorepoSrc}/cmake "$out" - '' + '' - cp -r ${monorepoSrc}/${baseName} "$out" - '') else src; + src' = + if monorepoSrc != null then + runCommand "${baseName}-src-${version}" { inherit (monorepoSrc) passthru; } ( + '' + mkdir -p "$out" + '' + + lib.optionalString (lib.versionAtLeast release_version "14") '' + cp -r ${monorepoSrc}/cmake "$out" + '' + + '' + cp -r ${monorepoSrc}/${baseName} "$out" + '' + ) + else + src; in stdenv.mkDerivation { @@ -62,151 +73,207 @@ stdenv.mkDerivation { src = src'; sourceRoot = "${src'.name}/${baseName}"; - nativeBuildInputs = [ cmake ] + nativeBuildInputs = + [ cmake ] ++ (lib.optional (lib.versionAtLeast release_version "15") ninja) - ++ [ python3 libllvm.dev ] + ++ [ + python3 + libllvm.dev + ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ jq ]; buildInputs = lib.optional (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isRiscV) linuxHeaders ++ lib.optional (stdenv.hostPlatform.isFreeBSD) freebsd.include; - env = { - NIX_CFLAGS_COMPILE = toString ([ - "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" - ] ++ lib.optionals (!haveLibc) [ - # The compiler got stricter about this, and there is a usellvm patch below - # which patches out the assert include causing an implicit definition of - # assert. It would be nicer to understand why compiler-rt thinks it should - # be able to #include in the first place; perhaps it's in the - # wrong, or perhaps there is a way to provide an assert.h. - "-Wno-error=implicit-function-declaration" - ]); - } // lib.optionalAttrs (stdenv.hostPlatform.isDarwin) { - # Work around clang’s trying to invoke unprefixed-ld on Darwin when `-target` is passed. - NIX_CFLAGS_LINK = "--ld-path=${stdenv.cc.bintools}/bin/${stdenv.cc.targetPrefix}ld"; - }; + env = + { + NIX_CFLAGS_COMPILE = toString ( + [ + "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" + ] + ++ lib.optionals (!haveLibc) [ + # The compiler got stricter about this, and there is a usellvm patch below + # which patches out the assert include causing an implicit definition of + # assert. It would be nicer to understand why compiler-rt thinks it should + # be able to #include in the first place; perhaps it's in the + # wrong, or perhaps there is a way to provide an assert.h. + "-Wno-error=implicit-function-declaration" + ] + ); + } + // lib.optionalAttrs (stdenv.hostPlatform.isDarwin) { + # Work around clang’s trying to invoke unprefixed-ld on Darwin when `-target` is passed. + NIX_CFLAGS_LINK = "--ld-path=${stdenv.cc.bintools}/bin/${stdenv.cc.targetPrefix}ld"; + }; - cmakeFlags = [ - "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" - "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" - "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" - ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [ - "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" - ] ++ lib.optionals (useLLVM && haveLibc && stdenv.cc.libcxx == libcxx) [ - "-DSANITIZER_CXX_ABI=libcxxabi" - "-DSANITIZER_CXX_ABI_LIBNAME=libcxxabi" - "-DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON" - ] ++ lib.optionals ((!haveLibc || bareMetal || isMusl || isAarch64) && (lib.versions.major release_version == "13")) [ - "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" - ] ++ lib.optionals (useLLVM && haveLibc) [ - "-DCOMPILER_RT_BUILD_SANITIZERS=ON" - ] ++ lib.optionals (noSanitizers) [ - "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" - ] ++ lib.optionals ((useLLVM && !haveLibcxx) || !haveLibc || bareMetal || isMusl || isDarwinStatic) [ - "-DCOMPILER_RT_BUILD_XRAY=OFF" - "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" - "-DCOMPILER_RT_BUILD_MEMPROF=OFF" - "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary - ] ++ lib.optionals (useLLVM && haveLibc) [ - "-DCOMPILER_RT_BUILD_PROFILE=ON" - ] ++ lib.optionals (!haveLibc || bareMetal) [ - "-DCOMPILER_RT_BUILD_PROFILE=OFF" - ] ++ lib.optionals (!haveLibc || bareMetal || isDarwinStatic) [ - "-DCMAKE_CXX_COMPILER_WORKS=ON" - ] ++ lib.optionals (!haveLibc || bareMetal) [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCOMPILER_RT_BAREMETAL_BUILD=ON" - "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" - ] ++ lib.optionals (!haveLibc) [ - "-DCMAKE_C_FLAGS=-nodefaultlibs" - ] ++ lib.optionals (useLLVM) [ - "-DCOMPILER_RT_BUILD_BUILTINS=ON" - #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program - "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" - ] ++ lib.optionals (bareMetal) [ - "-DCOMPILER_RT_OS_DIR=baremetal" - ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) (lib.optionals (lib.versionAtLeast release_version "16") [ - "-DCMAKE_LIPO=${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}lipo" - ] ++ lib.optionals (!haveLibcxx) [ - # Darwin fails to detect that the compiler supports the `-g` flag when there is no libc++ during the - # compiler-rt bootstrap, which prevents compiler-rt from building. The `-g` flag is required by the - # Darwin support, so force it to be enabled during the first stage of the compiler-rt bootstrap. - "-DCOMPILER_RT_HAS_G_FLAG=ON" - ] ++ [ - "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" - "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" - "-DSANITIZER_MIN_OSX_VERSION=${stdenv.hostPlatform.darwinMinVersion}" - ] ++ lib.optionals (lib.versionAtLeast release_version "15") [ - # `COMPILER_RT_DEFAULT_TARGET_ONLY` does not apply to Darwin: - # https://github.com/llvm/llvm-project/blob/27ef42bec80b6c010b7b3729ed0528619521a690/compiler-rt/cmake/base-config-ix.cmake#L153 - "-DCOMPILER_RT_ENABLE_IOS=OFF" - ]) ++ lib.optionals (noSanitizers && lib.versionAtLeast release_version "19") [ - "-DCOMPILER_RT_BUILD_CTX_PROFILE=OFF" - ] ++ devExtraCmakeFlags; - - outputs = [ "out" "dev" ]; - - postPatch = lib.optionalString (!stdenv.hostPlatform.isDarwin) '' - substituteInPlace cmake/builtin-config-ix.cmake \ - --replace-fail 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' - '' + lib.optionalString (!haveLibc) ((lib.optionalString (lib.versions.major release_version == "18") '' - substituteInPlace lib/builtins/aarch64/sme-libc-routines.c \ - --replace-fail "" "" - '') + '' - substituteInPlace lib/builtins/int_util.c \ - --replace-fail "#include " "" - '' + (lib.optionalString (!stdenv.hostPlatform.isFreeBSD) - # On FreeBSD, assert/static_assert are macros and allowing them to be implicitly declared causes link errors. - # see description above for why we're nuking assert.h normally but that doesn't work here. - # instead, we add the freebsd.include dependency explicitly - '' - substituteInPlace lib/builtins/clear_cache.c \ - --replace-fail "#include " "" - substituteInPlace lib/builtins/cpu_model${lib.optionalString (lib.versionAtLeast release_version "18") "/x86"}.c \ - --replace-fail "#include " "" - '')) + lib.optionalString (lib.versionAtLeast release_version "13" && lib.versionOlder release_version "14") '' - # https://github.com/llvm/llvm-project/blob/llvmorg-14.0.6/libcxx/utils/merge_archives.py - # Seems to only be used in v13 though it's present in v12 and v14, and dropped in v15. - substituteInPlace ../libcxx/utils/merge_archives.py \ - --replace-fail "import distutils.spawn" "from shutil import which as find_executable" \ - --replace-fail "distutils.spawn." "" - '' + lib.optionalString (lib.versionAtLeast release_version "19") - # codesign in sigtool doesn't support the various options used by the build - # and is present in the bootstrap-tools. Removing find_program prevents the - # build from trying to use it and failing. + cmakeFlags = + [ + "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" + "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" + "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" + ] + ++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [ + "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" + ] + ++ lib.optionals (useLLVM && haveLibc && stdenv.cc.libcxx == libcxx) [ + "-DSANITIZER_CXX_ABI=libcxxabi" + "-DSANITIZER_CXX_ABI_LIBNAME=libcxxabi" + "-DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON" + ] + ++ + lib.optionals + ((!haveLibc || bareMetal || isMusl || isAarch64) && (lib.versions.major release_version == "13")) + [ + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" + ] + ++ lib.optionals (useLLVM && haveLibc) [ + "-DCOMPILER_RT_BUILD_SANITIZERS=ON" + ] + ++ lib.optionals (noSanitizers) [ + "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" + ] + ++ lib.optionals ((useLLVM && !haveLibcxx) || !haveLibc || bareMetal || isMusl || isDarwinStatic) [ + "-DCOMPILER_RT_BUILD_XRAY=OFF" + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" + "-DCOMPILER_RT_BUILD_MEMPROF=OFF" + "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary + ] + ++ lib.optionals (useLLVM && haveLibc) [ + "-DCOMPILER_RT_BUILD_PROFILE=ON" + ] + ++ lib.optionals (!haveLibc || bareMetal) [ + "-DCOMPILER_RT_BUILD_PROFILE=OFF" + ] + ++ lib.optionals (!haveLibc || bareMetal || isDarwinStatic) [ + "-DCMAKE_CXX_COMPILER_WORKS=ON" + ] + ++ lib.optionals (!haveLibc || bareMetal) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCOMPILER_RT_BAREMETAL_BUILD=ON" + "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" + ] + ++ lib.optionals (!haveLibc) [ + "-DCMAKE_C_FLAGS=-nodefaultlibs" + ] + ++ lib.optionals (useLLVM) [ + "-DCOMPILER_RT_BUILD_BUILTINS=ON" + #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program + "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" + ] + ++ lib.optionals (bareMetal) [ + "-DCOMPILER_RT_OS_DIR=baremetal" + ] + ++ lib.optionals (stdenv.hostPlatform.isDarwin) ( + lib.optionals (lib.versionAtLeast release_version "16") [ + "-DCMAKE_LIPO=${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}lipo" + ] + ++ lib.optionals (!haveLibcxx) [ + # Darwin fails to detect that the compiler supports the `-g` flag when there is no libc++ during the + # compiler-rt bootstrap, which prevents compiler-rt from building. The `-g` flag is required by the + # Darwin support, so force it to be enabled during the first stage of the compiler-rt bootstrap. + "-DCOMPILER_RT_HAS_G_FLAG=ON" + ] + ++ [ + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" + "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" + "-DSANITIZER_MIN_OSX_VERSION=${stdenv.hostPlatform.darwinMinVersion}" + ] + ++ lib.optionals (lib.versionAtLeast release_version "15") [ + # `COMPILER_RT_DEFAULT_TARGET_ONLY` does not apply to Darwin: + # https://github.com/llvm/llvm-project/blob/27ef42bec80b6c010b7b3729ed0528619521a690/compiler-rt/cmake/base-config-ix.cmake#L153 + "-DCOMPILER_RT_ENABLE_IOS=OFF" + ] + ) + ++ lib.optionals (noSanitizers && lib.versionAtLeast release_version "19") [ + "-DCOMPILER_RT_BUILD_CTX_PROFILE=OFF" + ] + ++ devExtraCmakeFlags; + + outputs = [ + "out" + "dev" + ]; + + postPatch = + lib.optionalString (!stdenv.hostPlatform.isDarwin) '' + substituteInPlace cmake/builtin-config-ix.cmake \ + --replace-fail 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' '' - substituteInPlace cmake/Modules/AddCompilerRT.cmake \ - --replace-fail 'find_program(CODESIGN codesign)' "" - ''; - - preConfigure = lib.optionalString (lib.versionOlder release_version "16" && !haveLibc) '' - cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") - '' + lib.optionalString stdenv.hostPlatform.isDarwin '' - cmakeFlagsArray+=( - "-DDARWIN_macosx_CACHED_SYSROOT=$SDKROOT" - "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=$(jq -r .Version "$SDKROOT/SDKSettings.json")" + + lib.optionalString (!haveLibc) ( + (lib.optionalString (lib.versions.major release_version == "18") '' + substituteInPlace lib/builtins/aarch64/sme-libc-routines.c \ + --replace-fail "" "" + '') + + '' + substituteInPlace lib/builtins/int_util.c \ + --replace-fail "#include " "" + '' + + (lib.optionalString (!stdenv.hostPlatform.isFreeBSD) + # On FreeBSD, assert/static_assert are macros and allowing them to be implicitly declared causes link errors. + # see description above for why we're nuking assert.h normally but that doesn't work here. + # instead, we add the freebsd.include dependency explicitly + '' + substituteInPlace lib/builtins/clear_cache.c \ + --replace-fail "#include " "" + substituteInPlace lib/builtins/cpu_model${lib.optionalString (lib.versionAtLeast release_version "18") "/x86"}.c \ + --replace-fail "#include " "" + '' + ) ) - ''; + + + lib.optionalString + (lib.versionAtLeast release_version "13" && lib.versionOlder release_version "14") + '' + # https://github.com/llvm/llvm-project/blob/llvmorg-14.0.6/libcxx/utils/merge_archives.py + # Seems to only be used in v13 though it's present in v12 and v14, and dropped in v15. + substituteInPlace ../libcxx/utils/merge_archives.py \ + --replace-fail "import distutils.spawn" "from shutil import which as find_executable" \ + --replace-fail "distutils.spawn." "" + '' + + + lib.optionalString (lib.versionAtLeast release_version "19") + # codesign in sigtool doesn't support the various options used by the build + # and is present in the bootstrap-tools. Removing find_program prevents the + # build from trying to use it and failing. + '' + substituteInPlace cmake/Modules/AddCompilerRT.cmake \ + --replace-fail 'find_program(CODESIGN codesign)' "" + ''; + + preConfigure = + lib.optionalString (lib.versionOlder release_version "16" && !haveLibc) '' + cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") + '' + + lib.optionalString stdenv.hostPlatform.isDarwin '' + cmakeFlagsArray+=( + "-DDARWIN_macosx_CACHED_SYSROOT=$SDKROOT" + "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=$(jq -r .Version "$SDKROOT/SDKSettings.json")" + ) + ''; # Hack around weird upsream RPATH bug - postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin) '' - ln -s "$out/lib"/*/* "$out/lib" - '' + lib.optionalString (useLLVM && stdenv.hostPlatform.isLinux) '' - ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o - ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o - # Note the history of crt{begin,end}S in previous versions of llvm in nixpkg: - # The presence of crtbegin_shared has been added and removed; it's possible - # people have added/removed it to get it working on their platforms. - # Try each in turn for now. - ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbeginS.o - ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtendS.o - ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o - ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o - '' + lib.optionalString doFakeLibgcc '' - ln -s $out/lib/*/libclang_rt.builtins-*.a $out/lib/libgcc.a - '' + lib.optionalString forceLinkCompilerRt '' - ln -s $out/lib/*/libclang_rt.builtins-*.a $out/lib/libcompiler_rt.a - ''; + postInstall = + lib.optionalString (stdenv.hostPlatform.isDarwin) '' + ln -s "$out/lib"/*/* "$out/lib" + '' + + lib.optionalString (useLLVM && stdenv.hostPlatform.isLinux) '' + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o + # Note the history of crt{begin,end}S in previous versions of llvm in nixpkg: + # The presence of crtbegin_shared has been added and removed; it's possible + # people have added/removed it to get it working on their platforms. + # Try each in turn for now. + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbeginS.o + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtendS.o + ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o + ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o + '' + + lib.optionalString doFakeLibgcc '' + ln -s $out/lib/*/libclang_rt.builtins-*.a $out/lib/libgcc.a + '' + + lib.optionalString forceLinkCompilerRt '' + ln -s $out/lib/*/libclang_rt.builtins-*.a $out/lib/libcompiler_rt.a + ''; meta = llvm_meta // { homepage = "https://compiler-rt.llvm.org/"; @@ -221,7 +288,10 @@ stdenv.mkDerivation { ''; # "All of the code in the compiler-rt project is dual licensed under the MIT # license and the UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; + license = with lib.licenses; [ + mit + ncsa + ]; broken = # compiler-rt requires a Clang stdenv on 32-bit RISC-V: # https://reviews.llvm.org/D43106#1019077 diff --git a/pkgs/development/compilers/llvm/common/default.nix b/pkgs/development/compilers/llvm/common/default.nix index 7d2ef2e3f135d..a65537c965550 100644 --- a/pkgs/development/compilers/llvm/common/default.nix +++ b/pkgs/development/compilers/llvm/common/default.nix @@ -502,9 +502,11 @@ let llvm = tools.libllvm; tblgen = callPackage ./tblgen.nix { - patches = builtins.filter - # Crude method to drop polly patches if present, they're not needed for tblgen. - (p: (!lib.hasInfix "-polly" p)) tools.libllvm.patches; + patches = + builtins.filter + # Crude method to drop polly patches if present, they're not needed for tblgen. + (p: (!lib.hasInfix "-polly" p)) + tools.libllvm.patches; clangPatches = [ # Would take tools.libclang.patches, but this introduces a cycle due # to replacements depending on the llvm outpath (e.g. the LLVMgold patch). @@ -526,12 +528,13 @@ let # libraries. eg: `clang -munsupported hello.c -lc` ./clang/clang-unsupported-option.patch ] - ++ lib.optional (lib.versions.major metadata.release_version == "13") - # Revert of https://reviews.llvm.org/D100879 - # The malloc alignment assumption is incorrect for jemalloc and causes - # mis-compilation in firefox. - # See: https://bugzilla.mozilla.org/show_bug.cgi?id=1741454 - (metadata.getVersionFile "clang/revert-malloc-alignment-assumption.patch") + ++ + lib.optional (lib.versions.major metadata.release_version == "13") + # Revert of https://reviews.llvm.org/D100879 + # The malloc alignment assumption is incorrect for jemalloc and causes + # mis-compilation in firefox. + # See: https://bugzilla.mozilla.org/show_bug.cgi?id=1741454 + (metadata.getVersionFile "clang/revert-malloc-alignment-assumption.patch") ++ lib.optional (lib.versionOlder metadata.release_version "17") ( if lib.versionAtLeast metadata.release_version "14" then fetchpatch { @@ -660,7 +663,7 @@ let lldbPlugins = lib.makeExtensible ( lldbPlugins: let - callPackage = newScope ( lldbPlugins // tools // args // metadata ); + callPackage = newScope (lldbPlugins // tools // args // metadata); in lib.recurseIntoAttrs { llef = callPackage ./lldb-plugins/llef.nix { }; } ); diff --git a/pkgs/development/compilers/llvm/common/libcxx/default.nix b/pkgs/development/compilers/llvm/common/libcxx/default.nix index c4ada0bf669be..2ec95e937c84c 100644 --- a/pkgs/development/compilers/llvm/common/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/common/libcxx/default.nix @@ -1,22 +1,23 @@ -{ lib -, stdenv -, llvm_meta -, release_version -, monorepoSrc ? null -, src ? null -, patches ? [] -, runCommand -, cmake -, lndir -, ninja -, python3 -, fixDarwinDylibNames -, version -, freebsd -, cxxabi ? if stdenv.hostPlatform.isFreeBSD then freebsd.libcxxrt else null -, libunwind -, enableShared ? stdenv.hostPlatform.hasSharedLibraries -, devExtraCmakeFlags ? [] +{ + lib, + stdenv, + llvm_meta, + release_version, + monorepoSrc ? null, + src ? null, + patches ? [ ], + runCommand, + cmake, + lndir, + ninja, + python3, + fixDarwinDylibNames, + version, + freebsd, + cxxabi ? if stdenv.hostPlatform.isFreeBSD then freebsd.libcxxrt else null, + libunwind, + enableShared ? stdenv.hostPlatform.hasSharedLibraries, + devExtraCmakeFlags ? [ ], }: # external cxxabi is not supported on Darwin as the build will not link libcxx @@ -33,167 +34,249 @@ let # Note: useLLVM is likely false for Darwin but true under pkgsLLVM useLLVM = stdenv.hostPlatform.useLLVM or false; - src' = if monorepoSrc != null then - runCommand "${pname}-src-${version}" { inherit (monorepoSrc) passthru; } ('' - mkdir -p "$out/llvm" - '' + (lib.optionalString (lib.versionAtLeast release_version "14") '' - cp -r ${monorepoSrc}/cmake "$out" - '') + '' - cp -r ${monorepoSrc}/libcxx "$out" - cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" - cp -r ${monorepoSrc}/llvm/utils "$out/llvm" - '' + (lib.optionalString (lib.versionAtLeast release_version "14") '' - cp -r ${monorepoSrc}/third-party "$out" - '') + (lib.optionalString (lib.versionAtLeast release_version "20") '' - cp -r ${monorepoSrc}/libc "$out" - '') + '' - cp -r ${monorepoSrc}/runtimes "$out" - '' + (lib.optionalString (cxxabi == null) '' - cp -r ${monorepoSrc}/libcxxabi "$out" - '')) else src; - - cxxabiCMakeFlags = lib.optionals (lib.versionAtLeast release_version "18") [ - "-DLIBCXXABI_USE_LLVM_UNWINDER=OFF" - ] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) (if lib.versionAtLeast release_version "18" then [ - "-DLIBCXXABI_ADDITIONAL_LIBRARIES=unwind" - "-DLIBCXXABI_USE_COMPILER_RT=ON" - ] else [ - "-DLIBCXXABI_USE_COMPILER_RT=ON" - "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" - ]) ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXXABI_ENABLE_THREADS=OFF" - "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared || stdenv.hostPlatform.isWindows) [ - # Required on Windows due to https://github.com/llvm/llvm-project/issues/55245 - "-DLIBCXXABI_ENABLE_SHARED=OFF" - ]; - - cxxCMakeFlags = [ - "-DLIBCXX_CXX_ABI=${cxxabiName}" - ] ++ lib.optionals (cxxabi == null && lib.versionAtLeast release_version "16") [ - # Note: llvm < 16 doesn't support this flag (or it's broken); handled in postInstall instead. - # Include libc++abi symbols within libc++.a for static linking libc++; - # dynamic linking includes them through libc++.so being a linker script - # which includes both shared objects. - "-DLIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY=ON" - ] ++ lib.optionals (cxxabi != null) [ - "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${lib.getDev cxxabi}/include" - ] ++ lib.optionals (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [ - "-DLIBCXX_HAS_MUSL_LIBC=1" - ] ++ lib.optionals (lib.versionAtLeast release_version "18" && !useLLVM && stdenv.hostPlatform.libc == "glibc" && !stdenv.hostPlatform.isStatic) [ - "-DLIBCXX_ADDITIONAL_LIBRARIES=gcc_s" - ] ++ lib.optionals (lib.versionAtLeast release_version "18" && stdenv.hostPlatform.isFreeBSD) [ - # Name and documentation claim this is for libc++abi, but its man effect is adding `-lunwind` - # to the libc++.so linker script. We want FreeBSD's so-called libgcc instead of libunwind. - "-DLIBCXXABI_USE_LLVM_UNWINDER=OFF" - ] ++ lib.optionals useLLVM [ - "-DLIBCXX_USE_COMPILER_RT=ON" - ] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isFreeBSD && lib.versionAtLeast release_version "16") [ - "-DLIBCXX_ADDITIONAL_LIBRARIES=unwind" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXX_ENABLE_THREADS=OFF" - "-DLIBCXX_ENABLE_FILESYSTEM=OFF" - "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals stdenv.hostPlatform.isWindows [ - # https://github.com/llvm/llvm-project/issues/55245 - "-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON" - ] ++ lib.optionals (!enableShared) [ - "-DLIBCXX_ENABLE_SHARED=OFF" - ] ++ lib.optionals (cxxabi != null && cxxabi.libName == "cxxrt") [ - "-DLIBCXX_ENABLE_NEW_DELETE_DEFINITIONS=ON" - ]; - - cmakeFlags = [ - "-DLLVM_ENABLE_RUNTIMES=${lib.concatStringsSep ";" runtimes}" - ] ++ lib.optionals ( - stdenv.hostPlatform.isWasm - || (lib.versions.major release_version == "12" && stdenv.hostPlatform.isDarwin) - ) [ - "-DCMAKE_CXX_COMPILER_WORKS=ON" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker - ] ++ cxxCMakeFlags + src' = + if monorepoSrc != null then + runCommand "${pname}-src-${version}" { inherit (monorepoSrc) passthru; } ( + '' + mkdir -p "$out/llvm" + '' + + (lib.optionalString (lib.versionAtLeast release_version "14") '' + cp -r ${monorepoSrc}/cmake "$out" + '') + + '' + cp -r ${monorepoSrc}/libcxx "$out" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" + '' + + (lib.optionalString (lib.versionAtLeast release_version "14") '' + cp -r ${monorepoSrc}/third-party "$out" + '') + + (lib.optionalString (lib.versionAtLeast release_version "20") '' + cp -r ${monorepoSrc}/libc "$out" + '') + + '' + cp -r ${monorepoSrc}/runtimes "$out" + '' + + (lib.optionalString (cxxabi == null) '' + cp -r ${monorepoSrc}/libcxxabi "$out" + '') + ) + else + src; + + cxxabiCMakeFlags = + lib.optionals (lib.versionAtLeast release_version "18") [ + "-DLIBCXXABI_USE_LLVM_UNWINDER=OFF" + ] + ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) ( + if lib.versionAtLeast release_version "18" then + [ + "-DLIBCXXABI_ADDITIONAL_LIBRARIES=unwind" + "-DLIBCXXABI_USE_COMPILER_RT=ON" + ] + else + [ + "-DLIBCXXABI_USE_COMPILER_RT=ON" + "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" + ] + ) + ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXXABI_ENABLE_THREADS=OFF" + "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" + ] + ++ lib.optionals (!enableShared || stdenv.hostPlatform.isWindows) [ + # Required on Windows due to https://github.com/llvm/llvm-project/issues/55245 + "-DLIBCXXABI_ENABLE_SHARED=OFF" + ]; + + cxxCMakeFlags = + [ + "-DLIBCXX_CXX_ABI=${cxxabiName}" + ] + ++ lib.optionals (cxxabi == null && lib.versionAtLeast release_version "16") [ + # Note: llvm < 16 doesn't support this flag (or it's broken); handled in postInstall instead. + # Include libc++abi symbols within libc++.a for static linking libc++; + # dynamic linking includes them through libc++.so being a linker script + # which includes both shared objects. + "-DLIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY=ON" + ] + ++ lib.optionals (cxxabi != null) [ + "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${lib.getDev cxxabi}/include" + ] + ++ lib.optionals (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [ + "-DLIBCXX_HAS_MUSL_LIBC=1" + ] + ++ + lib.optionals + ( + lib.versionAtLeast release_version "18" + && !useLLVM + && stdenv.hostPlatform.libc == "glibc" + && !stdenv.hostPlatform.isStatic + ) + [ + "-DLIBCXX_ADDITIONAL_LIBRARIES=gcc_s" + ] + ++ lib.optionals (lib.versionAtLeast release_version "18" && stdenv.hostPlatform.isFreeBSD) [ + # Name and documentation claim this is for libc++abi, but its man effect is adding `-lunwind` + # to the libc++.so linker script. We want FreeBSD's so-called libgcc instead of libunwind. + "-DLIBCXXABI_USE_LLVM_UNWINDER=OFF" + ] + ++ lib.optionals useLLVM [ + "-DLIBCXX_USE_COMPILER_RT=ON" + ] + ++ + lib.optionals (useLLVM && !stdenv.hostPlatform.isFreeBSD && lib.versionAtLeast release_version "16") + [ + "-DLIBCXX_ADDITIONAL_LIBRARIES=unwind" + ] + ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXX_ENABLE_THREADS=OFF" + "-DLIBCXX_ENABLE_FILESYSTEM=OFF" + "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" + ] + ++ lib.optionals stdenv.hostPlatform.isWindows [ + # https://github.com/llvm/llvm-project/issues/55245 + "-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON" + ] + ++ lib.optionals (!enableShared) [ + "-DLIBCXX_ENABLE_SHARED=OFF" + ] + ++ lib.optionals (cxxabi != null && cxxabi.libName == "cxxrt") [ + "-DLIBCXX_ENABLE_NEW_DELETE_DEFINITIONS=ON" + ]; + + cmakeFlags = + [ + "-DLLVM_ENABLE_RUNTIMES=${lib.concatStringsSep ";" runtimes}" + ] + ++ + lib.optionals + ( + stdenv.hostPlatform.isWasm + || (lib.versions.major release_version == "12" && stdenv.hostPlatform.isDarwin) + ) + [ + "-DCMAKE_CXX_COMPILER_WORKS=ON" + ] + ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker + ] + ++ cxxCMakeFlags ++ lib.optionals (cxxabi == null) cxxabiCMakeFlags ++ devExtraCmakeFlags; in -stdenv.mkDerivation (rec { - inherit pname version cmakeFlags patches; - - src = src'; - - outputs = [ "out" "dev" ]; - - preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' - patchShebangs utils/cat_files.py - ''; - - nativeBuildInputs = [ cmake ninja python3 ] - ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames - ++ lib.optional (cxxabi != null) lndir; - - buildInputs = [ cxxabi ] - ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm && !stdenv.hostPlatform.isFreeBSD) [ libunwind ]; - - # libc++.so is a linker script which expands to multiple libraries, - # libc++.so.1 and libc++abi.so or the external cxxabi. ld-wrapper doesn't - # support linker scripts so the external cxxabi needs to be symlinked in - postInstall = lib.optionalString (cxxabi != null) '' - lndir ${lib.getDev cxxabi}/include $dev/include/c++/v1 - lndir ${lib.getLib cxxabi}/lib $out/lib - libcxxabi=$out/lib/lib${cxxabi.libName}.a - '' - # LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY=ON doesn't work for LLVM < 16 or - # external cxxabi libraries so merge libc++abi.a into libc++.a ourselves. - - # GNU binutils emits objects in LIFO order in MRI scripts so after the merge - # the objects are in reversed order so a second MRI script is required so the - # objects in the archive are listed in proper order (libc++.a, libc++abi.a) - + lib.optionalString (cxxabi != null || lib.versionOlder release_version "16") '' - libcxxabi=''${libcxxabi-$out/lib/libc++abi.a} - if [[ -f $out/lib/libc++.a && -e $libcxxabi ]]; then - $AR -M < 0; - prePatch = lib.optionalString (lib.versionAtLeast release_version "15" && (hasPatches || lib.versionOlder release_version "18")) '' - cd ../${pname} - chmod -R u+w . - ''; + prePatch = + lib.optionalString + (lib.versionAtLeast release_version "15" && (hasPatches || lib.versionOlder release_version "18")) + '' + cd ../${pname} + chmod -R u+w . + ''; - postPatch = lib.optionalString (lib.versionAtLeast release_version "15" && (hasPatches || lib.versionOlder release_version "18")) '' - cd ../runtimes - ''; + postPatch = + lib.optionalString + (lib.versionAtLeast release_version "15" && (hasPatches || lib.versionOlder release_version "18")) + '' + cd ../runtimes + ''; postInstall = lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin) '' # libcxxabi wants to link to libunwind_shared.so (?). ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so ''; in -stdenv.mkDerivation (rec { - inherit pname version patches; +stdenv.mkDerivation ( + rec { + inherit pname version patches; - src = src'; + src = src'; - sourceRoot = - if lib.versionAtLeast release_version "15" - then "${src.name}/runtimes" - else "${src.name}/${pname}"; + sourceRoot = + if lib.versionAtLeast release_version "15" then "${src.name}/runtimes" else "${src.name}/${pname}"; - outputs = [ "out" "dev" ]; + outputs = [ + "out" + "dev" + ]; - nativeBuildInputs = [ cmake ] ++ lib.optionals (lib.versionAtLeast release_version "15") [ - ninja python3 - ]; + nativeBuildInputs = + [ cmake ] + ++ lib.optionals (lib.versionAtLeast release_version "15") [ + ninja + python3 + ]; - cmakeFlags = lib.optional (lib.versionAtLeast release_version "15") "-DLLVM_ENABLE_RUNTIMES=libunwind" - ++ lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF" - ++ lib.optionals (lib.versions.major release_version == "12" && stdenv.hostPlatform.isDarwin) [ - "-DCMAKE_CXX_COMPILER_WORKS=ON" - ] - ++ devExtraCmakeFlags; + cmakeFlags = + lib.optional (lib.versionAtLeast release_version "15") "-DLLVM_ENABLE_RUNTIMES=libunwind" + ++ lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF" + ++ lib.optionals (lib.versions.major release_version == "12" && stdenv.hostPlatform.isDarwin) [ + "-DCMAKE_CXX_COMPILER_WORKS=ON" + ] + ++ devExtraCmakeFlags; - meta = llvm_meta // { - # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst - homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library"; - description = "LLVM's unwinder library"; - longDescription = '' - The unwind library provides a family of _Unwind_* functions implementing - the language-neutral stack unwinding portion of the Itanium C++ ABI (Level - I). It is a dependency of the C++ ABI library, and sometimes is a - dependency of other runtimes. - ''; - }; -} // (if (lib.versionAtLeast release_version "15") then { inherit postInstall; } else {}) - // (if prePatch != "" then { inherit prePatch; } else {}) - // (if postPatch != "" then { inherit postPatch; } else {})) + meta = llvm_meta // { + # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst + homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library"; + description = "LLVM's unwinder library"; + longDescription = '' + The unwind library provides a family of _Unwind_* functions implementing + the language-neutral stack unwinding portion of the Itanium C++ ABI (Level + I). It is a dependency of the C++ ABI library, and sometimes is a + dependency of other runtimes. + ''; + }; + } + // (if (lib.versionAtLeast release_version "15") then { inherit postInstall; } else { }) + // (if prePatch != "" then { inherit prePatch; } else { }) + // (if postPatch != "" then { inherit postPatch; } else { }) +) diff --git a/pkgs/development/compilers/llvm/common/lld/default.nix b/pkgs/development/compilers/llvm/common/lld/default.nix index 49371bb24883a..83e2ac4f52f16 100644 --- a/pkgs/development/compilers/llvm/common/lld/default.nix +++ b/pkgs/development/compilers/llvm/common/lld/default.nix @@ -1,72 +1,95 @@ -{ lib -, stdenv -, llvm_meta -, release_version -, patches ? [] -, buildLlvmTools -, monorepoSrc ? null -, src ? null -, runCommand -, cmake -, ninja -, libxml2 -, libllvm -, version -, devExtraCmakeFlags ? [] +{ + lib, + stdenv, + llvm_meta, + release_version, + patches ? [ ], + buildLlvmTools, + monorepoSrc ? null, + src ? null, + runCommand, + cmake, + ninja, + libxml2, + libllvm, + version, + devExtraCmakeFlags ? [ ], }: let pname = "lld"; src' = if monorepoSrc != null then - runCommand "lld-src-${version}" { inherit (monorepoSrc) passthru; } ('' - mkdir -p "$out" - '' + lib.optionalString (lib.versionAtLeast release_version "14") '' - cp -r ${monorepoSrc}/cmake "$out" - '' + '' - cp -r ${monorepoSrc}/${pname} "$out" - mkdir -p "$out/libunwind" - cp -r ${monorepoSrc}/libunwind/include "$out/libunwind" - mkdir -p "$out/llvm" - '') else src; + runCommand "lld-src-${version}" { inherit (monorepoSrc) passthru; } ( + '' + mkdir -p "$out" + '' + + lib.optionalString (lib.versionAtLeast release_version "14") '' + cp -r ${monorepoSrc}/cmake "$out" + '' + + '' + cp -r ${monorepoSrc}/${pname} "$out" + mkdir -p "$out/libunwind" + cp -r ${monorepoSrc}/libunwind/include "$out/libunwind" + mkdir -p "$out/llvm" + '' + ) + else + src; postPatch = lib.optionalString (lib.versionOlder release_version "14") '' substituteInPlace MachO/CMakeLists.txt --replace-fail \ '(''${LLVM_MAIN_SRC_DIR}/' '(../' ''; in -stdenv.mkDerivation (rec { - inherit pname version patches; +stdenv.mkDerivation ( + rec { + inherit pname version patches; - src = src'; + src = src'; - sourceRoot = "${src.name}/${pname}"; + sourceRoot = "${src.name}/${pname}"; - nativeBuildInputs = [ cmake ] ++ lib.optional (lib.versionAtLeast release_version "15") ninja; - buildInputs = [ libllvm libxml2 ]; + nativeBuildInputs = [ cmake ] ++ lib.optional (lib.versionAtLeast release_version "15") ninja; + buildInputs = [ + libllvm + libxml2 + ]; - cmakeFlags = lib.optionals (lib.versionOlder release_version "14") [ - "-DLLVM_CONFIG_PATH=${libllvm.dev}/bin/llvm-config${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"}" - ] ++ lib.optionals (lib.versionAtLeast release_version "15") [ - "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/lld" - ] ++ [ - "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.tblgen}/bin/llvm-tblgen" - ] ++ devExtraCmakeFlags; + cmakeFlags = + lib.optionals (lib.versionOlder release_version "14") [ + "-DLLVM_CONFIG_PATH=${libllvm.dev}/bin/llvm-config${ + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native" + }" + ] + ++ lib.optionals (lib.versionAtLeast release_version "15") [ + "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/lld" + ] + ++ [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.tblgen}/bin/llvm-tblgen" + ] + ++ devExtraCmakeFlags; - # Musl's default stack size is too small for lld to be able to link Firefox. - LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152"; + # Musl's default stack size is too small for lld to be able to link Firefox. + LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152"; - outputs = [ "out" "lib" "dev" ]; + outputs = [ + "out" + "lib" + "dev" + ]; - meta = llvm_meta // { - homepage = "https://lld.llvm.org/"; - description = "LLVM linker (unwrapped)"; - longDescription = '' - LLD is a linker from the LLVM project that is a drop-in replacement for - system linkers and runs much faster than them. It also provides features - that are useful for toolchain developers. - The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and - WebAssembly in descending order of completeness. Internally, LLD consists - of several different linkers. - ''; - }; -} // (lib.optionalAttrs (postPatch != "") { inherit postPatch; })) + meta = llvm_meta // { + homepage = "https://lld.llvm.org/"; + description = "LLVM linker (unwrapped)"; + longDescription = '' + LLD is a linker from the LLVM project that is a drop-in replacement for + system linkers and runs much faster than them. It also provides features + that are useful for toolchain developers. + The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and + WebAssembly in descending order of completeness. Internally, LLD consists + of several different linkers. + ''; + }; + } + // (lib.optionalAttrs (postPatch != "") { inherit postPatch; }) +) diff --git a/pkgs/development/compilers/llvm/common/lldb.nix b/pkgs/development/compilers/llvm/common/lldb.nix index f4a131c476205..f11ada84810c5 100644 --- a/pkgs/development/compilers/llvm/common/lldb.nix +++ b/pkgs/development/compilers/llvm/common/lldb.nix @@ -1,196 +1,230 @@ -{ lib -, stdenv -, llvm_meta -, release_version -, cmake -, zlib -, ncurses -, swig -, which -, libedit -, libxml2 -, libllvm -, libclang -, python3 -, version -, darwin -, lit -, makeWrapper -, lua5_3 -, ninja -, runCommand -, src ? null -, monorepoSrc ? null -, patches ? [ ] -, enableManpages ? false -, devExtraCmakeFlags ? [ ] -, ... +{ + lib, + stdenv, + llvm_meta, + release_version, + cmake, + zlib, + ncurses, + swig, + which, + libedit, + libxml2, + libllvm, + libclang, + python3, + version, + darwin, + lit, + makeWrapper, + lua5_3, + ninja, + runCommand, + src ? null, + monorepoSrc ? null, + patches ? [ ], + enableManpages ? false, + devExtraCmakeFlags ? [ ], + ... }: let src' = if monorepoSrc != null then - runCommand "lldb-src-${version}" { inherit (monorepoSrc) passthru; } ('' - mkdir -p "$out" - '' + lib.optionalString (lib.versionAtLeast release_version "14") '' - cp -r ${monorepoSrc}/cmake "$out" - '' + '' - cp -r ${monorepoSrc}/lldb "$out" - '' + lib.optionalString (lib.versionAtLeast release_version "19" && enableManpages) '' - mkdir -p "$out/llvm" - cp -r ${monorepoSrc}/llvm/docs "$out/llvm/docs" - '') else src; + runCommand "lldb-src-${version}" { inherit (monorepoSrc) passthru; } ( + '' + mkdir -p "$out" + '' + + lib.optionalString (lib.versionAtLeast release_version "14") '' + cp -r ${monorepoSrc}/cmake "$out" + '' + + '' + cp -r ${monorepoSrc}/lldb "$out" + '' + + lib.optionalString (lib.versionAtLeast release_version "19" && enableManpages) '' + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/docs "$out/llvm/docs" + '' + ) + else + src; vscodeExt = { name = if lib.versionAtLeast release_version "18" then "lldb-dap" else "lldb-vscode"; version = if lib.versionAtLeast release_version "18" then "0.2.0" else "0.1.0"; }; in -stdenv.mkDerivation (rec { - passthru.monorepoSrc = monorepoSrc; - pname = "lldb"; - inherit version; - - src = src'; - inherit patches; - - # LLDB expects to find the path to `bin` relative to `lib` on Darwin. It can’t be patched with the location of - # the `lib` output because that would create a cycle between it and the `out` output. - outputs = [ "out" "dev" ] ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [ "lib" ]; - - sourceRoot = lib.optional (lib.versionAtLeast release_version "13") "${src.name}/${pname}"; - - nativeBuildInputs = [ - cmake - python3 - which - swig - lit - makeWrapper - lua5_3 - ] ++ lib.optionals enableManpages [ - python3.pkgs.sphinx - ] ++ lib.optionals (lib.versionOlder release_version "18" && enableManpages) [ - python3.pkgs.recommonmark - ] ++ lib.optionals (lib.versionAtLeast release_version "18" && enableManpages) [ - python3.pkgs.myst-parser - ] ++ lib.optionals (lib.versionAtLeast release_version "14") [ - ninja - ]; - - buildInputs = [ - ncurses - zlib - libedit - libxml2 - libllvm - ] ++ lib.optionals (lib.versionAtLeast release_version "16") [ - # Starting with LLVM 16, the resource dir patch is no longer enough to get - # libclang into the rpath of the lldb executables. By putting it into - # buildInputs cc-wrapper will set up rpath correctly for us. - (lib.getLib libclang) - ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ - darwin.bootstrap_cmds - ]; - - hardeningDisable = [ "format" ]; - - cmakeFlags = [ - "-DLLDB_INCLUDE_TESTS=${if doCheck then "YES" else "NO"}" - "-DLLVM_ENABLE_RTTI=OFF" - "-DClang_DIR=${lib.getDev libclang}/lib/cmake" - "-DLLVM_EXTERNAL_LIT=${lit}/bin/lit" - ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ - "-DLLDB_USE_SYSTEM_DEBUGSERVER=ON" - ] ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [ - "-DLLDB_CODESIGN_IDENTITY=" # codesigning makes nondeterministic - ] ++ lib.optionals (lib.versionAtLeast release_version "17") [ - "-DCLANG_RESOURCE_DIR=../../../../${lib.getLib libclang}" - ] ++ lib.optionals enableManpages ([ - "-DLLVM_ENABLE_SPHINX=ON" - "-DSPHINX_OUTPUT_MAN=ON" - "-DSPHINX_OUTPUT_HTML=OFF" - ] ++ lib.optionals (lib.versionAtLeast release_version "15") [ - # docs reference `automodapi` but it's not added to the extensions list when - # only building the manpages: - # https://github.com/llvm/llvm-project/blob/af6ec9200b09039573d85e349496c4f5b17c3d7f/lldb/docs/conf.py#L54 - # - # so, we just ignore the resulting errors - "-DSPHINX_WARNINGS_AS_ERRORS=OFF" - ]) ++ lib.optionals doCheck [ - "-DLLDB_TEST_C_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" - "-DLLDB_TEST_CXX_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++" - ] ++ devExtraCmakeFlags; - - doCheck = false; - doInstallCheck = lib.versionOlder release_version "15"; - - # TODO: cleanup with mass-rebuild - installCheckPhase = '' - if [ ! -e ''${!outputLib}/${python3.sitePackages}/lldb/_lldb*.so ] ; then - echo "ERROR: python files not installed where expected!"; - return 1; - fi - '' # Something lua is built on older versions but this file doesn't exist. - + lib.optionalString (lib.versionAtLeast release_version "14") '' - if [ ! -e "''${!outputLib}/lib/lua/${lua5_3.luaversion}/lldb.so" ] ; then - echo "ERROR: lua files not installed where expected!"; - return 1; - fi - ''; - - postInstall = '' - wrapProgram $out/bin/lldb --prefix PYTHONPATH : $lib/${python3.sitePackages}/ - - # Editor support - # vscode: - install -D ../tools/${vscodeExt.name}/package.json $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/package.json - mkdir -p $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin - ln -s $out/bin/*${if lib.versionAtLeast release_version "18" then vscodeExt.name else "-vscode"} $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin - ''; - - passthru.vscodeExtName = vscodeExt.name; - passthru.vscodeExtPublisher = "llvm"; - passthru.vscodeExtUniqueId = "llvm-org.${vscodeExt.name}-${vscodeExt.version}"; - - meta = llvm_meta // { - homepage = "https://lldb.llvm.org/"; - description = "Next-generation high-performance debugger"; - longDescription = '' - LLDB is a next generation, high-performance debugger. It is built as a set - of reusable components which highly leverage existing libraries in the - larger LLVM Project, such as the Clang expression parser and LLVM - disassembler. +stdenv.mkDerivation ( + rec { + passthru.monorepoSrc = monorepoSrc; + pname = "lldb"; + inherit version; + + src = src'; + inherit patches; + + # LLDB expects to find the path to `bin` relative to `lib` on Darwin. It can’t be patched with the location of + # the `lib` output because that would create a cycle between it and the `out` output. + outputs = [ + "out" + "dev" + ] ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [ "lib" ]; + + sourceRoot = lib.optional (lib.versionAtLeast release_version "13") "${src.name}/${pname}"; + + nativeBuildInputs = + [ + cmake + python3 + which + swig + lit + makeWrapper + lua5_3 + ] + ++ lib.optionals enableManpages [ + python3.pkgs.sphinx + ] + ++ lib.optionals (lib.versionOlder release_version "18" && enableManpages) [ + python3.pkgs.recommonmark + ] + ++ lib.optionals (lib.versionAtLeast release_version "18" && enableManpages) [ + python3.pkgs.myst-parser + ] + ++ lib.optionals (lib.versionAtLeast release_version "14") [ + ninja + ]; + + buildInputs = + [ + ncurses + zlib + libedit + libxml2 + libllvm + ] + ++ lib.optionals (lib.versionAtLeast release_version "16") [ + # Starting with LLVM 16, the resource dir patch is no longer enough to get + # libclang into the rpath of the lldb executables. By putting it into + # buildInputs cc-wrapper will set up rpath correctly for us. + (lib.getLib libclang) + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + darwin.bootstrap_cmds + ]; + + hardeningDisable = [ "format" ]; + + cmakeFlags = + [ + "-DLLDB_INCLUDE_TESTS=${if doCheck then "YES" else "NO"}" + "-DLLVM_ENABLE_RTTI=OFF" + "-DClang_DIR=${lib.getDev libclang}/lib/cmake" + "-DLLVM_EXTERNAL_LIT=${lit}/bin/lit" + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + "-DLLDB_USE_SYSTEM_DEBUGSERVER=ON" + ] + ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [ + "-DLLDB_CODESIGN_IDENTITY=" # codesigning makes nondeterministic + ] + ++ lib.optionals (lib.versionAtLeast release_version "17") [ + "-DCLANG_RESOURCE_DIR=../../../../${lib.getLib libclang}" + ] + ++ lib.optionals enableManpages ( + [ + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + ] + ++ lib.optionals (lib.versionAtLeast release_version "15") [ + # docs reference `automodapi` but it's not added to the extensions list when + # only building the manpages: + # https://github.com/llvm/llvm-project/blob/af6ec9200b09039573d85e349496c4f5b17c3d7f/lldb/docs/conf.py#L54 + # + # so, we just ignore the resulting errors + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] + ) + ++ lib.optionals doCheck [ + "-DLLDB_TEST_C_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" + "-DLLDB_TEST_CXX_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++" + ] + ++ devExtraCmakeFlags; + + doCheck = false; + doInstallCheck = lib.versionOlder release_version "15"; + + # TODO: cleanup with mass-rebuild + installCheckPhase = + '' + if [ ! -e ''${!outputLib}/${python3.sitePackages}/lldb/_lldb*.so ] ; then + echo "ERROR: python files not installed where expected!"; + return 1; + fi + '' # Something lua is built on older versions but this file doesn't exist. + + lib.optionalString (lib.versionAtLeast release_version "14") '' + if [ ! -e "''${!outputLib}/lib/lua/${lua5_3.luaversion}/lldb.so" ] ; then + echo "ERROR: lua files not installed where expected!"; + return 1; + fi + ''; + + postInstall = '' + wrapProgram $out/bin/lldb --prefix PYTHONPATH : $lib/${python3.sitePackages}/ + + # Editor support + # vscode: + install -D ../tools/${vscodeExt.name}/package.json $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/package.json + mkdir -p $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin + ln -s $out/bin/*${ + if lib.versionAtLeast release_version "18" then vscodeExt.name else "-vscode" + } $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin ''; - broken = lib.versionOlder release_version "14"; - mainProgram = "lldb"; - }; -} // lib.optionalAttrs enableManpages { - pname = "lldb-manpages"; - - buildPhase = lib.optionalString (lib.versionOlder release_version "15") '' - make ${if (lib.versionOlder release_version "12") then "docs-man" else "docs-lldb-man"} - ''; + passthru.vscodeExtName = vscodeExt.name; + passthru.vscodeExtPublisher = "llvm"; + passthru.vscodeExtUniqueId = "llvm-org.${vscodeExt.name}-${vscodeExt.version}"; + + meta = llvm_meta // { + homepage = "https://lldb.llvm.org/"; + description = "Next-generation high-performance debugger"; + longDescription = '' + LLDB is a next generation, high-performance debugger. It is built as a set + of reusable components which highly leverage existing libraries in the + larger LLVM Project, such as the Clang expression parser and LLVM + disassembler. + ''; + broken = lib.versionOlder release_version "14"; + mainProgram = "lldb"; + }; + } + // lib.optionalAttrs enableManpages { + pname = "lldb-manpages"; + + buildPhase = lib.optionalString (lib.versionOlder release_version "15") '' + make ${if (lib.versionOlder release_version "12") then "docs-man" else "docs-lldb-man"} + ''; - ninjaFlags = lib.optionals (lib.versionAtLeast release_version "15") [ "docs-lldb-man" ]; + ninjaFlags = lib.optionals (lib.versionAtLeast release_version "15") [ "docs-lldb-man" ]; - propagatedBuildInputs = [ ]; + propagatedBuildInputs = [ ]; - # manually install lldb man page - installPhase = '' - mkdir -p $out/share/man/man1 - install docs/man/lldb.1 -t $out/share/man/man1/ - ''; + # manually install lldb man page + installPhase = '' + mkdir -p $out/share/man/man1 + install docs/man/lldb.1 -t $out/share/man/man1/ + ''; - postPatch = null; - postInstall = null; + postPatch = null; + postInstall = null; - outputs = [ "out" ]; + outputs = [ "out" ]; - doCheck = false; + doCheck = false; - meta = llvm_meta // { - description = "man pages for LLDB ${version}"; - }; -}) + meta = llvm_meta // { + description = "man pages for LLDB ${version}"; + }; + } +) diff --git a/pkgs/development/compilers/llvm/common/llvm/default.nix b/pkgs/development/compilers/llvm/common/llvm/default.nix index 2e248209819a5..952bf66c7ceb3 100644 --- a/pkgs/development/compilers/llvm/common/llvm/default.nix +++ b/pkgs/development/compilers/llvm/common/llvm/default.nix @@ -1,44 +1,51 @@ -{ lib -, stdenv -, llvm_meta -, pkgsBuildBuild -, pollyPatches ? [] -, patches ? [] -, src ? null -, monorepoSrc ? null -, runCommand -, cmake -, darwin -, ninja -, python3 -, python3Packages -, libffi -, ld64 -, libbfd -, libpfm -, libxml2 -, ncurses -, version -, release_version -, zlib -, which -, sysctl -, buildLlvmTools -, updateAutotoolsGnuConfigScriptsHook -, debugVersion ? false -, doCheck ? !stdenv.hostPlatform.isAarch32 && (if lib.versionOlder release_version "15" then stdenv.hostPlatform.isLinux else true) - && (!stdenv.hostPlatform.isx86_32 /* TODO: why */) && (!stdenv.hostPlatform.isMusl) - && !(stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isBigEndian) - && (stdenv.hostPlatform == stdenv.buildPlatform) -, enableManpages ? false -, enableSharedLibraries ? !stdenv.hostPlatform.isStatic -, enablePFM ? stdenv.hostPlatform.isLinux /* PFM only supports Linux */ - # broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 - # broken for the armv7l builder - && !stdenv.hostPlatform.isAarch -, enablePolly ? lib.versionAtLeast release_version "14" -, enableTerminfo ? true -, devExtraCmakeFlags ? [] +{ + lib, + stdenv, + llvm_meta, + pkgsBuildBuild, + pollyPatches ? [ ], + patches ? [ ], + src ? null, + monorepoSrc ? null, + runCommand, + cmake, + darwin, + ninja, + python3, + python3Packages, + libffi, + ld64, + libbfd, + libpfm, + libxml2, + ncurses, + version, + release_version, + zlib, + which, + sysctl, + buildLlvmTools, + updateAutotoolsGnuConfigScriptsHook, + debugVersion ? false, + doCheck ? + !stdenv.hostPlatform.isAarch32 + && (if lib.versionOlder release_version "15" then stdenv.hostPlatform.isLinux else true) + && ( + !stdenv.hostPlatform.isx86_32 # TODO: why + ) + && (!stdenv.hostPlatform.isMusl) + && !(stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isBigEndian) + && (stdenv.hostPlatform == stdenv.buildPlatform), + enableManpages ? false, + enableSharedLibraries ? !stdenv.hostPlatform.isStatic, + enablePFM ? + stdenv.hostPlatform.isLinux # PFM only supports Linux + # broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 + # broken for the armv7l builder + && !stdenv.hostPlatform.isAarch, + enablePolly ? lib.versionAtLeast release_version "14", + enableTerminfo ? true, + devExtraCmakeFlags ? [ ], }: let @@ -69,480 +76,624 @@ let # # So, we "manually" assemble one python derivation for the package to depend # on, taking into account whether checks are enabled or not: - python = if doCheck && !isDarwinBootstrap then - # Note that we _explicitly_ ask for a python interpreter for our host - # platform here; the splicing that would ordinarily take care of this for - # us does not seem to work once we use `withPackages`. - let - checkDeps = ps: [ ps.psutil ]; - in pkgsBuildBuild.targetPackages.python3.withPackages checkDeps - else python3; + python = + if doCheck && !isDarwinBootstrap then + # Note that we _explicitly_ ask for a python interpreter for our host + # platform here; the splicing that would ordinarily take care of this for + # us does not seem to work once we use `withPackages`. + let + checkDeps = ps: [ ps.psutil ]; + in + pkgsBuildBuild.targetPackages.python3.withPackages checkDeps + else + python3; pname = "llvm"; # TODO: simplify versionAtLeast condition for cmake and third-party via rebuild - src' = if monorepoSrc != null then - runCommand "${pname}-src-${version}" { inherit (monorepoSrc) passthru; } ('' - mkdir -p "$out" - '' + lib.optionalString (lib.versionAtLeast release_version "14") '' - cp -r ${monorepoSrc}/cmake "$out" - '' + '' - cp -r ${monorepoSrc}/${pname} "$out" - '' + lib.optionalString (lib.versionAtLeast release_version "14") '' - cp -r ${monorepoSrc}/third-party "$out" - '' + lib.optionalString enablePolly '' - chmod u+w "$out/${pname}/tools" - cp -r ${monorepoSrc}/polly "$out/${pname}/tools" - '') else src; + src' = + if monorepoSrc != null then + runCommand "${pname}-src-${version}" { inherit (monorepoSrc) passthru; } ( + '' + mkdir -p "$out" + '' + + lib.optionalString (lib.versionAtLeast release_version "14") '' + cp -r ${monorepoSrc}/cmake "$out" + '' + + '' + cp -r ${monorepoSrc}/${pname} "$out" + '' + + lib.optionalString (lib.versionAtLeast release_version "14") '' + cp -r ${monorepoSrc}/third-party "$out" + '' + + lib.optionalString enablePolly '' + chmod u+w "$out/${pname}/tools" + cp -r ${monorepoSrc}/polly "$out/${pname}/tools" + '' + ) + else + src; patches' = patches ++ lib.optionals enablePolly pollyPatches; in -stdenv.mkDerivation (finalAttrs: { - inherit pname version; - - src = src'; - patches = patches'; - - sourceRoot = "${finalAttrs.src.name}/${pname}"; - - outputs = [ "out" "lib" "dev" "python" ]; - - hardeningDisable = [ - "trivialautovarinit" - "shadowstack" - ]; - - nativeBuildInputs = [ - cmake - # while this is not an autotools build, it still includes a config.guess - # this is needed until scripts are updated to not use /usr/bin/uname on FreeBSD native - updateAutotoolsGnuConfigScriptsHook - ] - ++ (lib.optional (lib.versionAtLeast release_version "15") ninja) - ++ [ python ] - ++ optionals enableManpages [ - # Note: we intentionally use `python3Packages` instead of `python3.pkgs`; - # splicing does *not* work with the latter. (TODO: fix) - python3Packages.sphinx - ] ++ optionals (lib.versionOlder version "18" && enableManpages) [ - python3Packages.recommonmark - ] ++ optionals (lib.versionAtLeast version "18" && enableManpages) [ - python3Packages.myst-parser - ]; - - buildInputs = [ libxml2 libffi ] - ++ optional enablePFM libpfm; # exegesis - - propagatedBuildInputs = (lib.optional (lib.versionAtLeast release_version "14" || stdenv.buildPlatform == stdenv.hostPlatform) ncurses) - ++ [ zlib ]; - - postPatch = optionalString stdenv.hostPlatform.isDarwin ('' - substituteInPlace cmake/modules/AddLLVM.cmake \ - --replace-fail 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" - '' + - # As of LLVM 15, marked as XFAIL on arm64 macOS but lit doesn't seem to pick - # this up: https://github.com/llvm/llvm-project/blob/c344d97a125b18f8fed0a64aace73c49a870e079/llvm/test/MC/ELF/cfi-version.ll#L7 - (optionalString (lib.versionAtLeast release_version "15") ('' - rm test/MC/ELF/cfi-version.ll - - '' + - # This test tries to call `sw_vers` by absolute path (`/usr/bin/sw_vers`) - # and thus fails under the sandbox: - (if lib.versionAtLeast release_version "16" then '' - substituteInPlace unittests/TargetParser/Host.cpp \ - --replace-fail '/usr/bin/sw_vers' "${(builtins.toString darwin.DarwinTools) + "/bin/sw_vers" }" - '' else '' - substituteInPlace unittests/Support/Host.cpp \ - --replace-fail '/usr/bin/sw_vers' "${(builtins.toString darwin.DarwinTools) + "/bin/sw_vers" }" - '') + - # This test tries to call the intrinsics `@llvm.roundeven.f32` and - # `@llvm.roundeven.f64` which seem to (incorrectly?) lower to `roundevenf` - # and `roundeven` on macOS and FreeBSD. - # - # However these functions are glibc specific so the test fails: - # - https://www.gnu.org/software/gnulib/manual/html_node/roundevenf.html - # - https://www.gnu.org/software/gnulib/manual/html_node/roundeven.html - # - # TODO(@rrbutani): this seems to run fine on `aarch64-darwin`, why does it - # pass there? - optionalString (lib.versionAtLeast release_version "16") '' - substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \ - --replace-fail "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \ - --replace-fail "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" "" - '' + - # fails when run in sandbox - optionalString (!stdenv.hostPlatform.isx86 && lib.versionAtLeast release_version "18") '' - substituteInPlace unittests/Support/VirtualFileSystemTest.cpp \ - --replace-fail "PhysicalFileSystemWorkingDirFailure" "DISABLED_PhysicalFileSystemWorkingDirFailure" - ''))) + - # dup of above patch with different conditions - optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86 && lib.versionAtLeast release_version "15") (optionalString (lib.versionOlder release_version "16") '' - substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \ - --replace-fail "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \ - --replace-fail "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" "" - - '' + - # fails when run in sandbox - ((optionalString (lib.versionAtLeast release_version "18") '' - substituteInPlace unittests/Support/VirtualFileSystemTest.cpp \ - --replace-fail "PhysicalFileSystemWorkingDirFailure" "DISABLED_PhysicalFileSystemWorkingDirFailure" - '') + - # This test fails on darwin x86_64 because `sw_vers` reports a different - # macOS version than what LLVM finds by reading - # `/System/Library/CoreServices/SystemVersion.plist` (which is passed into - # the sandbox on macOS). - # - # The `sw_vers` provided by nixpkgs reports the macOS version associated - # with the `CoreFoundation` framework with which it was built. Because - # nixpkgs pins the SDK for `aarch64-darwin` and `x86_64-darwin` what - # `sw_vers` reports is not guaranteed to match the macOS version of the host - # that's building this derivation. - # - # Astute readers will note that we only _patch_ this test on aarch64-darwin - # (to use the nixpkgs provided `sw_vers`) instead of disabling it outright. - # So why does this test pass on aarch64? - # - # Well, it seems that `sw_vers` on aarch64 actually links against the _host_ - # CoreFoundation framework instead of the nixpkgs provided one. - # - # Not entirely sure what the right fix is here. I'm assuming aarch64 - # `sw_vers` doesn't intentionally link against the host `CoreFoundation` - # (still digging into how this ends up happening, will follow up) but that - # aside I think the more pertinent question is: should we be patching LLVM's - # macOS version detection logic to use `sw_vers` instead of reading host - # paths? This *is* a way in which details about builder machines can creep - # into the artifacts that are produced, affecting reproducibility, but it's - # not clear to me when/where/for what this even gets used in LLVM. - # - # TODO(@rrbutani): fix/follow-up - (if lib.versionAtLeast release_version "16" then '' - substituteInPlace unittests/TargetParser/Host.cpp \ - --replace-fail "getMacOSHostVersion" "DISABLED_getMacOSHostVersion" - '' else '' - substituteInPlace unittests/Support/Host.cpp \ - --replace-fail "getMacOSHostVersion" "DISABLED_getMacOSHostVersion" - '') + - # This test fails with a `dysmutil` crash; have not yet dug into what's - # going on here (TODO(@rrbutani)). - lib.optionalString (lib.versionOlder release_version "19") '' - rm test/tools/dsymutil/ARM/obfuscated.test - '')) + - # FileSystem permissions tests fail with various special bits - '' - substituteInPlace unittests/Support/CMakeLists.txt \ - --replace-fail "Path.cpp" "" - rm unittests/Support/Path.cpp - substituteInPlace unittests/IR/CMakeLists.txt \ - --replace-fail "PassBuilderCallbacksTest.cpp" "" - rm unittests/IR/PassBuilderCallbacksTest.cpp - '' + lib.optionalString (lib.versionAtLeast release_version "13") '' - rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test - '' + lib.optionalString (lib.versionOlder release_version "13") '' - # TODO: Fix failing tests: - rm test/DebugInfo/X86/vla-multi.ll - '' + - # Fails in the presence of anti-virus software or other intrusion-detection software that - # modifies the atime when run. See #284056. - lib.optionalString (lib.versionAtLeast release_version "16") ('' - rm test/tools/llvm-objcopy/ELF/strip-preserve-atime.test - '' + lib.optionalString (lib.versionOlder release_version "17") '' - - '') + - # timing-based tests are trouble - lib.optionalString (lib.versionAtLeast release_version "15" && lib.versionOlder release_version "17") '' - rm utils/lit/tests/googletest-timeout.py - '' + - # valgrind unhappy with musl or glibc, but fails w/musl only - optionalString stdenv.hostPlatform.isMusl '' - patch -p1 -i ${./TLI-musl.patch} - substituteInPlace unittests/Support/CMakeLists.txt \ - --replace-fail "add_subdirectory(DynamicLibrary)" "" - rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp - rm test/CodeGen/AArch64/wineh4.mir - '' + optionalString stdenv.hostPlatform.isAarch32 '' - # skip failing X86 test cases on 32-bit ARM - rm test/DebugInfo/X86/convert-debugloc.ll - rm test/DebugInfo/X86/convert-inlined.ll - rm test/DebugInfo/X86/convert-linked.ll - rm test/tools/dsymutil/X86/op-convert.test - rm test/tools/gold/X86/split-dwarf.ll - rm test/tools/llvm-objcopy/MachO/universal-object.test - '' + - # Seems to require certain floating point hardware (NEON?) - optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' - rm test/ExecutionEngine/frem.ll - '' + - # 1. TODO: Why does this test fail on FreeBSD? - # It seems to reference /usr/local/lib/libfile.a, which is clearly a problem. - # 2. This test fails for the same reason it fails on MacOS, but the fix is - # not trivial to apply. - optionalString stdenv.hostPlatform.isFreeBSD '' - rm test/tools/llvm-libtool-darwin/L-and-l.test - rm test/ExecutionEngine/Interpreter/intrinsics.ll - '' + '' - patchShebangs test/BugPoint/compile-custom.ll.py - '' + - # Tweak tests to ignore namespace part of type to support - # gcc-12: https://gcc.gnu.org/PR103598. - # The change below mangles strings like: - # CHECK-NEXT: Starting llvm::Function pass manager run. - # to: - # CHECK-NEXT: Starting {{.*}}Function pass manager run. - (lib.optionalString (lib.versionOlder release_version "13") ('' - for f in \ - test/Other/new-pass-manager.ll \ - test/Other/new-pm-O0-defaults.ll \ - test/Other/new-pm-defaults.ll \ - test/Other/new-pm-lto-defaults.ll \ - test/Other/new-pm-thinlto-defaults.ll \ - test/Other/pass-pipeline-parsing.ll \ - test/Transforms/Inline/cgscc-incremental-invalidate.ll \ - test/Transforms/Inline/clear-analyses.ll \ - test/Transforms/LoopUnroll/unroll-loop-invalidation.ll \ - test/Transforms/SCCP/ipsccp-preserve-analysis.ll \ - test/Transforms/SCCP/preserve-analysis.ll \ - test/Transforms/SROA/dead-inst.ll \ - test/tools/gold/X86/new-pm.ll \ - ; do - echo "PATCH: $f" - substituteInPlace $f \ - --replace-quiet 'Starting llvm::' 'Starting {{.*}}' \ - --replace-quiet 'Finished llvm::' 'Finished {{.*}}' - done - '' + - # gcc-13 fix - '' - sed -i '/#include /i#include ' \ - include/llvm/DebugInfo/Symbolize/DIPrinter.h - '')); - - # Workaround for configure flags that need to have spaces - preConfigure = if lib.versionAtLeast release_version "15" then '' - cmakeFlagsArray+=( - -DLLVM_LIT_ARGS="-svj''${NIX_BUILD_CORES} --no-progress-bar" - ) - '' else '' - cmakeFlagsArray+=( - -DLLVM_LIT_ARGS='-svj''${NIX_BUILD_CORES} --no-progress-bar' - ) - ''; +stdenv.mkDerivation ( + finalAttrs: + { + inherit pname version; - # E.g. Mesa uses the build-id as a cache key (see #93946): - LDFLAGS = optionalString (enableSharedLibraries && !stdenv.hostPlatform.isDarwin) "-Wl,--build-id=sha1"; + src = src'; + patches = patches'; - cmakeBuildType = if debugVersion then "Debug" else "Release"; + sourceRoot = "${finalAttrs.src.name}/${pname}"; - cmakeFlags = let - # These flags influence llvm-config's BuildVariables.inc in addition to the - # general build. We need to make sure these are also passed via - # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native - # will return different results from the cross llvm-config. - # - # Some flags don't need to be repassed because LLVM already does so (like - # CMAKE_BUILD_TYPE), others are irrelevant to the result. - flagsForLlvmConfig = (if lib.versionOlder release_version "15" then [ - "-DLLVM_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake/llvm/" - ] else [ - "-DLLVM_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/llvm" - ]) ++ [ - "-DLLVM_ENABLE_RTTI=ON" - ] ++ optionals enableSharedLibraries [ - "-DLLVM_LINK_LLVM_DYLIB=ON" + outputs = [ + "out" + "lib" + "dev" + "python" ]; - in flagsForLlvmConfig ++ [ - "-DLLVM_TABLEGEN=${buildLlvmTools.tblgen}/bin/llvm-tblgen" - "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc - "-DLLVM_BUILD_TESTS=${if finalAttrs.finalPackage.doCheck then "ON" else "OFF"}" - "-DLLVM_ENABLE_FFI=ON" - "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" - "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" - "-DLLVM_ENABLE_DUMP=ON" - (lib.cmakeBool "LLVM_ENABLE_TERMINFO" enableTerminfo) - ] ++ optionals (!finalAttrs.finalPackage.doCheck) [ - "-DLLVM_INCLUDE_TESTS=OFF" - ] ++ optionals stdenv.hostPlatform.isStatic [ - # Disables building of shared libs, -fPIC is still injected by cc-wrapper - "-DLLVM_ENABLE_PIC=OFF" - "-DCMAKE_SKIP_INSTALL_RPATH=ON" - "-DLLVM_BUILD_STATIC=ON" - # libxml2 needs to be disabled because the LLVM build system ignores its .la - # file and doesn't link zlib as well. - # https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812 - "-DLLVM_ENABLE_LIBXML2=OFF" - ] ++ optionals enableManpages [ - "-DLLVM_BUILD_DOCS=ON" - "-DLLVM_ENABLE_SPHINX=ON" - "-DSPHINX_OUTPUT_MAN=ON" - "-DSPHINX_OUTPUT_HTML=OFF" - "-DSPHINX_WARNINGS_AS_ERRORS=OFF" - ] ++ optionals (libbfd != null) [ - # LLVM depends on binutils only through libbfd/include/plugin-api.h, which - # is meant to be a stable interface. Depend on that file directly rather - # than through a build of BFD to break the dependency of clang on the target - # triple. The result of this is that a single clang build can be used for - # multiple targets. - "-DLLVM_BINUTILS_INCDIR=${libbfd.plugin-api-header}/include" - ] ++ optionals stdenv.hostPlatform.isDarwin [ - "-DLLVM_ENABLE_LIBCXX=ON" - "-DCAN_TARGET_i386=false" - ] ++ optionals ((stdenv.hostPlatform != stdenv.buildPlatform) && !(stdenv.buildPlatform.canExecute stdenv.hostPlatform)) [ - "-DCMAKE_CROSSCOMPILING=True" - ( + + hardeningDisable = [ + "trivialautovarinit" + "shadowstack" + ]; + + nativeBuildInputs = + [ + cmake + # while this is not an autotools build, it still includes a config.guess + # this is needed until scripts are updated to not use /usr/bin/uname on FreeBSD native + updateAutotoolsGnuConfigScriptsHook + ] + ++ (lib.optional (lib.versionAtLeast release_version "15") ninja) + ++ [ python ] + ++ optionals enableManpages [ + # Note: we intentionally use `python3Packages` instead of `python3.pkgs`; + # splicing does *not* work with the latter. (TODO: fix) + python3Packages.sphinx + ] + ++ optionals (lib.versionOlder version "18" && enableManpages) [ + python3Packages.recommonmark + ] + ++ optionals (lib.versionAtLeast version "18" && enableManpages) [ + python3Packages.myst-parser + ]; + + buildInputs = [ + libxml2 + libffi + ] ++ optional enablePFM libpfm; # exegesis + + propagatedBuildInputs = + (lib.optional ( + lib.versionAtLeast release_version "14" || stdenv.buildPlatform == stdenv.hostPlatform + ) ncurses) + ++ [ zlib ]; + + postPatch = + optionalString stdenv.hostPlatform.isDarwin ( + '' + substituteInPlace cmake/modules/AddLLVM.cmake \ + --replace-fail 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" + '' + + + # As of LLVM 15, marked as XFAIL on arm64 macOS but lit doesn't seem to pick + # this up: https://github.com/llvm/llvm-project/blob/c344d97a125b18f8fed0a64aace73c49a870e079/llvm/test/MC/ELF/cfi-version.ll#L7 + (optionalString (lib.versionAtLeast release_version "15") ( + '' + rm test/MC/ELF/cfi-version.ll + + '' + + + # This test tries to call `sw_vers` by absolute path (`/usr/bin/sw_vers`) + # and thus fails under the sandbox: + ( + if lib.versionAtLeast release_version "16" then + '' + substituteInPlace unittests/TargetParser/Host.cpp \ + --replace-fail '/usr/bin/sw_vers' "${(builtins.toString darwin.DarwinTools) + "/bin/sw_vers"}" + '' + else + '' + substituteInPlace unittests/Support/Host.cpp \ + --replace-fail '/usr/bin/sw_vers' "${(builtins.toString darwin.DarwinTools) + "/bin/sw_vers"}" + '' + ) + + + # This test tries to call the intrinsics `@llvm.roundeven.f32` and + # `@llvm.roundeven.f64` which seem to (incorrectly?) lower to `roundevenf` + # and `roundeven` on macOS and FreeBSD. + # + # However these functions are glibc specific so the test fails: + # - https://www.gnu.org/software/gnulib/manual/html_node/roundevenf.html + # - https://www.gnu.org/software/gnulib/manual/html_node/roundeven.html + # + # TODO(@rrbutani): this seems to run fine on `aarch64-darwin`, why does it + # pass there? + optionalString (lib.versionAtLeast release_version "16") '' + substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \ + --replace-fail "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \ + --replace-fail "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" "" + '' + + + # fails when run in sandbox + optionalString (!stdenv.hostPlatform.isx86 && lib.versionAtLeast release_version "18") '' + substituteInPlace unittests/Support/VirtualFileSystemTest.cpp \ + --replace-fail "PhysicalFileSystemWorkingDirFailure" "DISABLED_PhysicalFileSystemWorkingDirFailure" + '' + )) + ) + + + # dup of above patch with different conditions + optionalString + ( + stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86 && lib.versionAtLeast release_version "15" + ) + ( + optionalString (lib.versionOlder release_version "16") '' + substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \ + --replace-fail "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \ + --replace-fail "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" "" + + '' + + + # fails when run in sandbox + ( + (optionalString (lib.versionAtLeast release_version "18") '' + substituteInPlace unittests/Support/VirtualFileSystemTest.cpp \ + --replace-fail "PhysicalFileSystemWorkingDirFailure" "DISABLED_PhysicalFileSystemWorkingDirFailure" + '') + + + # This test fails on darwin x86_64 because `sw_vers` reports a different + # macOS version than what LLVM finds by reading + # `/System/Library/CoreServices/SystemVersion.plist` (which is passed into + # the sandbox on macOS). + # + # The `sw_vers` provided by nixpkgs reports the macOS version associated + # with the `CoreFoundation` framework with which it was built. Because + # nixpkgs pins the SDK for `aarch64-darwin` and `x86_64-darwin` what + # `sw_vers` reports is not guaranteed to match the macOS version of the host + # that's building this derivation. + # + # Astute readers will note that we only _patch_ this test on aarch64-darwin + # (to use the nixpkgs provided `sw_vers`) instead of disabling it outright. + # So why does this test pass on aarch64? + # + # Well, it seems that `sw_vers` on aarch64 actually links against the _host_ + # CoreFoundation framework instead of the nixpkgs provided one. + # + # Not entirely sure what the right fix is here. I'm assuming aarch64 + # `sw_vers` doesn't intentionally link against the host `CoreFoundation` + # (still digging into how this ends up happening, will follow up) but that + # aside I think the more pertinent question is: should we be patching LLVM's + # macOS version detection logic to use `sw_vers` instead of reading host + # paths? This *is* a way in which details about builder machines can creep + # into the artifacts that are produced, affecting reproducibility, but it's + # not clear to me when/where/for what this even gets used in LLVM. + # + # TODO(@rrbutani): fix/follow-up + ( + if lib.versionAtLeast release_version "16" then + '' + substituteInPlace unittests/TargetParser/Host.cpp \ + --replace-fail "getMacOSHostVersion" "DISABLED_getMacOSHostVersion" + '' + else + '' + substituteInPlace unittests/Support/Host.cpp \ + --replace-fail "getMacOSHostVersion" "DISABLED_getMacOSHostVersion" + '' + ) + + + # This test fails with a `dysmutil` crash; have not yet dug into what's + # going on here (TODO(@rrbutani)). + lib.optionalString (lib.versionOlder release_version "19") '' + rm test/tools/dsymutil/ARM/obfuscated.test + '' + ) + ) + + + # FileSystem permissions tests fail with various special bits + '' + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace-fail "Path.cpp" "" + rm unittests/Support/Path.cpp + substituteInPlace unittests/IR/CMakeLists.txt \ + --replace-fail "PassBuilderCallbacksTest.cpp" "" + rm unittests/IR/PassBuilderCallbacksTest.cpp + '' + + lib.optionalString (lib.versionAtLeast release_version "13") '' + rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test + '' + + lib.optionalString (lib.versionOlder release_version "13") '' + # TODO: Fix failing tests: + rm test/DebugInfo/X86/vla-multi.ll + '' + + + # Fails in the presence of anti-virus software or other intrusion-detection software that + # modifies the atime when run. See #284056. + lib.optionalString (lib.versionAtLeast release_version "16") ( + '' + rm test/tools/llvm-objcopy/ELF/strip-preserve-atime.test + '' + + lib.optionalString (lib.versionOlder release_version "17") '' + + '' + ) + + + # timing-based tests are trouble + lib.optionalString + (lib.versionAtLeast release_version "15" && lib.versionOlder release_version "17") + '' + rm utils/lit/tests/googletest-timeout.py + '' + + + # valgrind unhappy with musl or glibc, but fails w/musl only + optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -i ${./TLI-musl.patch} + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace-fail "add_subdirectory(DynamicLibrary)" "" + rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp + rm test/CodeGen/AArch64/wineh4.mir + '' + + optionalString stdenv.hostPlatform.isAarch32 '' + # skip failing X86 test cases on 32-bit ARM + rm test/DebugInfo/X86/convert-debugloc.ll + rm test/DebugInfo/X86/convert-inlined.ll + rm test/DebugInfo/X86/convert-linked.ll + rm test/tools/dsymutil/X86/op-convert.test + rm test/tools/gold/X86/split-dwarf.ll + rm test/tools/llvm-objcopy/MachO/universal-object.test + '' + + + # Seems to require certain floating point hardware (NEON?) + optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' + rm test/ExecutionEngine/frem.ll + '' + + + # 1. TODO: Why does this test fail on FreeBSD? + # It seems to reference /usr/local/lib/libfile.a, which is clearly a problem. + # 2. This test fails for the same reason it fails on MacOS, but the fix is + # not trivial to apply. + optionalString stdenv.hostPlatform.isFreeBSD '' + rm test/tools/llvm-libtool-darwin/L-and-l.test + rm test/ExecutionEngine/Interpreter/intrinsics.ll + '' + + '' + patchShebangs test/BugPoint/compile-custom.ll.py + '' + + + # Tweak tests to ignore namespace part of type to support + # gcc-12: https://gcc.gnu.org/PR103598. + # The change below mangles strings like: + # CHECK-NEXT: Starting llvm::Function pass manager run. + # to: + # CHECK-NEXT: Starting {{.*}}Function pass manager run. + (lib.optionalString (lib.versionOlder release_version "13") ( + '' + for f in \ + test/Other/new-pass-manager.ll \ + test/Other/new-pm-O0-defaults.ll \ + test/Other/new-pm-defaults.ll \ + test/Other/new-pm-lto-defaults.ll \ + test/Other/new-pm-thinlto-defaults.ll \ + test/Other/pass-pipeline-parsing.ll \ + test/Transforms/Inline/cgscc-incremental-invalidate.ll \ + test/Transforms/Inline/clear-analyses.ll \ + test/Transforms/LoopUnroll/unroll-loop-invalidation.ll \ + test/Transforms/SCCP/ipsccp-preserve-analysis.ll \ + test/Transforms/SCCP/preserve-analysis.ll \ + test/Transforms/SROA/dead-inst.ll \ + test/tools/gold/X86/new-pm.ll \ + ; do + echo "PATCH: $f" + substituteInPlace $f \ + --replace-quiet 'Starting llvm::' 'Starting {{.*}}' \ + --replace-quiet 'Finished llvm::' 'Finished {{.*}}' + done + '' + + + # gcc-13 fix + '' + sed -i '/#include /i#include ' \ + include/llvm/DebugInfo/Symbolize/DIPrinter.h + '' + )); + + # Workaround for configure flags that need to have spaces + preConfigure = + if lib.versionAtLeast release_version "15" then + '' + cmakeFlagsArray+=( + -DLLVM_LIT_ARGS="-svj''${NIX_BUILD_CORES} --no-progress-bar" + ) + '' + else + '' + cmakeFlagsArray+=( + -DLLVM_LIT_ARGS='-svj''${NIX_BUILD_CORES} --no-progress-bar' + ) + ''; + + # E.g. Mesa uses the build-id as a cache key (see #93946): + LDFLAGS = optionalString ( + enableSharedLibraries && !stdenv.hostPlatform.isDarwin + ) "-Wl,--build-id=sha1"; + + cmakeBuildType = if debugVersion then "Debug" else "Release"; + + cmakeFlags = let - nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; - nativeBintools = nativeCC.bintools.bintools; - nativeToolchainFlags = [ - "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" - "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" - "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" - "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" - "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" - ]; - # We need to repass the custom GNUInstallDirs values, otherwise CMake - # will choose them for us, leading to wrong results in llvm-config-native - nativeInstallFlags = [ - "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" - "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin" - "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include" - "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" - "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" - ]; - in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" - + lib.concatStringsSep ";" (lib.concatLists [ - flagsForLlvmConfig - nativeToolchainFlags - nativeInstallFlags - ]) + # These flags influence llvm-config's BuildVariables.inc in addition to the + # general build. We need to make sure these are also passed via + # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native + # will return different results from the cross llvm-config. + # + # Some flags don't need to be repassed because LLVM already does so (like + # CMAKE_BUILD_TYPE), others are irrelevant to the result. + flagsForLlvmConfig = + ( + if lib.versionOlder release_version "15" then + [ + "-DLLVM_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake/llvm/" + ] + else + [ + "-DLLVM_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/llvm" + ] + ) + ++ [ + "-DLLVM_ENABLE_RTTI=ON" + ] + ++ optionals enableSharedLibraries [ + "-DLLVM_LINK_LLVM_DYLIB=ON" + ]; + in + flagsForLlvmConfig + ++ [ + "-DLLVM_TABLEGEN=${buildLlvmTools.tblgen}/bin/llvm-tblgen" + "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc + "-DLLVM_BUILD_TESTS=${if finalAttrs.finalPackage.doCheck then "ON" else "OFF"}" + "-DLLVM_ENABLE_FFI=ON" + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_ENABLE_DUMP=ON" + (lib.cmakeBool "LLVM_ENABLE_TERMINFO" enableTerminfo) + ] + ++ optionals (!finalAttrs.finalPackage.doCheck) [ + "-DLLVM_INCLUDE_TESTS=OFF" + ] + ++ optionals stdenv.hostPlatform.isStatic [ + # Disables building of shared libs, -fPIC is still injected by cc-wrapper + "-DLLVM_ENABLE_PIC=OFF" + "-DCMAKE_SKIP_INSTALL_RPATH=ON" + "-DLLVM_BUILD_STATIC=ON" + # libxml2 needs to be disabled because the LLVM build system ignores its .la + # file and doesn't link zlib as well. + # https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812 + "-DLLVM_ENABLE_LIBXML2=OFF" + ] + ++ optionals enableManpages [ + "-DLLVM_BUILD_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] + ++ optionals (libbfd != null) [ + # LLVM depends on binutils only through libbfd/include/plugin-api.h, which + # is meant to be a stable interface. Depend on that file directly rather + # than through a build of BFD to break the dependency of clang on the target + # triple. The result of this is that a single clang build can be used for + # multiple targets. + "-DLLVM_BINUTILS_INCDIR=${libbfd.plugin-api-header}/include" + ] + ++ optionals stdenv.hostPlatform.isDarwin [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DCAN_TARGET_i386=false" + ] + ++ + optionals + ( + (stdenv.hostPlatform != stdenv.buildPlatform) + && !(stdenv.buildPlatform.canExecute stdenv.hostPlatform) + ) + [ + "-DCMAKE_CROSSCOMPILING=True" + ( + let + nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; + nativeBintools = nativeCC.bintools.bintools; + nativeToolchainFlags = [ + "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" + "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" + "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" + "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" + "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" + ]; + # We need to repass the custom GNUInstallDirs values, otherwise CMake + # will choose them for us, leading to wrong results in llvm-config-native + nativeInstallFlags = [ + "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" + "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin" + "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include" + "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" + "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" + ]; + in + "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" + + lib.concatStringsSep ";" ( + lib.concatLists [ + flagsForLlvmConfig + nativeToolchainFlags + nativeInstallFlags + ] + ) + ) + ] + ++ devExtraCmakeFlags; + + postInstall = + '' + mkdir -p $python/share + mv $out/share/opt-viewer $python/share/opt-viewer + moveToOutput "bin/llvm-config*" "$dev" + substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${ + if debugVersion then "debug" else "release" + }.cmake" \ + --replace-fail "$out/bin/llvm-config" "$dev/bin/llvm-config" + '' + + ( + if lib.versionOlder release_version "15" then + '' + substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ + --replace-fail 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}'"$lib"'")' + '' + else + '' + substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ + --replace-fail 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "'"$lib"'")' + '' + ) + + + optionalString + (stdenv.hostPlatform.isDarwin && enableSharedLibraries && lib.versionOlder release_version "18") + '' + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib + '' + + optionalString (stdenv.hostPlatform.isDarwin && enableSharedLibraries) '' + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib + '' + + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ( + if stdenv.buildPlatform.canExecute stdenv.hostPlatform then + '' + ln -s $dev/bin/llvm-config $dev/bin/llvm-config-native + '' + else + '' + cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native + '' + ); + + doCheck = !isDarwinBootstrap && doCheck; + + checkTarget = "check-all"; + + # For the update script: + passthru.monorepoSrc = monorepoSrc; + + requiredSystemFeatures = [ "big-parallel" ]; + meta = llvm_meta // { + homepage = "https://llvm.org/"; + description = "Collection of modular and reusable compiler and toolchain technologies"; + longDescription = '' + The LLVM Project is a collection of modular and reusable compiler and + toolchain technologies. Despite its name, LLVM has little to do with + traditional virtual machines. The name "LLVM" itself is not an acronym; it + is the full name of the project. + LLVM began as a research project at the University of Illinois, with the + goal of providing a modern, SSA-based compilation strategy capable of + supporting both static and dynamic compilation of arbitrary programming + languages. Since then, LLVM has grown to be an umbrella project consisting + of a number of subprojects, many of which are being used in production by + a wide variety of commercial and open source projects as well as being + widely used in academic research. Code in the LLVM project is licensed + under the "Apache 2.0 License with LLVM exceptions". + ''; + }; + } + // lib.optionalAttrs enableManpages ( + { + pname = "llvm-manpages"; + + propagatedBuildInputs = [ ]; + + postPatch = null; + postInstall = null; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man pages for LLVM ${version}"; + }; + } + // ( + if lib.versionOlder release_version "15" then + { + buildPhase = '' + make docs-llvm-man + ''; + + installPhase = '' + make -C docs install + ''; + } + else + { + ninjaFlags = [ "docs-llvm-man" ]; + installTargets = [ "install-docs-llvm-man" ]; + + postPatch = null; + postInstall = null; + } ) - ] ++ devExtraCmakeFlags; - - postInstall = '' - mkdir -p $python/share - mv $out/share/opt-viewer $python/share/opt-viewer - moveToOutput "bin/llvm-config*" "$dev" - substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ - --replace-fail "$out/bin/llvm-config" "$dev/bin/llvm-config" - '' + (if lib.versionOlder release_version "15" then '' - substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ - --replace-fail 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}'"$lib"'")' - '' else '' - substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ - --replace-fail 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "'"$lib"'")' - '') - + optionalString (stdenv.hostPlatform.isDarwin && enableSharedLibraries && lib.versionOlder release_version "18") '' - ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib - '' - + optionalString (stdenv.hostPlatform.isDarwin && enableSharedLibraries) '' - ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib - '' - + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) (if stdenv.buildPlatform.canExecute stdenv.hostPlatform then '' - ln -s $dev/bin/llvm-config $dev/bin/llvm-config-native - '' else '' - cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native - ''); - - doCheck = !isDarwinBootstrap && doCheck; - - checkTarget = "check-all"; - - # For the update script: - passthru.monorepoSrc = monorepoSrc; - - requiredSystemFeatures = [ "big-parallel" ]; - meta = llvm_meta // { - homepage = "https://llvm.org/"; - description = "Collection of modular and reusable compiler and toolchain technologies"; - longDescription = '' - The LLVM Project is a collection of modular and reusable compiler and - toolchain technologies. Despite its name, LLVM has little to do with - traditional virtual machines. The name "LLVM" itself is not an acronym; it - is the full name of the project. - LLVM began as a research project at the University of Illinois, with the - goal of providing a modern, SSA-based compilation strategy capable of - supporting both static and dynamic compilation of arbitrary programming - languages. Since then, LLVM has grown to be an umbrella project consisting - of a number of subprojects, many of which are being used in production by - a wide variety of commercial and open source projects as well as being - widely used in academic research. Code in the LLVM project is licensed - under the "Apache 2.0 License with LLVM exceptions". + ) + // lib.optionalAttrs (lib.versionAtLeast release_version "13") { + nativeCheckInputs = [ + which + ] ++ lib.optional (stdenv.hostPlatform.isDarwin && lib.versionAtLeast release_version "15") sysctl; + } + // lib.optionalAttrs (lib.versionOlder release_version "15") { + # hacky fix: created binaries need to be run before installation + preBuild = '' + mkdir -p $out/ + ln -sv $PWD/lib $out ''; - }; -} // lib.optionalAttrs enableManpages ({ - pname = "llvm-manpages"; - - propagatedBuildInputs = []; - - postPatch = null; - postInstall = null; - - outputs = [ "out" ]; - - doCheck = false; - - meta = llvm_meta // { - description = "man pages for LLVM ${version}"; - }; -} // (if lib.versionOlder release_version "15" then { - buildPhase = '' - make docs-llvm-man - ''; - - installPhase = '' - make -C docs install - ''; -} else { - ninjaFlags = [ "docs-llvm-man" ]; - installTargets = [ "install-docs-llvm-man" ]; - - postPatch = null; - postInstall = null; -})) // lib.optionalAttrs (lib.versionAtLeast release_version "13") { - nativeCheckInputs = [ which ] ++ lib.optional (stdenv.hostPlatform.isDarwin && lib.versionAtLeast release_version "15") sysctl; -} // lib.optionalAttrs (lib.versionOlder release_version "15") { - # hacky fix: created binaries need to be run before installation - preBuild = '' - mkdir -p $out/ - ln -sv $PWD/lib $out - ''; - - postBuild = '' - rm -fR $out - ''; - - preCheck = '' - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib - ''; -} // lib.optionalAttrs (lib.versionAtLeast release_version "15") { - # Defensive check: some paths (that we make symlinks to) depend on the release - # version, for example: - # - https://github.com/llvm/llvm-project/blob/406bde9a15136254f2b10d9ef3a42033b3cb1b16/clang/lib/Headers/CMakeLists.txt#L185 - # - # So we want to sure that the version in the source matches the release - # version we were given. - # - # We do this check here, in the LLVM build, because it happens early. - postConfigure = let - v = lib.versions; - major = v.major release_version; - minor = v.minor release_version; - patch = v.patch release_version; - in '' - # $1: part, $2: expected - check_version() { - part="''${1^^}" - part="$(cat include/llvm/Config/llvm-config.h | grep "#define LLVM_VERSION_''${part} " | cut -d' ' -f3)" - - if [[ "$part" != "$2" ]]; then - echo >&2 \ - "mismatch in the $1 version! we have version ${release_version}" \ - "and expected the $1 version to be '$2'; the source has '$part' instead" - exit 3 - fi - } - check_version major ${major} - check_version minor ${minor} - check_version patch ${patch} - ''; -}) + postBuild = '' + rm -fR $out + ''; + + preCheck = '' + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib + ''; + } + // lib.optionalAttrs (lib.versionAtLeast release_version "15") { + # Defensive check: some paths (that we make symlinks to) depend on the release + # version, for example: + # - https://github.com/llvm/llvm-project/blob/406bde9a15136254f2b10d9ef3a42033b3cb1b16/clang/lib/Headers/CMakeLists.txt#L185 + # + # So we want to sure that the version in the source matches the release + # version we were given. + # + # We do this check here, in the LLVM build, because it happens early. + postConfigure = + let + v = lib.versions; + major = v.major release_version; + minor = v.minor release_version; + patch = v.patch release_version; + in + '' + # $1: part, $2: expected + check_version() { + part="''${1^^}" + part="$(cat include/llvm/Config/llvm-config.h | grep "#define LLVM_VERSION_''${part} " | cut -d' ' -f3)" + + if [[ "$part" != "$2" ]]; then + echo >&2 \ + "mismatch in the $1 version! we have version ${release_version}" \ + "and expected the $1 version to be '$2'; the source has '$part' instead" + exit 3 + fi + } + + check_version major ${major} + check_version minor ${minor} + check_version patch ${patch} + ''; + } +) diff --git a/pkgs/development/compilers/llvm/common/mlir/default.nix b/pkgs/development/compilers/llvm/common/mlir/default.nix index 8f2f28c72c65f..24c3f90d1f7ce 100644 --- a/pkgs/development/compilers/llvm/common/mlir/default.nix +++ b/pkgs/development/compilers/llvm/common/mlir/default.nix @@ -1,17 +1,22 @@ -{ lib -, stdenv -, llvm_meta -, release_version -, buildLlvmTools -, monorepoSrc -, runCommand -, cmake -, ninja -, libxml2 -, libllvm -, version -, doCheck ? (!stdenv.hostPlatform.isx86_32 /* TODO: why */) && (!stdenv.hostPlatform.isMusl) -, devExtraCmakeFlags ? [] +{ + lib, + stdenv, + llvm_meta, + release_version, + buildLlvmTools, + monorepoSrc, + runCommand, + cmake, + ninja, + libxml2, + libllvm, + version, + doCheck ? + ( + !stdenv.hostPlatform.isx86_32 # TODO: why + ) + && (!stdenv.hostPlatform.isMusl), + devExtraCmakeFlags ? [ ], }: stdenv.mkDerivation rec { @@ -19,16 +24,20 @@ stdenv.mkDerivation rec { inherit version doCheck; # Blank llvm dir just so relative path works - src = runCommand "${pname}-src-${version}" { inherit (monorepoSrc) passthru; } ('' - mkdir -p "$out" - '' + lib.optionalString (lib.versionAtLeast release_version "14") '' - cp -r ${monorepoSrc}/cmake "$out" - '' + '' - cp -r ${monorepoSrc}/mlir "$out" - cp -r ${monorepoSrc}/third-party "$out/third-party" + src = runCommand "${pname}-src-${version}" { inherit (monorepoSrc) passthru; } ( + '' + mkdir -p "$out" + '' + + lib.optionalString (lib.versionAtLeast release_version "14") '' + cp -r ${monorepoSrc}/cmake "$out" + '' + + '' + cp -r ${monorepoSrc}/mlir "$out" + cp -r ${monorepoSrc}/third-party "$out/third-party" - mkdir -p "$out/llvm" - ''); + mkdir -p "$out/llvm" + '' + ); sourceRoot = "${src.name}/mlir"; @@ -46,29 +55,35 @@ stdenv.mkDerivation rec { libxml2 ]; - cmakeFlags = [ - "-DLLVM_BUILD_TOOLS=ON" - # Install headers as well - "-DLLVM_INSTALL_TOOLCHAIN_ONLY=OFF" - "-DMLIR_TOOLS_INSTALL_DIR=${placeholder "out"}/bin/" - "-DLLVM_ENABLE_IDE=OFF" - "-DMLIR_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/mlir" - "-DMLIR_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake/mlir" - "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" - "-DLLVM_ENABLE_FFI=ON" - "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" - "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" - "-DLLVM_ENABLE_DUMP=ON" - "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.tblgen}/bin/llvm-tblgen" - "-DMLIR_TABLEGEN_EXE=${buildLlvmTools.tblgen}/bin/mlir-tblgen" - ] ++ lib.optionals stdenv.hostPlatform.isStatic [ - # Disables building of shared libs, -fPIC is still injected by cc-wrapper - "-DLLVM_ENABLE_PIC=OFF" - "-DLLVM_BUILD_STATIC=ON" - "-DLLVM_LINK_LLVM_DYLIB=OFF" - ] ++ devExtraCmakeFlags; + cmakeFlags = + [ + "-DLLVM_BUILD_TOOLS=ON" + # Install headers as well + "-DLLVM_INSTALL_TOOLCHAIN_ONLY=OFF" + "-DMLIR_TOOLS_INSTALL_DIR=${placeholder "out"}/bin/" + "-DLLVM_ENABLE_IDE=OFF" + "-DMLIR_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/mlir" + "-DMLIR_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake/mlir" + "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" + "-DLLVM_ENABLE_FFI=ON" + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_ENABLE_DUMP=ON" + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.tblgen}/bin/llvm-tblgen" + "-DMLIR_TABLEGEN_EXE=${buildLlvmTools.tblgen}/bin/mlir-tblgen" + ] + ++ lib.optionals stdenv.hostPlatform.isStatic [ + # Disables building of shared libs, -fPIC is still injected by cc-wrapper + "-DLLVM_ENABLE_PIC=OFF" + "-DLLVM_BUILD_STATIC=ON" + "-DLLVM_LINK_LLVM_DYLIB=OFF" + ] + ++ devExtraCmakeFlags; - outputs = [ "out" "dev" ]; + outputs = [ + "out" + "dev" + ]; meta = llvm_meta // { homepage = "https://mlir.llvm.org/"; diff --git a/pkgs/development/compilers/llvm/common/openmp/default.nix b/pkgs/development/compilers/llvm/common/openmp/default.nix index 68c50e06abd30..2c5f9f8c61f2f 100644 --- a/pkgs/development/compilers/llvm/common/openmp/default.nix +++ b/pkgs/development/compilers/llvm/common/openmp/default.nix @@ -1,86 +1,104 @@ -{ lib -, stdenv -, llvm_meta -, release_version -, patches ? [] -, monorepoSrc ? null -, src ? null -, runCommand -, cmake -, ninja -, llvm -, targetLlvm -, lit -, clang-unwrapped -, perl -, pkg-config -, version -, devExtraCmakeFlags ? [] +{ + lib, + stdenv, + llvm_meta, + release_version, + patches ? [ ], + monorepoSrc ? null, + src ? null, + runCommand, + cmake, + ninja, + llvm, + targetLlvm, + lit, + clang-unwrapped, + perl, + pkg-config, + version, + devExtraCmakeFlags ? [ ], }: let pname = "openmp"; src' = if monorepoSrc != null then - runCommand "${pname}-src-${version}" { inherit (monorepoSrc) passthru; } ('' - mkdir -p "$out" - '' + lib.optionalString (lib.versionAtLeast release_version "14") '' - cp -r ${monorepoSrc}/cmake "$out" - '' + '' - cp -r ${monorepoSrc}/${pname} "$out" - '') else src; + runCommand "${pname}-src-${version}" { inherit (monorepoSrc) passthru; } ( + '' + mkdir -p "$out" + '' + + lib.optionalString (lib.versionAtLeast release_version "14") '' + cp -r ${monorepoSrc}/cmake "$out" + '' + + '' + cp -r ${monorepoSrc}/${pname} "$out" + '' + ) + else + src; in -stdenv.mkDerivation (rec { - inherit pname version patches; +stdenv.mkDerivation ( + rec { + inherit pname version patches; - src = src'; + src = src'; - sourceRoot = "${src.name}/${pname}"; + sourceRoot = "${src.name}/${pname}"; - outputs = [ "out" ] - ++ lib.optionals (lib.versionAtLeast release_version "14") [ "dev" ]; + outputs = [ "out" ] ++ lib.optionals (lib.versionAtLeast release_version "14") [ "dev" ]; - patchFlags = - if lib.versionOlder release_version "14" then [ "-p2" ] - else null; + patchFlags = if lib.versionOlder release_version "14" then [ "-p2" ] else null; - nativeBuildInputs = [ - cmake - ] ++ lib.optionals (lib.versionAtLeast release_version "15") [ - ninja - ] ++ [ perl ] ++ lib.optionals (lib.versionAtLeast release_version "14") [ - pkg-config lit - ]; + nativeBuildInputs = + [ + cmake + ] + ++ lib.optionals (lib.versionAtLeast release_version "15") [ + ninja + ] + ++ [ perl ] + ++ lib.optionals (lib.versionAtLeast release_version "14") [ + pkg-config + lit + ]; - buildInputs = [ - (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) - ]; + buildInputs = [ + (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) + ]; - cmakeFlags = lib.optionals (lib.versions.major release_version == "13") [ - "-DLIBOMPTARGET_BUILD_AMDGCN_BCLIB=OFF" # Building the AMDGCN device RTL fails - ] ++ lib.optionals (lib.versionAtLeast release_version "14") [ - "-DCLANG_TOOL=${clang-unwrapped}/bin/clang" - "-DOPT_TOOL=${llvm}/bin/opt" - "-DLINK_TOOL=${llvm}/bin/llvm-link" - ] ++ devExtraCmakeFlags; + cmakeFlags = + lib.optionals (lib.versions.major release_version == "13") [ + "-DLIBOMPTARGET_BUILD_AMDGCN_BCLIB=OFF" # Building the AMDGCN device RTL fails + ] + ++ lib.optionals (lib.versionAtLeast release_version "14") [ + "-DCLANG_TOOL=${clang-unwrapped}/bin/clang" + "-DOPT_TOOL=${llvm}/bin/opt" + "-DLINK_TOOL=${llvm}/bin/llvm-link" + ] + ++ devExtraCmakeFlags; - meta = llvm_meta // { - homepage = "https://openmp.llvm.org/"; - description = "Support for the OpenMP language"; - longDescription = '' - The OpenMP subproject of LLVM contains the components required to build an - executable OpenMP program that are outside the compiler itself. - Contains the code for the runtime library against which code compiled by - "clang -fopenmp" must be linked before it can run and the library that - supports offload to target devices. + meta = llvm_meta // { + homepage = "https://openmp.llvm.org/"; + description = "Support for the OpenMP language"; + longDescription = '' + The OpenMP subproject of LLVM contains the components required to build an + executable OpenMP program that are outside the compiler itself. + Contains the code for the runtime library against which code compiled by + "clang -fopenmp" must be linked before it can run and the library that + supports offload to target devices. + ''; + # "All of the code is dual licensed under the MIT license and the UIUC + # License (a BSD-like license)": + license = with lib.licenses; [ + mit + ncsa + ]; + }; + } + // (lib.optionalAttrs (lib.versionAtLeast release_version "14") { + doCheck = false; + checkTarget = "check-openmp"; + preCheck = '' + patchShebangs ../tools/archer/tests/deflake.bash ''; - # "All of the code is dual licensed under the MIT license and the UIUC - # License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; - }; -} // (lib.optionalAttrs (lib.versionAtLeast release_version "14") { - doCheck = false; - checkTarget = "check-openmp"; - preCheck = '' - patchShebangs ../tools/archer/tests/deflake.bash - ''; -})) + }) +)