Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodejs: fix build with clang 16 #253009

Merged
merged 3 commits into from
Oct 19, 2023
Merged

nodejs: fix build with clang 16 #253009

merged 3 commits into from
Oct 19, 2023

Conversation

reckenrode
Copy link
Contributor

@reckenrode reckenrode commented Sep 2, 2023

Description of changes

Node.js requires severals fixes to build with clang 16:

  • Use posix_memalign on x86_64-darwin. Otherwise, libc++ will try to use aligned_alloc, which is not available until 10.15. This is done by defining it as using the 10.13 SDK even though the 10.12 SDK is sufficient;
  • Use clang <16 with v14 and v16. The v18 patch doesn’t apply, but -Wenum-constexpr-conversion may become a hard error in a future clang release. Using an older version ensures it builds until these versions are dropped from nixpkgs.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Copy link
Contributor

@toonn toonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good to me, only one nit. Still trying to run test builds.

pkgs/development/web/nodejs/v16.nix Show resolved Hide resolved
Copy link
Contributor

@toonn toonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebasing this on the LLVM 16 bump I'm getting a permission error about env not being permitted as an interpreter?

Last lines of the build log:

  LD_LIBRARY_PATH=/private/tmp/nix-build-nodejs-18.17.1.drv-0/node-v18.17.1/out/
Release/lib.host:/private/tmp/nix-build-nodejs-18.17.1.drv-0/node-v18.17.1/out/R
elease/lib.target:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; cd ../.; mkdir -p /p
rivate/tmp/nix-build-nodejs-18.17.1.drv-0/node-v18.17.1/out/Release/obj/gen/src;
 python tools/inspector_protocol/convert_protocol_to_json.py src/inspector/node_
protocol.pdl "/private/tmp/nix-build-nodejs-18.17.1.drv-0/node-v18.17.1/out/Rele
ase/obj/gen/src/node_protocol.json"                                             
  rm -f /private/tmp/nix-build-nodejs-18.17.1.drv-0/node-v18.17.1/out/Release/li
bbase64.a && ./gyp-mac-tool filter-libtool libtool  -static -o /private/tmp/nix-
build-nodejs-18.17.1.drv-0/node-v18.17.1/out/Release/libbase64.a /private/tmp/ni
x-build-nodejs-18.17.1.drv-0/node-v18.17.1/out/Release/obj.target/base64/deps/ba
se64/base64/lib/arch/generic/codec.o /private/tmp/nix-build-nodejs-18.17.1.drv-0
/node-v18.17.1/out/Release/obj.target/base64/deps/base64/base64/lib/tables/table
s.o /private/tmp/nix-build-nodejs-18.17.1.drv-0/node-v18.17.1/out/Release/obj.ta
rget/base64/deps/base64/base64/lib/codec_choose.o /private/tmp/nix-build-nodejs-
18.17.1.drv-0/node-v18.17.1/out/Release/obj.target/base64/deps/base64/base64/lib/lib.o /private/tmp/nix-build-nodejs-18.17.1.drv-0/node-v18.17.1/out/Release/obj.target/base64/deps/base64/base64/lib/arch/neon32/codec.o /private/tmp/nix-build-nodejs-18.17.1.drv-0/node-v18.17.1/out/Release/obj.target/base64/deps/base64/base64/lib/arch/neon64/codec.o
In file included from <built-in>:440:
<command line>:32:9: warning: '__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__' macro redefined [-Wmacro-redefined]
#define __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 101300
        ^
<built-in>:431:9: note: previous definition is here
#define __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 101500
        ^
/nix/store/0iqd25xfcld27z9kg92qdayj872rw2k9-bash-5.2-p15/bin/bash: ./gyp-mac-tool: /usr/bin/env: bad interpreter: Operation not permitted
make[1]: *** [deps/base64/base64.target.mk:174: /private/tmp/nix-build-nodejs-18.17.1.drv-0/node-v18.17.1/out/Release/libbase64.a] Error 126
make[1]: *** Waiting for unfinished jobs....
21 warnings generated.
1 warning generated. 
23 warnings generated.
rm bd7fbf3b03451c23263e00021ee01d702a3b9540.intermediate c5009241ae6960ccbf1b3255e5c7cbad052383eb.intermediate
make: *** [Makefile:134: node] Error 2
error: builder for '/nix/store/ag1bvf2wxfbwz0559dihhzhavd1blcmg-nodejs-18.17.1.drv' failed with exit code 2

Might still be doing something wrong, I don't remember this error from when I looked at this earlier but I can't seem to get around it now.

EDIT: The relation to env actually seems tenuous. Sometimes it's the bad interpreter error, other times it's just make error 2.

Make aligned allocations work on x86_64-darwin by ensuring libc++ uses
`posix_memalign` instead of `aligned_alloc`, which was added in 10.15.
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++).
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++).
@reckenrode
Copy link
Contributor Author

I rebased on staging and dropped the node v18 commit. Upstream has cherry-picked the required commits to fix building with clang 16.

Copy link
Contributor

@toonn toonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@toonn toonn merged commit d7d8f29 into NixOS:staging Oct 19, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants