From 7b0d16c5eca1fd7cb239db7a6e9a4dc11a30fa5a Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 28 Oct 2023 20:11:47 -0400 Subject: [PATCH 01/18] llvmPackages_5.clang: use the stdenv libc++ on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change treats the top-level libc++ as the “system” libc++ on Darwin, matching the way libstdc++ is used on Linux. The approach it takes is to use the requested version’s libc++ headers while linking against the top-level library. This is safe to do because libc++ is built with the stable ABI on Darwin by default. This change is necessary to support building a package with one version of clang while linking against libraries that are built with different versions. Otherwise, if they both use C++, they will link against different versions of libc++ and (probably) crash at runtime. Examples of where this is an issue include older versions of nodejs building with clang 15 and darktable (which is currently built with clang 13). --- pkgs/development/compilers/llvm/5/default.nix | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkgs/development/compilers/llvm/5/default.nix b/pkgs/development/compilers/llvm/5/default.nix index 70f0d2e11bb67..067f32be40aef 100644 --- a/pkgs/development/compilers/llvm/5/default.nix +++ b/pkgs/development/compilers/llvm/5/default.nix @@ -78,6 +78,51 @@ let # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + # Treat Darwin’s top-level libc++ as the standard one for the platform. Otherwise, binaries + # built with a non-default version of clang can end up linked against multiple versions of + # libc++ simultaneously, which can lead to runtime crashes when both dylibs are loaded. + # Note that the headers from the requested clang will be used, but the runtime library + # will be the default version for Darwin. This is okay because libc++ defaults to building + # with the stable API (LIBCXX_ABI_VERSION is 1). + else if stdenv.targetPlatform.isDarwin then ( + let + llvmLibcxxVersion = lib.getVersion llvmLibcxx; + stdenvLibcxxVersion = lib.getVersion stdenvLibcxx; + + stdenvLibcxx = pkgs.stdenv.cc.libcxx; + stdenvCxxabi = pkgs.stdenv.cc.libcxx.cxxabi; + + llvmLibcxx = tools.libcxxClang.libcxx; + llvmCxxabi = tools.libcxxClang.libcxx.cxxabi; + + libcxx = pkgs.runCommand "${stdenvLibcxx.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit cxxabi; + isLLVM = true; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvLibcxx}' "$out" + echo '${stdenvLibcxx}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmLibcxx}/include' "$dev/include" + ''; + + cxxabi = pkgs.runCommand "${stdenvCxxabi.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit (stdenvCxxabi) libName; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvCxxabi}' "$out" + echo '${stdenvCxxabi}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmCxxabi}/include' "$dev/include" + ''; + in + if llvmLibcxxVersion != stdenvLibcxxVersion + then tools.libcxxClang.override { + inherit libcxx; + extraPackages = [ cxxabi targetLlvmLibraries.compiler-rt ]; + } + else tools.libcxxClang + ) else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; From cb9a7e290e13c40c7ddcc14485c79bf1cb4c0b98 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 28 Oct 2023 20:11:55 -0400 Subject: [PATCH 02/18] llvmPackages_6.clang: use the stdenv libc++ on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change treats the top-level libc++ as the “system” libc++ on Darwin, matching the way libstdc++ is used on Linux. The approach it takes is to use the requested version’s libc++ headers while linking against the top-level library. This is safe to do because libc++ is built with the stable ABI on Darwin by default. This change is necessary to support building a package with one version of clang while linking against libraries that are built with different versions. Otherwise, if they both use C++, they will link against different versions of libc++ and (probably) crash at runtime. Examples of where this is an issue include older versions of nodejs building with clang 15 and darktable (which is currently built with clang 13). --- pkgs/development/compilers/llvm/6/default.nix | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkgs/development/compilers/llvm/6/default.nix b/pkgs/development/compilers/llvm/6/default.nix index 3dcc75023f4f6..fc2e13d094db3 100644 --- a/pkgs/development/compilers/llvm/6/default.nix +++ b/pkgs/development/compilers/llvm/6/default.nix @@ -79,6 +79,51 @@ let # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + # Treat Darwin’s top-level libc++ as the standard one for the platform. Otherwise, binaries + # built with a non-default version of clang can end up linked against multiple versions of + # libc++ simultaneously, which can lead to runtime crashes when both dylibs are loaded. + # Note that the headers from the requested clang will be used, but the runtime library + # will be the default version for Darwin. This is okay because libc++ defaults to building + # with the stable API (LIBCXX_ABI_VERSION is 1). + else if stdenv.targetPlatform.isDarwin then ( + let + llvmLibcxxVersion = lib.getVersion llvmLibcxx; + stdenvLibcxxVersion = lib.getVersion stdenvLibcxx; + + stdenvLibcxx = pkgs.stdenv.cc.libcxx; + stdenvCxxabi = pkgs.stdenv.cc.libcxx.cxxabi; + + llvmLibcxx = tools.libcxxClang.libcxx; + llvmCxxabi = tools.libcxxClang.libcxx.cxxabi; + + libcxx = pkgs.runCommand "${stdenvLibcxx.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit cxxabi; + isLLVM = true; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvLibcxx}' "$out" + echo '${stdenvLibcxx}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmLibcxx}/include' "$dev/include" + ''; + + cxxabi = pkgs.runCommand "${stdenvCxxabi.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit (stdenvCxxabi) libName; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvCxxabi}' "$out" + echo '${stdenvCxxabi}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmCxxabi}/include' "$dev/include" + ''; + in + if llvmLibcxxVersion != stdenvLibcxxVersion + then tools.libcxxClang.override { + inherit libcxx; + extraPackages = [ cxxabi targetLlvmLibraries.compiler-rt ]; + } + else tools.libcxxClang + ) else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; From fe66a29059e2d93fb7c7cb4208b39fbe5e4ca371 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 28 Oct 2023 20:12:06 -0400 Subject: [PATCH 03/18] llvmPackages_7.clang: use the stdenv libc++ on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change treats the top-level libc++ as the “system” libc++ on Darwin, matching the way libstdc++ is used on Linux. The approach it takes is to use the requested version’s libc++ headers while linking against the top-level library. This is safe to do because libc++ is built with the stable ABI on Darwin by default. This change is necessary to support building a package with one version of clang while linking against libraries that are built with different versions. Otherwise, if they both use C++, they will link against different versions of libc++ and (probably) crash at runtime. Examples of where this is an issue include older versions of nodejs building with clang 15 and darktable (which is currently built with clang 13). --- pkgs/development/compilers/llvm/7/default.nix | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkgs/development/compilers/llvm/7/default.nix b/pkgs/development/compilers/llvm/7/default.nix index 0607b5ebf42c2..a6a84b666d0a3 100644 --- a/pkgs/development/compilers/llvm/7/default.nix +++ b/pkgs/development/compilers/llvm/7/default.nix @@ -110,6 +110,51 @@ let # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + # Treat Darwin’s top-level libc++ as the standard one for the platform. Otherwise, binaries + # built with a non-default version of clang can end up linked against multiple versions of + # libc++ simultaneously, which can lead to runtime crashes when both dylibs are loaded. + # Note that the headers from the requested clang will be used, but the runtime library + # will be the default version for Darwin. This is okay because libc++ defaults to building + # with the stable API (LIBCXX_ABI_VERSION is 1). + else if stdenv.targetPlatform.isDarwin then ( + let + llvmLibcxxVersion = lib.getVersion llvmLibcxx; + stdenvLibcxxVersion = lib.getVersion stdenvLibcxx; + + stdenvLibcxx = pkgs.stdenv.cc.libcxx; + stdenvCxxabi = pkgs.stdenv.cc.libcxx.cxxabi; + + llvmLibcxx = tools.libcxxClang.libcxx; + llvmCxxabi = tools.libcxxClang.libcxx.cxxabi; + + libcxx = pkgs.runCommand "${stdenvLibcxx.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit cxxabi; + isLLVM = true; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvLibcxx}' "$out" + echo '${stdenvLibcxx}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmLibcxx}/include' "$dev/include" + ''; + + cxxabi = pkgs.runCommand "${stdenvCxxabi.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit (stdenvCxxabi) libName; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvCxxabi}' "$out" + echo '${stdenvCxxabi}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmCxxabi}/include' "$dev/include" + ''; + in + if llvmLibcxxVersion != stdenvLibcxxVersion + then tools.libcxxClang.override { + inherit libcxx; + extraPackages = [ cxxabi targetLlvmLibraries.compiler-rt ]; + } + else tools.libcxxClang + ) else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; From 4d837bf8eb644a30576518148d43572fc898c89e Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 28 Oct 2023 20:12:34 -0400 Subject: [PATCH 04/18] llvmPackages_8.clang: use the stdenv libc++ on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change treats the top-level libc++ as the “system” libc++ on Darwin, matching the way libstdc++ is used on Linux. The approach it takes is to use the requested version’s libc++ headers while linking against the top-level library. This is safe to do because libc++ is built with the stable ABI on Darwin by default. This change is necessary to support building a package with one version of clang while linking against libraries that are built with different versions. Otherwise, if they both use C++, they will link against different versions of libc++ and (probably) crash at runtime. Examples of where this is an issue include older versions of nodejs building with clang 15 and darktable (which is currently built with clang 13). --- pkgs/development/compilers/llvm/8/default.nix | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkgs/development/compilers/llvm/8/default.nix b/pkgs/development/compilers/llvm/8/default.nix index 5beb8afb2ee94..b5d2ff7e625c8 100644 --- a/pkgs/development/compilers/llvm/8/default.nix +++ b/pkgs/development/compilers/llvm/8/default.nix @@ -111,6 +111,51 @@ let # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + # Treat Darwin’s top-level libc++ as the standard one for the platform. Otherwise, binaries + # built with a non-default version of clang can end up linked against multiple versions of + # libc++ simultaneously, which can lead to runtime crashes when both dylibs are loaded. + # Note that the headers from the requested clang will be used, but the runtime library + # will be the default version for Darwin. This is okay because libc++ defaults to building + # with the stable API (LIBCXX_ABI_VERSION is 1). + else if stdenv.targetPlatform.isDarwin then ( + let + llvmLibcxxVersion = lib.getVersion llvmLibcxx; + stdenvLibcxxVersion = lib.getVersion stdenvLibcxx; + + stdenvLibcxx = pkgs.stdenv.cc.libcxx; + stdenvCxxabi = pkgs.stdenv.cc.libcxx.cxxabi; + + llvmLibcxx = tools.libcxxClang.libcxx; + llvmCxxabi = tools.libcxxClang.libcxx.cxxabi; + + libcxx = pkgs.runCommand "${stdenvLibcxx.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit cxxabi; + isLLVM = true; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvLibcxx}' "$out" + echo '${stdenvLibcxx}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmLibcxx}/include' "$dev/include" + ''; + + cxxabi = pkgs.runCommand "${stdenvCxxabi.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit (stdenvCxxabi) libName; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvCxxabi}' "$out" + echo '${stdenvCxxabi}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmCxxabi}/include' "$dev/include" + ''; + in + if llvmLibcxxVersion != stdenvLibcxxVersion + then tools.libcxxClang.override { + inherit libcxx; + extraPackages = [ cxxabi targetLlvmLibraries.compiler-rt ]; + } + else tools.libcxxClang + ) else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; From 58ccbaf70896dba0b9c717ed60555c1f4059d3d5 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 28 Oct 2023 20:12:39 -0400 Subject: [PATCH 05/18] llvmPackages_9.clang: use the stdenv libc++ on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change treats the top-level libc++ as the “system” libc++ on Darwin, matching the way libstdc++ is used on Linux. The approach it takes is to use the requested version’s libc++ headers while linking against the top-level library. This is safe to do because libc++ is built with the stable ABI on Darwin by default. This change is necessary to support building a package with one version of clang while linking against libraries that are built with different versions. Otherwise, if they both use C++, they will link against different versions of libc++ and (probably) crash at runtime. Examples of where this is an issue include older versions of nodejs building with clang 15 and darktable (which is currently built with clang 13). --- pkgs/development/compilers/llvm/9/default.nix | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkgs/development/compilers/llvm/9/default.nix b/pkgs/development/compilers/llvm/9/default.nix index 9f79dc5cce7fc..f6a3a1a87f2d7 100644 --- a/pkgs/development/compilers/llvm/9/default.nix +++ b/pkgs/development/compilers/llvm/9/default.nix @@ -111,6 +111,51 @@ let # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + # Treat Darwin’s top-level libc++ as the standard one for the platform. Otherwise, binaries + # built with a non-default version of clang can end up linked against multiple versions of + # libc++ simultaneously, which can lead to runtime crashes when both dylibs are loaded. + # Note that the headers from the requested clang will be used, but the runtime library + # will be the default version for Darwin. This is okay because libc++ defaults to building + # with the stable API (LIBCXX_ABI_VERSION is 1). + else if stdenv.targetPlatform.isDarwin then ( + let + llvmLibcxxVersion = lib.getVersion llvmLibcxx; + stdenvLibcxxVersion = lib.getVersion stdenvLibcxx; + + stdenvLibcxx = pkgs.stdenv.cc.libcxx; + stdenvCxxabi = pkgs.stdenv.cc.libcxx.cxxabi; + + llvmLibcxx = tools.libcxxClang.libcxx; + llvmCxxabi = tools.libcxxClang.libcxx.cxxabi; + + libcxx = pkgs.runCommand "${stdenvLibcxx.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit cxxabi; + isLLVM = true; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvLibcxx}' "$out" + echo '${stdenvLibcxx}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmLibcxx}/include' "$dev/include" + ''; + + cxxabi = pkgs.runCommand "${stdenvCxxabi.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit (stdenvCxxabi) libName; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvCxxabi}' "$out" + echo '${stdenvCxxabi}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmCxxabi}/include' "$dev/include" + ''; + in + if llvmLibcxxVersion != stdenvLibcxxVersion + then tools.libcxxClang.override { + inherit libcxx; + extraPackages = [ cxxabi targetLlvmLibraries.compiler-rt ]; + } + else tools.libcxxClang + ) else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; From a1d08cb067f75b89c950fa19bc4b23f86cec777b Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 28 Oct 2023 20:12:42 -0400 Subject: [PATCH 06/18] llvmPackages_10.clang: use the stdenv libc++ on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change treats the top-level libc++ as the “system” libc++ on Darwin, matching the way libstdc++ is used on Linux. The approach it takes is to use the requested version’s libc++ headers while linking against the top-level library. This is safe to do because libc++ is built with the stable ABI on Darwin by default. This change is necessary to support building a package with one version of clang while linking against libraries that are built with different versions. Otherwise, if they both use C++, they will link against different versions of libc++ and (probably) crash at runtime. Examples of where this is an issue include older versions of nodejs building with clang 15 and darktable (which is currently built with clang 13). --- .../development/compilers/llvm/10/default.nix | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkgs/development/compilers/llvm/10/default.nix b/pkgs/development/compilers/llvm/10/default.nix index 37c32e425c63c..49e3cfc473665 100644 --- a/pkgs/development/compilers/llvm/10/default.nix +++ b/pkgs/development/compilers/llvm/10/default.nix @@ -103,6 +103,51 @@ let # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + # Treat Darwin’s top-level libc++ as the standard one for the platform. Otherwise, binaries + # built with a non-default version of clang can end up linked against multiple versions of + # libc++ simultaneously, which can lead to runtime crashes when both dylibs are loaded. + # Note that the headers from the requested clang will be used, but the runtime library + # will be the default version for Darwin. This is okay because libc++ defaults to building + # with the stable API (LIBCXX_ABI_VERSION is 1). + else if stdenv.targetPlatform.isDarwin then ( + let + llvmLibcxxVersion = lib.getVersion llvmLibcxx; + stdenvLibcxxVersion = lib.getVersion stdenvLibcxx; + + stdenvLibcxx = pkgs.stdenv.cc.libcxx; + stdenvCxxabi = pkgs.stdenv.cc.libcxx.cxxabi; + + llvmLibcxx = tools.libcxxClang.libcxx; + llvmCxxabi = tools.libcxxClang.libcxx.cxxabi; + + libcxx = pkgs.runCommand "${stdenvLibcxx.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit cxxabi; + isLLVM = true; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvLibcxx}' "$out" + echo '${stdenvLibcxx}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmLibcxx}/include' "$dev/include" + ''; + + cxxabi = pkgs.runCommand "${stdenvCxxabi.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit (stdenvCxxabi) libName; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvCxxabi}' "$out" + echo '${stdenvCxxabi}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmCxxabi}/include' "$dev/include" + ''; + in + if llvmLibcxxVersion != stdenvLibcxxVersion + then tools.libcxxClang.override { + inherit libcxx; + extraPackages = [ cxxabi targetLlvmLibraries.compiler-rt ]; + } + else tools.libcxxClang + ) else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; From 0ab9dddc84c9c5ab475da9275f21b1d020435e11 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 28 Oct 2023 20:12:46 -0400 Subject: [PATCH 07/18] llvmPackages_11.clang: use the stdenv libc++ on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change treats the top-level libc++ as the “system” libc++ on Darwin, matching the way libstdc++ is used on Linux. The approach it takes is to use the requested version’s libc++ headers while linking against the top-level library. This is safe to do because libc++ is built with the stable ABI on Darwin by default. This change is necessary to support building a package with one version of clang while linking against libraries that are built with different versions. Otherwise, if they both use C++, they will link against different versions of libc++ and (probably) crash at runtime. Examples of where this is an issue include older versions of nodejs building with clang 15 and darktable (which is currently built with clang 13). --- .../development/compilers/llvm/11/default.nix | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkgs/development/compilers/llvm/11/default.nix b/pkgs/development/compilers/llvm/11/default.nix index 6ce7d86c835e0..213d698f9d94b 100644 --- a/pkgs/development/compilers/llvm/11/default.nix +++ b/pkgs/development/compilers/llvm/11/default.nix @@ -118,6 +118,51 @@ let # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + # Treat Darwin’s top-level libc++ as the standard one for the platform. Otherwise, binaries + # built with a non-default version of clang can end up linked against multiple versions of + # libc++ simultaneously, which can lead to runtime crashes when both dylibs are loaded. + # Note that the headers from the requested clang will be used, but the runtime library + # will be the default version for Darwin. This is okay because libc++ defaults to building + # with the stable API (LIBCXX_ABI_VERSION is 1). + else if stdenv.targetPlatform.isDarwin then ( + let + llvmLibcxxVersion = lib.getVersion llvmLibcxx; + stdenvLibcxxVersion = lib.getVersion stdenvLibcxx; + + stdenvLibcxx = pkgs.stdenv.cc.libcxx; + stdenvCxxabi = pkgs.stdenv.cc.libcxx.cxxabi; + + llvmLibcxx = tools.libcxxClang.libcxx; + llvmCxxabi = tools.libcxxClang.libcxx.cxxabi; + + libcxx = pkgs.runCommand "${stdenvLibcxx.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit cxxabi; + isLLVM = true; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvLibcxx}' "$out" + echo '${stdenvLibcxx}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmLibcxx}/include' "$dev/include" + ''; + + cxxabi = pkgs.runCommand "${stdenvCxxabi.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit (stdenvCxxabi) libName; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvCxxabi}' "$out" + echo '${stdenvCxxabi}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmCxxabi}/include' "$dev/include" + ''; + in + if llvmLibcxxVersion != stdenvLibcxxVersion + then tools.libcxxClang.override { + inherit libcxx; + extraPackages = [ cxxabi targetLlvmLibraries.compiler-rt ]; + } + else tools.libcxxClang + ) else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; From e6a8275fb0f0fa6c08482ec98e363411f8f0ff2d Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 28 Oct 2023 20:12:51 -0400 Subject: [PATCH 08/18] llvmPackages_12.clang: use the stdenv libc++ on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change treats the top-level libc++ as the “system” libc++ on Darwin, matching the way libstdc++ is used on Linux. The approach it takes is to use the requested version’s libc++ headers while linking against the top-level library. This is safe to do because libc++ is built with the stable ABI on Darwin by default. This change is necessary to support building a package with one version of clang while linking against libraries that are built with different versions. Otherwise, if they both use C++, they will link against different versions of libc++ and (probably) crash at runtime. Examples of where this is an issue include older versions of nodejs building with clang 15 and darktable (which is currently built with clang 13). --- .../development/compilers/llvm/12/default.nix | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkgs/development/compilers/llvm/12/default.nix b/pkgs/development/compilers/llvm/12/default.nix index b976dd2ee67a1..3641d7a1c1e98 100644 --- a/pkgs/development/compilers/llvm/12/default.nix +++ b/pkgs/development/compilers/llvm/12/default.nix @@ -106,6 +106,51 @@ let # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + # Treat Darwin’s top-level libc++ as the standard one for the platform. Otherwise, binaries + # built with a non-default version of clang can end up linked against multiple versions of + # libc++ simultaneously, which can lead to runtime crashes when both dylibs are loaded. + # Note that the headers from the requested clang will be used, but the runtime library + # will be the default version for Darwin. This is okay because libc++ defaults to building + # with the stable API (LIBCXX_ABI_VERSION is 1). + else if stdenv.targetPlatform.isDarwin then ( + let + llvmLibcxxVersion = lib.getVersion llvmLibcxx; + stdenvLibcxxVersion = lib.getVersion stdenvLibcxx; + + stdenvLibcxx = pkgs.stdenv.cc.libcxx; + stdenvCxxabi = pkgs.stdenv.cc.libcxx.cxxabi; + + llvmLibcxx = tools.libcxxClang.libcxx; + llvmCxxabi = tools.libcxxClang.libcxx.cxxabi; + + libcxx = pkgs.runCommand "${stdenvLibcxx.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit cxxabi; + isLLVM = true; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvLibcxx}' "$out" + echo '${stdenvLibcxx}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmLibcxx}/include' "$dev/include" + ''; + + cxxabi = pkgs.runCommand "${stdenvCxxabi.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit (stdenvCxxabi) libName; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvCxxabi}' "$out" + echo '${stdenvCxxabi}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmCxxabi}/include' "$dev/include" + ''; + in + if llvmLibcxxVersion != stdenvLibcxxVersion + then tools.libcxxClang.override { + inherit libcxx; + extraPackages = [ cxxabi targetLlvmLibraries.compiler-rt ]; + } + else tools.libcxxClang + ) else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; From b93182ec50e2d1ebe03b6f257dc666bda757f6c9 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 28 Oct 2023 20:12:54 -0400 Subject: [PATCH 09/18] llvmPackages_13.clang: use the stdenv libc++ on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change treats the top-level libc++ as the “system” libc++ on Darwin, matching the way libstdc++ is used on Linux. The approach it takes is to use the requested version’s libc++ headers while linking against the top-level library. This is safe to do because libc++ is built with the stable ABI on Darwin by default. This change is necessary to support building a package with one version of clang while linking against libraries that are built with different versions. Otherwise, if they both use C++, they will link against different versions of libc++ and (probably) crash at runtime. Examples of where this is an issue include older versions of nodejs building with clang 15 and darktable (which is currently built with clang 13). --- .../development/compilers/llvm/13/default.nix | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkgs/development/compilers/llvm/13/default.nix b/pkgs/development/compilers/llvm/13/default.nix index 3cf7cd711ebef..173576c7ad868 100644 --- a/pkgs/development/compilers/llvm/13/default.nix +++ b/pkgs/development/compilers/llvm/13/default.nix @@ -107,6 +107,51 @@ let # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + # Treat Darwin’s top-level libc++ as the standard one for the platform. Otherwise, binaries + # built with a non-default version of clang can end up linked against multiple versions of + # libc++ simultaneously, which can lead to runtime crashes when both dylibs are loaded. + # Note that the headers from the requested clang will be used, but the runtime library + # will be the default version for Darwin. This is okay because libc++ defaults to building + # with the stable API (LIBCXX_ABI_VERSION is 1). + else if stdenv.targetPlatform.isDarwin then ( + let + llvmLibcxxVersion = lib.getVersion llvmLibcxx; + stdenvLibcxxVersion = lib.getVersion stdenvLibcxx; + + stdenvLibcxx = pkgs.stdenv.cc.libcxx; + stdenvCxxabi = pkgs.stdenv.cc.libcxx.cxxabi; + + llvmLibcxx = tools.libcxxClang.libcxx; + llvmCxxabi = tools.libcxxClang.libcxx.cxxabi; + + libcxx = pkgs.runCommand "${stdenvLibcxx.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit cxxabi; + isLLVM = true; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvLibcxx}' "$out" + echo '${stdenvLibcxx}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmLibcxx}/include' "$dev/include" + ''; + + cxxabi = pkgs.runCommand "${stdenvCxxabi.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit (stdenvCxxabi) libName; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvCxxabi}' "$out" + echo '${stdenvCxxabi}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmCxxabi}/include' "$dev/include" + ''; + in + if llvmLibcxxVersion != stdenvLibcxxVersion + then tools.libcxxClang.override { + inherit libcxx; + extraPackages = [ cxxabi targetLlvmLibraries.compiler-rt ]; + } + else tools.libcxxClang + ) else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; From 685e3cf51306a4e3073f4b98253a53d22a5923f1 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 28 Oct 2023 20:12:59 -0400 Subject: [PATCH 10/18] llvmPackages_14.clang: use the stdenv libc++ on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change treats the top-level libc++ as the “system” libc++ on Darwin, matching the way libstdc++ is used on Linux. The approach it takes is to use the requested version’s libc++ headers while linking against the top-level library. This is safe to do because libc++ is built with the stable ABI on Darwin by default. This change is necessary to support building a package with one version of clang while linking against libraries that are built with different versions. Otherwise, if they both use C++, they will link against different versions of libc++ and (probably) crash at runtime. Examples of where this is an issue include older versions of nodejs building with clang 15 and darktable (which is currently built with clang 13). --- .../development/compilers/llvm/14/default.nix | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkgs/development/compilers/llvm/14/default.nix b/pkgs/development/compilers/llvm/14/default.nix index b9a74e0f070a9..880ab1221234e 100644 --- a/pkgs/development/compilers/llvm/14/default.nix +++ b/pkgs/development/compilers/llvm/14/default.nix @@ -108,6 +108,51 @@ let # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + # Treat Darwin’s top-level libc++ as the standard one for the platform. Otherwise, binaries + # built with a non-default version of clang can end up linked against multiple versions of + # libc++ simultaneously, which can lead to runtime crashes when both dylibs are loaded. + # Note that the headers from the requested clang will be used, but the runtime library + # will be the default version for Darwin. This is okay because libc++ defaults to building + # with the stable API (LIBCXX_ABI_VERSION is 1). + else if stdenv.targetPlatform.isDarwin then ( + let + llvmLibcxxVersion = lib.getVersion llvmLibcxx; + stdenvLibcxxVersion = lib.getVersion stdenvLibcxx; + + stdenvLibcxx = pkgs.stdenv.cc.libcxx; + stdenvCxxabi = pkgs.stdenv.cc.libcxx.cxxabi; + + llvmLibcxx = tools.libcxxClang.libcxx; + llvmCxxabi = tools.libcxxClang.libcxx.cxxabi; + + libcxx = pkgs.runCommand "${stdenvLibcxx.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit cxxabi; + isLLVM = true; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvLibcxx}' "$out" + echo '${stdenvLibcxx}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmLibcxx}/include' "$dev/include" + ''; + + cxxabi = pkgs.runCommand "${stdenvCxxabi.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit (stdenvCxxabi) libName; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvCxxabi}' "$out" + echo '${stdenvCxxabi}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmCxxabi}/include' "$dev/include" + ''; + in + if llvmLibcxxVersion != stdenvLibcxxVersion + then tools.libcxxClang.override { + inherit libcxx; + extraPackages = [ cxxabi targetLlvmLibraries.compiler-rt ]; + } + else tools.libcxxClang + ) else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; From 5cdf21d1bbf399a7f1e8a032034fcde0649a02ff Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 28 Oct 2023 20:13:04 -0400 Subject: [PATCH 11/18] llvmPackages_15.clang: use the stdenv libc++ on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change treats the top-level libc++ as the “system” libc++ on Darwin, matching the way libstdc++ is used on Linux. The approach it takes is to use the requested version’s libc++ headers while linking against the top-level library. This is safe to do because libc++ is built with the stable ABI on Darwin by default. This change is necessary to support building a package with one version of clang while linking against libraries that are built with different versions. Otherwise, if they both use C++, they will link against different versions of libc++ and (probably) crash at runtime. Examples of where this is an issue include older versions of nodejs building with clang 15 and darktable (which is currently built with clang 13). --- .../development/compilers/llvm/15/default.nix | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix index 863d31874ec8c..bc0f74ee3a297 100644 --- a/pkgs/development/compilers/llvm/15/default.nix +++ b/pkgs/development/compilers/llvm/15/default.nix @@ -156,6 +156,51 @@ in let # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + # Treat Darwin’s top-level libc++ as the standard one for the platform. Otherwise, binaries + # built with a non-default version of clang can end up linked against multiple versions of + # libc++ simultaneously, which can lead to runtime crashes when both dylibs are loaded. + # Note that the headers from the requested clang will be used, but the runtime library + # will be the default version for Darwin. This is okay because libc++ defaults to building + # with the stable API (LIBCXX_ABI_VERSION is 1). + else if stdenv.targetPlatform.isDarwin then ( + let + llvmLibcxxVersion = lib.getVersion llvmLibcxx; + stdenvLibcxxVersion = lib.getVersion stdenvLibcxx; + + stdenvLibcxx = pkgs.stdenv.cc.libcxx; + stdenvCxxabi = pkgs.stdenv.cc.libcxx.cxxabi; + + llvmLibcxx = tools.libcxxClang.libcxx; + llvmCxxabi = tools.libcxxClang.libcxx.cxxabi; + + libcxx = pkgs.runCommand "${stdenvLibcxx.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit cxxabi; + isLLVM = true; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvLibcxx}' "$out" + echo '${stdenvLibcxx}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmLibcxx}/include' "$dev/include" + ''; + + cxxabi = pkgs.runCommand "${stdenvCxxabi.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit (stdenvCxxabi) libName; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvCxxabi}' "$out" + echo '${stdenvCxxabi}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmCxxabi}/include' "$dev/include" + ''; + in + if llvmLibcxxVersion != stdenvLibcxxVersion + then tools.libcxxClang.override { + inherit libcxx; + extraPackages = [ cxxabi targetLlvmLibraries.compiler-rt ]; + } + else tools.libcxxClang + ) else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; From da8ba1473e2d441997aafa503858878118d81ef2 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 28 Oct 2023 20:13:09 -0400 Subject: [PATCH 12/18] llvmPackages_16.clang: use the stdenv libc++ on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change treats the top-level libc++ as the “system” libc++ on Darwin, matching the way libstdc++ is used on Linux. The approach it takes is to use the requested version’s libc++ headers while linking against the top-level library. This is safe to do because libc++ is built with the stable ABI on Darwin by default. This change is necessary to support building a package with one version of clang while linking against libraries that are built with different versions. Otherwise, if they both use C++, they will link against different versions of libc++ and (probably) crash at runtime. Examples of where this is an issue include older versions of nodejs building with clang 15 and darktable (which is currently built with clang 13). --- .../development/compilers/llvm/16/default.nix | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/pkgs/development/compilers/llvm/16/default.nix b/pkgs/development/compilers/llvm/16/default.nix index a9ffac74123a3..270c3caeaa39a 100644 --- a/pkgs/development/compilers/llvm/16/default.nix +++ b/pkgs/development/compilers/llvm/16/default.nix @@ -50,7 +50,7 @@ in (gitRelease != null) (officialRelease != null)) ("must specify `gitRelease` or `officialRelease`" + - (lib.optionalString (gitRelease != null) " — not both")); + (lib.optionalString (gitRelease != null) " � not both")); let monorepoSrc' = monorepoSrc; in let @@ -157,6 +157,51 @@ in let # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + # Treat Darwin’s top-level libc++ as the standard one for the platform. Otherwise, binaries + # built with a non-default version of clang can end up linked against multiple versions of + # libc++ simultaneously, which can lead to runtime crashes when both dylibs are loaded. + # Note that the headers from the requested clang will be used, but the runtime library + # will be the default version for Darwin. This is okay because libc++ defaults to building + # with the stable API (LIBCXX_ABI_VERSION is 1). + else if stdenv.targetPlatform.isDarwin then ( + let + llvmLibcxxVersion = lib.getVersion llvmLibcxx; + stdenvLibcxxVersion = lib.getVersion stdenvLibcxx; + + stdenvLibcxx = pkgs.stdenv.cc.libcxx; + stdenvCxxabi = pkgs.stdenv.cc.libcxx.cxxabi; + + llvmLibcxx = tools.libcxxClang.libcxx; + llvmCxxabi = tools.libcxxClang.libcxx.cxxabi; + + libcxx = pkgs.runCommand "${stdenvLibcxx.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit cxxabi; + isLLVM = true; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvLibcxx}' "$out" + echo '${stdenvLibcxx}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmLibcxx}/include' "$dev/include" + ''; + + cxxabi = pkgs.runCommand "${stdenvCxxabi.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit (stdenvCxxabi) libName; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvCxxabi}' "$out" + echo '${stdenvCxxabi}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmCxxabi}/include' "$dev/include" + ''; + in + if llvmLibcxxVersion != stdenvLibcxxVersion + then tools.libcxxClang.override { + inherit libcxx; + extraPackages = [ cxxabi targetLlvmLibraries.compiler-rt ]; + } + else tools.libcxxClang + ) else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; @@ -226,7 +271,7 @@ in let # fully LLVM toolchain from scratch. No GCC toolchain should be # pulled in. As a consequence, it is very quick to build different # targets provided by LLVM and we can also build for what GCC - # doesn’t support like LLVM. Probably we should move to some other + # doesn�t support like LLVM. Probably we should move to some other # file. bintools-unwrapped = callPackage ../common/bintools.nix { }; From 2712c86d3691fc479312cd0bec20761131c75a78 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 28 Oct 2023 18:55:59 -0400 Subject: [PATCH 13/18] Revert "swift: use stdenv libc++ on Darwin" This reverts commit efdf4e9d1f05d6587230d1b71fab1e5000bed22a. --- pkgs/development/compilers/swift/default.nix | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/pkgs/development/compilers/swift/default.nix b/pkgs/development/compilers/swift/default.nix index 0da2510f09a00..2df883095cf15 100644 --- a/pkgs/development/compilers/swift/default.nix +++ b/pkgs/development/compilers/swift/default.nix @@ -2,14 +2,11 @@ , pkgs , newScope , darwin -, llvmPackages , llvmPackages_15 , overrideCC }: let - swiftLlvmPackages = llvmPackages_15; - self = rec { callPackage = newScope self; @@ -27,25 +24,12 @@ let # used in Swift, and applies the same libc overrides as `apple_sdk.stdenv`. clang = if pkgs.stdenv.isDarwin then - swiftLlvmPackages.clang.override rec { + llvmPackages_15.clang.override rec { libc = apple_sdk.Libsystem; bintools = pkgs.bintools.override { inherit libc; }; - # Ensure that Swift’s internal clang uses the same libc++ and libc++abi as the - # default Darwin stdenv. Using the default libc++ avoids issues (such as crashes) - # that can happen when a Swift application dynamically links different versions - # of libc++ and libc++abi than libraries it links are using. - inherit (llvmPackages) libcxx; - extraPackages = [ - llvmPackages.libcxxabi - # Use the compiler-rt associated with clang, but use the libc++abi from the stdenv - # to avoid linking against two different versions (for the same reasons as above). - (swiftLlvmPackages.compiler-rt.override { - inherit (llvmPackages) libcxxabi; - }) - ]; } else - swiftLlvmPackages.clang; + llvmPackages_15.clang; # Overrides that create a useful environment for swift packages, allowing # packaging with `swiftPackages.callPackage`. These are similar to From d1cfea5505bcefc37f81c0b6dc0e631cb7752c85 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 28 Oct 2023 20:13:59 -0400 Subject: [PATCH 14/18] nodejs_14: drop manual override of libc++ --- pkgs/development/web/nodejs/v14.nix | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pkgs/development/web/nodejs/v14.nix b/pkgs/development/web/nodejs/v14.nix index c2d5d58bea784..9954661a934da 100644 --- a/pkgs/development/web/nodejs/v14.nix +++ b/pkgs/development/web/nodejs/v14.nix @@ -5,10 +5,7 @@ let # Use an older version of clang with the current libc++ for compatibility (e.g., with icu). ensureCompatibleCC = packages: if packages.stdenv.cc.isClang && lib.versionAtLeast (lib.getVersion packages.stdenv.cc.cc) "16" - then overrideCC packages.llvmPackages_15.stdenv (packages.llvmPackages_15.stdenv.cc.override { - inherit (packages.llvmPackages) libcxx; - extraPackages = [ packages.llvmPackages.libcxxabi ]; - }) + then packages.llvmPackages_15.stdenv else packages.stdenv; buildNodejs = callPackage ./nodejs.nix { From c41ddc40d8abf7ee24b4cfebfd9649a119dfbd60 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 28 Oct 2023 20:35:53 -0400 Subject: [PATCH 15/18] nodejs_14: use Python 3.10 to build --- pkgs/development/web/nodejs/v14.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/web/nodejs/v14.nix b/pkgs/development/web/nodejs/v14.nix index 9954661a934da..5a6d8bfb05b26 100644 --- a/pkgs/development/web/nodejs/v14.nix +++ b/pkgs/development/web/nodejs/v14.nix @@ -1,4 +1,4 @@ -{ callPackage, lib, overrideCC, pkgs, buildPackages, openssl, python3, enableNpm ? true }: +{ callPackage, lib, overrideCC, pkgs, buildPackages, openssl, python310, enableNpm ? true }: let # Clang 16+ cannot build Node v14 due to -Wenum-constexpr-conversion errors. @@ -12,7 +12,7 @@ let inherit openssl; stdenv = ensureCompatibleCC pkgs; buildPackages = buildPackages // { stdenv = ensureCompatibleCC buildPackages; }; - python = python3; + python = python310; }; in buildNodejs { From 1ae5372340cb12e2e5aa99cc0bfc5babbbc5ef6f Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 28 Oct 2023 20:14:11 -0400 Subject: [PATCH 16/18] nodejs_16: drop manual override of libc++ --- pkgs/development/web/nodejs/v16.nix | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pkgs/development/web/nodejs/v16.nix b/pkgs/development/web/nodejs/v16.nix index 930b648ca5597..428c5974dff8c 100644 --- a/pkgs/development/web/nodejs/v16.nix +++ b/pkgs/development/web/nodejs/v16.nix @@ -5,10 +5,7 @@ let # Use an older version of clang with the current libc++ for compatibility (e.g., with icu). ensureCompatibleCC = packages: if packages.stdenv.cc.isClang && lib.versionAtLeast (lib.getVersion packages.stdenv.cc.cc) "16" - then overrideCC packages.llvmPackages_15.stdenv (packages.llvmPackages_15.stdenv.cc.override { - inherit (packages.llvmPackages) libcxx; - extraPackages = [ packages.llvmPackages.libcxxabi ]; - }) + then packages.llvmPackages_15.stdenv else packages.stdenv; buildNodejs = callPackage ./nodejs.nix { From 4bcd49cad8c20fb545bbaf40225449a440328795 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Fri, 27 Oct 2023 15:45:11 -0400 Subject: [PATCH 17/18] Revert "nodejs_18: fix build with clang 16" This reverts commit 81e4ca55c823f476882750559e6ccbfd0c445980. --- .../web/nodejs/enum-width-fix-backport.patch | 126 ------------------ pkgs/development/web/nodejs/v18.nix | 2 - 2 files changed, 128 deletions(-) delete mode 100644 pkgs/development/web/nodejs/enum-width-fix-backport.patch diff --git a/pkgs/development/web/nodejs/enum-width-fix-backport.patch b/pkgs/development/web/nodejs/enum-width-fix-backport.patch deleted file mode 100644 index 084cb0f3db080..0000000000000 --- a/pkgs/development/web/nodejs/enum-width-fix-backport.patch +++ /dev/null @@ -1,126 +0,0 @@ -See https://github.com/v8/v8/commit/d15d49b09dc7aef9edcc4cf6a0cb2b77a0db203f. - -v8 doesn’t compile with clang 16 due to an error regarding integer values being outside the enum -range. This is fixed in v8 upstream. This patch is a backport of the fix. - -Note that this patch is only needed for node.js v18. It is not needed for node v20. - - -diff --git a/include/v8-internal.h b/include/v8-internal.h -index a27f3a34480..5fb0f2ac16d 100644 ---- a/deps/v8/include/v8-internal.h -+++ b/deps/v8/include/v8-internal.h -@@ -574,7 +574,7 @@ class Internals { - - static const int kNodeClassIdOffset = 1 * kApiSystemPointerSize; - static const int kNodeFlagsOffset = 1 * kApiSystemPointerSize + 3; -- static const int kNodeStateMask = 0x7; -+ static const int kNodeStateMask = 0x3; - static const int kNodeStateIsWeakValue = 2; - - static const int kFirstNonstringType = 0x80; -diff --git a/src/ast/ast.h b/src/ast/ast.h -index 32438f9b249..8473f7fb67e 100644 ---- a/deps/v8/src/ast/ast.h -+++ b/deps/v8/src/ast/ast.h -@@ -1006,7 +1006,7 @@ class Literal final : public Expression { - friend class AstNodeFactory; - friend Zone; - -- using TypeField = Expression::NextBitField; -+ using TypeField = Expression::NextBitField; - - Literal(int smi, int position) : Expression(position, kLiteral), smi_(smi) { - bit_field_ = TypeField::update(bit_field_, kSmi); -diff --git a/src/base/bit-field.h b/src/base/bit-field.h -index 9a66468d4e0..ccfc23a065d 100644 ---- a/deps/v8/src/base/bit-field.h -+++ b/deps/v8/src/base/bit-field.h -@@ -40,6 +40,11 @@ class BitField final { - static constexpr U kNumValues = U{1} << kSize; - - // Value for the field with all bits set. -+ // If clang complains -+ // "constexpr variable 'kMax' must be initialized by a constant expression" -+ // on this line, then you're creating a BitField for an enum with more bits -+ // than needed for the enum values. Either reduce the BitField size, -+ // or give the enum an explicit underlying type. - static constexpr T kMax = static_cast(kNumValues - 1); - - template -diff --git a/src/compiler/backend/instruction-codes.h b/src/compiler/backend/instruction-codes.h -index 1add351b422..2fe2cd1a74f 100644 ---- a/deps/v8/src/compiler/backend/instruction-codes.h -+++ b/deps/v8/src/compiler/backend/instruction-codes.h -@@ -198,7 +198,7 @@ V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, - V(None) \ - TARGET_ADDRESSING_MODE_LIST(V) - --enum AddressingMode { -+enum AddressingMode : uint8_t { - #define DECLARE_ADDRESSING_MODE(Name) kMode_##Name, - ADDRESSING_MODE_LIST(DECLARE_ADDRESSING_MODE) - #undef DECLARE_ADDRESSING_MODE -@@ -309,7 +309,7 @@ using MiscField = base::BitField; - // LaneSizeField and AccessModeField are helper types to encode/decode a lane - // size, an access mode, or both inside the overlapping MiscField. - using LaneSizeField = base::BitField; --using AccessModeField = base::BitField; -+using AccessModeField = base::BitField; - // TODO(turbofan): {HasMemoryAccessMode} is currently only used to guard - // decoding (in CodeGenerator and InstructionScheduler). Encoding (in - // InstructionSelector) is not yet guarded. There are in fact instructions for -diff --git a/src/compiler/backend/instruction.h b/src/compiler/backend/instruction.h -index bed43dc6363..64b9063bcf8 100644 ---- a/deps/v8/src/compiler/backend/instruction.h -+++ b/deps/v8/src/compiler/backend/instruction.h -@@ -591,8 +591,8 @@ class LocationOperand : public InstructionOperand { - } - - STATIC_ASSERT(KindField::kSize == 3); -- using LocationKindField = base::BitField64; -- using RepresentationField = base::BitField64; -+ using LocationKindField = base::BitField64; -+ using RepresentationField = LocationKindField::Next; - using IndexField = base::BitField64; - }; - -diff --git a/src/handles/global-handles.cc b/src/handles/global-handles.cc -index 536059f3115..ae9e70b3a85 100644 ---- a/deps/v8/src/handles/global-handles.cc -+++ b/deps/v8/src/handles/global-handles.cc -@@ -652,7 +652,7 @@ class GlobalHandles::Node final : public NodeBase { - - // This stores three flags (independent, partially_dependent and - // in_young_list) and a State. -- using NodeState = base::BitField8; -+ using NodeState = base::BitField8; - using IsInYoungList = NodeState::Next; - using NodeWeaknessType = IsInYoungList::Next; - -diff --git a/src/maglev/maglev-ir.h b/src/maglev/maglev-ir.h -index 95aadfb5e14..f07f9fecf8c 100644 ---- a/deps/v8/src/maglev/maglev-ir.h -+++ b/deps/v8/src/maglev/maglev-ir.h -@@ -315,7 +315,7 @@ class OpProperties { - return kNeedsRegisterSnapshotBit::decode(bitfield_); - } - constexpr bool is_pure() const { -- return (bitfield_ | kPureMask) == kPureValue; -+ return (bitfield_ & kPureMask) == kPureValue; - } - constexpr bool is_required_when_unused() const { - return can_write() || non_memory_side_effects(); -diff --git a/src/wasm/wasm-code-manager.h b/src/wasm/wasm-code-manager.h -index f8329424777..81c7cce62e8 100644 ---- a/deps/v8/src/wasm/wasm-code-manager.h -+++ b/deps/v8/src/wasm/wasm-code-manager.h -@@ -487,7 +487,7 @@ class V8_EXPORT_PRIVATE WasmCode final { - int trap_handler_index_ = -1; - - // Bits encoded in {flags_}: -- using KindField = base::BitField8; -+ using KindField = base::BitField8; - using ExecutionTierField = KindField::Next; - using ForDebuggingField = ExecutionTierField::Next; - diff --git a/pkgs/development/web/nodejs/v18.nix b/pkgs/development/web/nodejs/v18.nix index 44b0c0b45ae99..3c8abbb291880 100644 --- a/pkgs/development/web/nodejs/v18.nix +++ b/pkgs/development/web/nodejs/v18.nix @@ -16,7 +16,5 @@ buildNodejs { ./revert-arm64-pointer-auth.patch ./node-npm-build-npm-package-logic.patch ./trap-handler-backport.patch - # Fix for enum width error when compiling with clang 16. - ./enum-width-fix-backport.patch ]; } From f33a85889fc35ab95ec02817e2e9b46ccac65349 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Fri, 27 Oct 2023 16:38:20 -0400 Subject: [PATCH 18/18] nodejs_18: fix build with clang 16 mk2 Trying to backport the fixes from v8 caused crashes with npm when building other packages, so just build it with clang 15 --- pkgs/development/web/nodejs/v18.nix | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkgs/development/web/nodejs/v18.nix b/pkgs/development/web/nodejs/v18.nix index 3c8abbb291880..bfc6ed4488b2a 100644 --- a/pkgs/development/web/nodejs/v18.nix +++ b/pkgs/development/web/nodejs/v18.nix @@ -1,8 +1,17 @@ -{ callPackage, fetchpatch, openssl, python3, enableNpm ? true }: +{ callPackage, lib, overrideCC, pkgs, buildPackages, fetchpatch, openssl, python3, enableNpm ? true }: let + # Clang 16+ cannot build Node v14 due to -Wenum-constexpr-conversion errors. + # Use an older version of clang with the current libc++ for compatibility (e.g., with icu). + ensureCompatibleCC = packages: + if packages.stdenv.cc.isClang && lib.versionAtLeast (lib.getVersion packages.stdenv.cc.cc) "16" + then packages.llvmPackages_15.stdenv + else packages.stdenv; + buildNodejs = callPackage ./nodejs.nix { inherit openssl; + stdenv = ensureCompatibleCC pkgs; + buildPackages = buildPackages // { stdenv = ensureCompatibleCC buildPackages; }; python = python3; }; in