GeezerVison is showing github.com — tools: cache V8 build on test-shared workflow · nodejs/node@c2de1fa
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/workflows/test-shared.yml +5-10Lines changed: 5 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -182,25 +182,20 @@ jobs: | 182 | 182 | core.exportVariable('ACTIONS_CACHE_SERVICE_V2', 'on'); | 183 | 183 | core.exportVariable('ACTIONS_RESULTS_URL', process.env.ACTIONS_RESULTS_URL || ''); | 184 | 184 | core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); | 185 | | -
| 186 | | - - name: Load shell.nix | 187 | | - if: github.event_name != 'workflow_dispatch' | 188 | | - run: | | 189 | | - mv "$TAR_DIR"/*.nix . | 190 | | - mkdir tools | 191 | | - mv "$TAR_DIR"/tools/nix tools/. | | 185 | + core.exportVariable('NIX_SCCACHE', '(import <nixpkgs> {}).sccache'); | 192 | 186 |
| 193 | 187 | - name: Build Node.js and run tests | 194 | 188 | run: | | 195 | 189 | nix-shell \ | 196 | | - -I nixpkgs=./tools/nix/pkgs.nix \ | | 190 | + -I "nixpkgs=$TAR_DIR/tools/nix/pkgs.nix" \ | 197 | 191 | --pure --keep TAR_DIR --keep FLAKY_TESTS \ | 198 | 192 | --keep SCCACHE_GHA_ENABLED --keep ACTIONS_CACHE_SERVICE_V2 --keep ACTIONS_RESULTS_URL --keep ACTIONS_RUNTIME_TOKEN \ | 199 | 193 | --arg loadJSBuiltinsDynamically false \ | 200 | | - --arg ccache '(import <nixpkgs> {}).sccache' \ | | 194 | + --arg useSeparateDerivationForV8 true \ | | 195 | + --arg ccache "${NIX_SCCACHE:-null}" \ | 201 | 196 | --arg devTools '[]' \ | 202 | 197 | --arg benchmarkTools '[]' \ | 203 | 198 | ${{ endsWith(matrix.system, '-darwin') && '--arg withAmaro false --arg withLief false --arg withSQLite false --arg extraConfigFlags ''["--without-inspector" "--without-node-options"]'' \' || '\' }} | 204 | 199 | --run ' | 205 | 200 | make -C "$TAR_DIR" run-ci -j4 V=1 TEST_CI_ARGS="-p actions --measure-flakiness 9 --skip-tests=$CI_SKIP_TESTS" | 206 | | - ' | | 201 | + ' "$TAR_DIR/shell.nix" |
Collapse file Copy file name to clipboardExpand all lines: configure.py +10-4Lines changed: 10 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2001,10 +2001,16 @@ def configure_v8(o, configs): | 2001 | 2001 | o['variables']['node_enable_v8windbg'] = b(options.enable_v8windbg) | 2002 | 2002 | if options.enable_d8: | 2003 | 2003 | o['variables']['test_isolation_mode'] = 'noop' # Needed by d8.gyp. | 2004 | | - if options.without_bundled_v8 and options.enable_d8: | 2005 | | - raise Exception('--enable-d8 is incompatible with --without-bundled-v8.') | 2006 | | - if options.without_bundled_v8 and options.enable_v8windbg: | 2007 | | - raise Exception('--enable-v8windbg is incompatible with --without-bundled-v8.') | | 2004 | + if options.without_bundled_v8: | | 2005 | + if options.enable_d8: | | 2006 | + raise Exception('--enable-d8 is incompatible with --without-bundled-v8.') | | 2007 | + if options.enable_v8windbg: | | 2008 | + raise Exception('--enable-v8windbg is incompatible with --without-bundled-v8.') | | 2009 | + (pkg_libs, pkg_cflags, pkg_libpath, _) = pkg_config("v8") | | 2010 | + if pkg_libs and pkg_libpath: | | 2011 | + output['libraries'] += [pkg_libpath] + pkg_libs.split() | | 2012 | + if pkg_cflags: | | 2013 | + output['include_dirs'] += [flag for flag in [flag.strip() for flag in pkg_cflags.split('-I')] if flag] | 2008 | 2014 | if options.static_zoslib_gyp: | 2009 | 2015 | o['variables']['static_zoslib_gyp'] = options.static_zoslib_gyp | 2010 | 2016 | if flavor != 'linux' and options.v8_enable_hugepage: | |
Collapse file Copy file name to clipboardExpand all lines: node.gyp +18-2Lines changed: 18 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 641 | 641 | 'xcode_settings': { | 642 | 642 | 'OTHER_LDFLAGS': [ | 643 | 643 | '-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)<(node_core_target_name)<(STATIC_LIB_SUFFIX)', | 644 | | - '-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)v8_base_without_compiler<(STATIC_LIB_SUFFIX)', | 645 | 644 | ], | 646 | 645 | }, | 647 | 646 | 'msvs_settings': { | | 653 | 652 | }, | 654 | 653 | }, | 655 | 654 | 'conditions': [ | 656 | | - ['OS != "aix" and OS != "os400" and OS != "mac" and OS != "ios"', { | | 655 | + ['node_use_bundled_v8=="true"', { | | 656 | + 'xcode_settings': { | | 657 | + 'OTHER_LDFLAGS': [ | | 658 | + '-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)v8_base_without_compiler<(STATIC_LIB_SUFFIX)', | | 659 | + ], | | 660 | + }, | | 661 | + }], | | 662 | + ['node_use_bundled_v8=="true" and OS != "aix" and OS != "os400" and OS != "mac" and OS != "ios"', { | 657 | 663 | 'ldflags': [ | 658 | 664 | '-Wl,--whole-archive', | 659 | 665 | '<(obj_dir)/<(STATIC_LIB_PREFIX)<(node_core_target_name)<(STATIC_LIB_SUFFIX)', | 660 | 666 | '<(obj_dir)/tools/v8_gypfiles/<(STATIC_LIB_PREFIX)v8_base_without_compiler<(STATIC_LIB_SUFFIX)', | 661 | 667 | '-Wl,--no-whole-archive', | 662 | 668 | ], | 663 | 669 | }], | | 670 | + ['node_use_bundled_v8!="true" and OS != "aix" and OS != "os400" and OS != "mac" and OS != "ios"', { | | 671 | + 'ldflags': [ | | 672 | + '-Wl,--whole-archive', | | 673 | + '<(obj_dir)/<(STATIC_LIB_PREFIX)<(node_core_target_name)<(STATIC_LIB_SUFFIX)', | | 674 | + '-Wl,--no-whole-archive', | | 675 | + ], | | 676 | + }], | 664 | 677 | [ 'OS=="win"', { | 665 | 678 | 'sources': [ 'src/res/node.rc' ], | 666 | 679 | }], | | 1530 | 1543 | 'src/builtin_info.cc', | 1531 | 1544 | ], | 1532 | 1545 | 'conditions': [ | | 1546 | + [ 'OS=="mac"', { | | 1547 | + 'libraries': [ '-framework CoreFoundation -framework Security' ], | | 1548 | + }], | 1533 | 1549 | [ 'node_shared_simdutf=="false"', { | 1534 | 1550 | 'dependencies': [ 'tools/v8_gypfiles/v8.gyp:simdutf#host' ], | 1535 | 1551 | }], | |
Collapse file Copy file name to clipboardExpand all lines: node.gypi +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 317 | 317 | 'NODE_PLATFORM="sunos"', | 318 | 318 | ], | 319 | 319 | }], | 320 | | - [ '(OS=="freebsd" or OS=="linux" or OS=="openharmony") and node_shared=="false"' | 321 | | - ' and force_load=="true"', { | | 320 | + [ 'node_use_bundled_v8=="true" and (OS=="freebsd" or OS=="linux" or OS=="openharmony") ' | | 321 | + 'and node_shared=="false" and force_load=="true"', { | 322 | 322 | 'ldflags': [ | 323 | 323 | '-Wl,-z,noexecstack', | 324 | 324 | '-Wl,--whole-archive <(v8_base)', | |
Collapse file Copy file name to clipboardExpand all lines: shell.nix +56-33Lines changed: 56 additions & 33 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | extraConfigFlags ? [ | 9 | 9 | "--debug-node" | 10 | 10 | ], | | 11 | + useSeparateDerivationForV8 ? false, # to help CI better managed its binary cache, not recommended outside of CI usage. | 11 | 12 |
| 12 | 13 | # Build options | 13 | 14 | icu ? pkgs.icu, | | 17 | 18 | withSQLite ? true, | 18 | 19 | withSSL ? true, | 19 | 20 | withTemporal ? false, | 20 | | - sharedLibDeps ? import ./tools/nix/sharedLibDeps.nix { | 21 | | - inherit | 22 | | - pkgs | 23 | | - withLief | 24 | | - withQuic | 25 | | - withSQLite | 26 | | - withSSL | 27 | | - withTemporal | 28 | | - ; | 29 | | - }, | | 21 | + sharedLibDeps ? | | 22 | + let | | 23 | + d = import ./tools/nix/sharedLibDeps.nix { | | 24 | + inherit | | 25 | + pkgs | | 26 | + withLief | | 27 | + withQuic | | 28 | + withSQLite | | 29 | + withSSL | | 30 | + withTemporal | | 31 | + ; | | 32 | + }; | | 33 | + in | | 34 | + # To avoid conflicts with V8's bundled simdutf lib, it's easier to remove it when using a precompiled V8. | | 35 | + if (useSeparateDerivationForV8 != false) then builtins.removeAttrs d [ "simdutf" ] else d, | 30 | 36 |
| 31 | 37 | # dev tools (not needed to build Node.js, useful to maintain it) | 32 | 38 | ncu-path ? null, # Provide this if you want to use a local version of NCU | | 40 | 46 | useSharedOpenSSL = builtins.hasAttr "openssl" sharedLibDeps; | 41 | 47 |
| 42 | 48 | needsRustCompiler = withTemporal && !builtins.hasAttr "temporal_capi" sharedLibDeps; | | 49 | + | | 50 | + buildInputs = builtins.attrValues sharedLibDeps ++ pkgs.lib.optional useSharedICU icu; | | 51 | + configureFlags = [ | | 52 | + ( | | 53 | + if icu == null then | | 54 | + "--without-intl" | | 55 | + else | | 56 | + "--with-intl=${if useSharedICU then "system" else icu}-icu" | | 57 | + ) | | 58 | + ] | | 59 | + ++ extraConfigFlags | | 60 | + ++ pkgs.lib.optional (!withAmaro) "--without-amaro" | | 61 | + ++ pkgs.lib.optional (!withLief) "--without-lief" | | 62 | + ++ pkgs.lib.optional withQuic "--experimental-quic" | | 63 | + ++ pkgs.lib.optional (!withSQLite) "--without-sqlite" | | 64 | + ++ pkgs.lib.optional (!withSSL) "--without-ssl" | | 65 | + ++ pkgs.lib.optional withTemporal "--v8-enable-temporal-support" | | 66 | + ++ pkgs.lib.optional (ninja != null) "--ninja" | | 67 | + ++ pkgs.lib.optional loadJSBuiltinsDynamically "--node-builtin-modules-path=${builtins.toString ../..}" | | 68 | + ++ pkgs.lib.concatMap (name: [ | | 69 | + "--shared-${name}" | | 70 | + "--shared-${name}-libpath=${pkgs.lib.getLib sharedLibDeps.${name}}/lib" | | 71 | + "--shared-${name}-include=${pkgs.lib.getInclude sharedLibDeps.${name}}/include" | | 72 | + ]) (builtins.attrNames sharedLibDeps); | 43 | 73 | in | 44 | 74 | pkgs.mkShell { | 45 | 75 | inherit (pkgs.nodejs_latest) nativeBuildInputs; | 46 | 76 |
| 47 | | - buildInputs = builtins.attrValues sharedLibDeps ++ pkgs.lib.optional useSharedICU icu; | | 77 | + buildInputs = | | 78 | + buildInputs | | 79 | + ++ pkgs.lib.optional (useSeparateDerivationForV8 != false) ( | | 80 | + if useSeparateDerivationForV8 == true then | | 81 | + import ./tools/nix/v8.nix { | | 82 | + inherit | | 83 | + pkgs | | 84 | + configureFlags | | 85 | + buildInputs | | 86 | + needsRustCompiler | | 87 | + ; | | 88 | + } | | 89 | + else | | 90 | + useSeparateDerivationForV8 | | 91 | + ); | 48 | 92 |
| 49 | 93 | packages = | 50 | 94 | pkgs.lib.optional (ccache != null) ccache | @@ -74,28 +118,7 @@ pkgs.mkShell { | 74 | 118 | ] | 75 | 119 | ); | 76 | 120 | CONFIG_FLAGS = builtins.toString ( | 77 | | - [ | 78 | | - ( | 79 | | - if icu == null then | 80 | | - "--without-intl" | 81 | | - else | 82 | | - "--with-intl=${if useSharedICU then "system" else icu}-icu" | 83 | | - ) | 84 | | - ] | 85 | | - ++ extraConfigFlags | 86 | | - ++ pkgs.lib.optional (!withAmaro) "--without-amaro" | 87 | | - ++ pkgs.lib.optional (!withLief) "--without-lief" | 88 | | - ++ pkgs.lib.optional withQuic "--experimental-quic" | 89 | | - ++ pkgs.lib.optional (!withSQLite) "--without-sqlite" | 90 | | - ++ pkgs.lib.optional (!withSSL) "--without-ssl" | 91 | | - ++ pkgs.lib.optional withTemporal "--v8-enable-temporal-support" | 92 | | - ++ pkgs.lib.optional (ninja != null) "--ninja" | 93 | | - ++ pkgs.lib.optional loadJSBuiltinsDynamically "--node-builtin-modules-path=${builtins.toString ./.}" | 94 | | - ++ pkgs.lib.concatMap (name: [ | 95 | | - "--shared-${name}" | 96 | | - "--shared-${name}-libpath=${pkgs.lib.getLib sharedLibDeps.${name}}/lib" | 97 | | - "--shared-${name}-include=${pkgs.lib.getInclude sharedLibDeps.${name}}/include" | 98 | | - ]) (builtins.attrNames sharedLibDeps) | | 121 | + configureFlags ++ pkgs.lib.optional (useSeparateDerivationForV8 != false) "--without-bundled-v8" | 99 | 122 | ); | 100 | 123 | NOSQLITE = pkgs.lib.optionalString (!withSQLite) "1"; | 101 | 124 | } |
Collapse file Copy file name to clipboard +127Lines changed: 127 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Derivation for Node.js CI (not officially supported for regular applications) | | 2 | +{ | | 3 | + pkgs ? import ./pkgs.nix { }, | | 4 | + buildInputs ? [ ], | | 5 | + configureFlags ? [ ], | | 6 | + needsRustCompiler ? false, | | 7 | +}: | | 8 | + | | 9 | +let | | 10 | + nodejs = pkgs.nodejs-slim_latest; | | 11 | + | | 12 | + version = | | 13 | + let | | 14 | + v8Version = builtins.match ( | | 15 | + ".*#define V8_MAJOR_VERSION ([0-9]+).*" | | 16 | + + "#define V8_MINOR_VERSION ([0-9]+).*" | | 17 | + + "#define V8_BUILD_NUMBER ([0-9]+).*" | | 18 | + + "#define V8_PATCH_LEVEL ([0-9]+).*" | | 19 | + ) (builtins.readFile ../../deps/v8/include/v8-version.h); | | 20 | + v8_embedder_string = builtins.match ".*'v8_embedder_string': '-(node.[0-9]+)'.*" ( | | 21 | + builtins.readFile ../../common.gypi | | 22 | + ); | | 23 | + in | | 24 | + if v8Version == null || v8_embedder_string == null then | | 25 | + throw "V8 version not found" | | 26 | + else | | 27 | + "${builtins.elemAt v8Version 0}.${builtins.elemAt v8Version 1}.${builtins.elemAt v8Version 2}.${builtins.elemAt v8Version 3}-${builtins.elemAt v8_embedder_string 0}"; | | 28 | +in | | 29 | +pkgs.stdenv.mkDerivation (finalAttrs: { | | 30 | + pname = "v8"; | | 31 | + inherit version; | | 32 | + src = | | 33 | + let | | 34 | + inherit (pkgs.lib) fileset; | | 35 | + in | | 36 | + fileset.toSource { | | 37 | + root = ../../.; | | 38 | + fileset = fileset.unions [ | | 39 | + ../../common.gypi | | 40 | + ../../configure | | 41 | + ../../configure.py | | 42 | + ../../deps/inspector_protocol/inspector_protocol.gyp | | 43 | + ../../deps/ncrypto/ncrypto.gyp | | 44 | + ../../deps/v8 | | 45 | + ../../node.gyp | | 46 | + ../../node.gypi | | 47 | + ../../src/inspector/node_inspector.gypi | | 48 | + ../../src/node_version.h | | 49 | + ../../tools/configure.d | | 50 | + ../../tools/getmoduleversion.py | | 51 | + ../../tools/getnapibuildversion.py | | 52 | + ../../tools/gyp | | 53 | + ../../tools/gyp_node.py | | 54 | + ../../tools/icu/icu_versions.json | | 55 | + ../../tools/icu/icu-system.gyp | | 56 | + ../../tools/utils.py | | 57 | + ../../tools/v8_gypfiles | | 58 | + ]; | | 59 | + }; | | 60 | + | | 61 | + # We need to patch tools/gyp/ to work from within Nix sandbox | | 62 | + patches = pkgs.lib.optional pkgs.stdenv.buildPlatform.isDarwin ( | | 63 | + pkgs.fetchpatch2 { | | 64 | + url = "https://github.com/NixOS/nixpkgs/raw/2343bbb58f99267223bc2aac4fc9ea301a155a16/pkgs/development/web/nodejs/gyp-patches-set-fallback-value-for-CLT-darwin.patch"; | | 65 | + hash = "sha256-BLF3mf3ME+ED1Qt84Qp9tswJ+3lVnEa10Zr/xdy+IhE="; | | 66 | + includes = [ "tools/gyp/*" ]; | | 67 | + } | | 68 | + ); | | 69 | + | | 70 | + inherit (nodejs) configureScript; | | 71 | + inherit configureFlags buildInputs; | | 72 | + | | 73 | + nativeBuildInputs = | | 74 | + nodejs.nativeBuildInputs | | 75 | + ++ [ | | 76 | + pkgs.patchutils | | 77 | + pkgs.validatePkgConfig | | 78 | + ] | | 79 | + ++ pkgs.lib.optionals needsRustCompiler [ | | 80 | + pkgs.cargo | | 81 | + pkgs.rustc | | 82 | + ]; | | 83 | + | | 84 | + buildPhase = '' | | 85 | + ninja -v -C out/Release v8_snapshot v8_libplatform | | 86 | + ''; | | 87 | + installPhase = '' | | 88 | + ${ | | 89 | + if pkgs.stdenv.buildPlatform.isDarwin then | | 90 | + # Darwin is excluded from creating thin archive in tools/gyp/pylib/gyp/generator/ninja.py:2488 | | 91 | + "install -Dm644 out/Release/lib* -t $out/lib" | | 92 | + else | | 93 | + # On other platforms, we need to create non-thin archive. | | 94 | + '' | | 95 | + mkdir -p $out/lib | | 96 | + for a in out/Release/obj/tools/v8_gypfiles/lib*; do | | 97 | + base=$(basename "$a") | | 98 | + dir=$(dirname "$a") | | 99 | +
| | 100 | + ( | | 101 | + cd "$dir" | | 102 | + "$AR" rc "$out/lib/$base" $("$AR" t "$base") | | 103 | + ) | | 104 | +
| | 105 | + "$RANLIB" "$out/lib/$base" | | 106 | + done | | 107 | + '' | | 108 | + } | | 109 | + libs=$(for f in $out/lib/lib*.a; do | | 110 | + b=$(basename "$f" .a) | | 111 | + printf " -l%s" "''${b#lib}" | | 112 | + done) | | 113 | +
| | 114 | + # copy v8 headers | | 115 | + cp -r deps/v8/include $out/ | | 116 | +
| | 117 | + # create a pkgconfig file for v8 | | 118 | + mkdir -p $out/lib/pkgconfig | | 119 | + cat -> $out/lib/pkgconfig/v8.pc << EOF | | 120 | + Name: v8 | | 121 | + Description: V8 JavaScript Engine build for Node.js CI | | 122 | + Version: ${version} | | 123 | + Libs: -L$out/lib $libs | | 124 | + Cflags: -I$out/include | | 125 | + EOF | | 126 | + ''; | | 127 | +}) |
|