nodejs_16: work around building with clang 16

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++).
This commit is contained in:
Randy Eckenrode 2023-09-02 11:52:28 -04:00
parent 3ad67b4e12
commit 3cb5c1189f
No known key found for this signature in database
GPG Key ID: 64C1CD4EC2A600D9

View File

@ -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;
};