From cf1128c17a8a94bea4c12487a865a8e231d931e7 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 15 Jul 2023 20:29:42 -0600 Subject: [PATCH 1/3] nodejs: clang 16 compatibility for x86_64-darwin Make aligned allocations work on x86_64-darwin by ensuring libc++ uses `posix_memalign` instead of `aligned_alloc`, which was added in 10.15. --- pkgs/development/web/nodejs/nodejs.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/development/web/nodejs/nodejs.nix b/pkgs/development/web/nodejs/nodejs.nix index 270b64b8675f6..b1bd0ae912d95 100644 --- a/pkgs/development/web/nodejs/nodejs.nix +++ b/pkgs/development/web/nodejs/nodejs.nix @@ -53,6 +53,12 @@ let strictDeps = true; + env = lib.optionalAttrs (stdenv.isDarwin && stdenv.isx86_64) { + # Make sure libc++ uses `posix_memalign` instead of `aligned_alloc` on x86_64-darwin. + # Otherwise, nodejs would require the 11.0 SDK and macOS 10.15+. + NIX_CFLAGS_COMPILE = "-D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=101300"; + }; + CC_host = "cc"; CXX_host = "c++"; depsBuildBuild = [ buildPackages.stdenv.cc openssl libuv zlib icu ]; From 3ad67b4e12eebbb23ab2632d44c74662709e02a5 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 2 Sep 2023 11:50:17 -0400 Subject: [PATCH 2/3] nodejs_14: work around building with clang 16 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Node v14 can’t build with clang 16 due to `-Wenum-constexpr-conversion` errors. Since the backport patch from v8 does not apply to Node v14, and it is likely this will become a hard error in future versions of clang, use clang 15 when the version in the stdenv is newer. The version of libc++ used with the clang is made to match the one used in the stdenv to avoid possible issues with mixing multiple versions of libc++ in one binary (e.g., icu links against libc++). --- pkgs/development/web/nodejs/v14.nix | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkgs/development/web/nodejs/v14.nix b/pkgs/development/web/nodejs/v14.nix index e7dec1c12f665..c2d5d58bea784 100644 --- a/pkgs/development/web/nodejs/v14.nix +++ b/pkgs/development/web/nodejs/v14.nix @@ -1,8 +1,20 @@ -{ callPackage, python3, lib, stdenv, openssl, enableNpm ? true }: +{ callPackage, lib, overrideCC, pkgs, buildPackages, 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 overrideCC packages.llvmPackages_15.stdenv (packages.llvmPackages_15.stdenv.cc.override { + inherit (packages.llvmPackages) libcxx; + extraPackages = [ packages.llvmPackages.libcxxabi ]; + }) + else packages.stdenv; + buildNodejs = callPackage ./nodejs.nix { inherit openssl; + stdenv = ensureCompatibleCC pkgs; + buildPackages = buildPackages // { stdenv = ensureCompatibleCC buildPackages; }; python = python3; }; in @@ -10,5 +22,5 @@ in inherit enableNpm; version = "14.21.3"; sha256 = "sha256-RY7AkuYK1wDdzwectj1DXBXaTHuz0/mbmo5YqZ5UB14="; - patches = lib.optional stdenv.isDarwin ./bypass-xcodebuild.diff; + patches = lib.optional pkgs.stdenv.isDarwin ./bypass-xcodebuild.diff; } From 3cb5c1189fcbe3706fd3cab7fdf4ea52053f7e7d Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 2 Sep 2023 11:52:28 -0400 Subject: [PATCH 3/3] nodejs_16: work around building with clang 16 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Node v16 can’t build with clang 16 due to `-Wenum-constexpr-conversion` errors. Since the backport patch from v8 does not apply to Node v14, and it is likely this will become a hard error in future versions of clang, use clang 15 when the version in the stdenv is newer. The version of libc++ used with the clang is made to match the one used in the stdenv to avoid possible issues with mixing multiple versions of libc++ in one binary (e.g., icu links against libc++). --- pkgs/development/web/nodejs/v16.nix | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkgs/development/web/nodejs/v16.nix b/pkgs/development/web/nodejs/v16.nix index d4bb94c07d3e5..930b648ca5597 100644 --- a/pkgs/development/web/nodejs/v16.nix +++ b/pkgs/development/web/nodejs/v16.nix @@ -1,8 +1,20 @@ -{ callPackage, openssl, python3, fetchpatch, enableNpm ? true }: +{ callPackage, lib, overrideCC, pkgs, buildPackages, openssl, python3, fetchpatch, 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 overrideCC packages.llvmPackages_15.stdenv (packages.llvmPackages_15.stdenv.cc.override { + inherit (packages.llvmPackages) libcxx; + extraPackages = [ packages.llvmPackages.libcxxabi ]; + }) + else packages.stdenv; + buildNodejs = callPackage ./nodejs.nix { inherit openssl; + stdenv = ensureCompatibleCC pkgs; + buildPackages = buildPackages // { stdenv = ensureCompatibleCC buildPackages; }; python = python3; };