From e3a005fba71fcaebb9b246d499fc930c138a694f Mon Sep 17 00:00:00 2001 From: StefanStojanovic Date: Fri, 20 Dec 2024 10:09:32 +0100 Subject: [PATCH 01/11] build,win: enable ccache --- common.gypi | 3 +++ configure.py | 10 ++++++++++ tools/msvs/props_4_ccache.props | 13 +++++++++++++ vcbuild.bat | 7 ++++++- 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tools/msvs/props_4_ccache.props diff --git a/common.gypi b/common.gypi index df1cf464134483..932b94f54ceb32 100644 --- a/common.gypi +++ b/common.gypi @@ -484,6 +484,9 @@ 'NOMINMAX', ], }], + ['ccache_used == 1', { + 'defines': ['CCACHE_USED',], + }], [ 'OS in "linux freebsd openbsd solaris aix os400"', { 'cflags': [ '-pthread' ], 'ldflags': [ '-pthread' ], diff --git a/configure.py b/configure.py index 227757669cd2a4..5db658ad2ed830 100755 --- a/configure.py +++ b/configure.py @@ -995,6 +995,11 @@ default=None, help='Configure for clang-cl on Windows. This flag sets the GYP "clang" ' + 'variable to 1 and "llvm_version" to the specified value.') +parser.add_argument('--ccache-used', + action='store_true', + dest='ccache_used', + default=None, + help='Ccache is used in compulation on Windows.') (options, args) = parser.parse_known_args() @@ -1171,6 +1176,8 @@ def get_gas_version(cc): # check involves checking the build number against an allowlist. I'm not # quite prepared to go that far yet. def check_compiler(o): + o['variables']['ccache_used'] = 0 + if sys.platform == 'win32': if options.clang_cl: o['variables']['clang'] = 1 @@ -1179,6 +1186,9 @@ def check_compiler(o): o['variables']['clang'] = 0 o['variables']['llvm_version'] = '0.0' + if options.ccache_used: + o['variables']['ccache_used'] = 1 + if not options.openssl_no_asm and options.dest_cpu in ('x86', 'x64'): nasm_version = get_nasm_version('nasm') o['variables']['nasm_version'] = nasm_version diff --git a/tools/msvs/props_4_ccache.props b/tools/msvs/props_4_ccache.props new file mode 100644 index 00000000000000..3fa3b3225830a6 --- /dev/null +++ b/tools/msvs/props_4_ccache.props @@ -0,0 +1,13 @@ + + + true + false + + + + + OldStyle + $(IntDir)%(FileName).obj + + + diff --git a/vcbuild.bat b/vcbuild.bat index f93998d2b14901..4250935a28c362 100644 --- a/vcbuild.bat +++ b/vcbuild.bat @@ -28,6 +28,7 @@ set target_env= set noprojgen= set projgen= set clang_cl= +set ccache_path= set nobuild= set sign= set nosnapshot= @@ -87,6 +88,7 @@ if /i "%1"=="vs2022" set target_env=vs2022&goto arg-ok if /i "%1"=="noprojgen" set noprojgen=1&goto arg-ok if /i "%1"=="projgen" set projgen=1&goto arg-ok if /i "%1"=="clang-cl" set clang_cl=1&goto arg-ok +if /i "%1"=="ccache" set "ccache_path=%2%"&goto arg-ok-2 if /i "%1"=="nobuild" set nobuild=1&goto arg-ok if /i "%1"=="nosign" set "sign="&echo Note: vcbuild no longer signs by default. "nosign" is redundant.&goto arg-ok if /i "%1"=="sign" set sign=1&goto arg-ok @@ -206,6 +208,7 @@ if defined debug_nghttp2 set configure_flags=%configure_flags% --debug-nghttp if defined openssl_no_asm set configure_flags=%configure_flags% --openssl-no-asm if defined no_shared_roheap set configure_flags=%configure_flags% --disable-shared-readonly-heap if defined DEBUG_HELPER set configure_flags=%configure_flags% --verbose +if defined ccache_path set configure_flags=%configure_flags% --ccache-used if defined compile_commands set configure_flags=%configure_flags% -C if "%target_arch%"=="x86" ( @@ -364,6 +367,7 @@ if "%target%"=="Build" ( if "%target%"=="node" if exist "%config%\cctest.exe" del "%config%\cctest.exe" if "%target%"=="node" if exist "%config%\embedtest.exe" del "%config%\embedtest.exe" if defined msbuild_args set "extra_msbuild_args=%extra_msbuild_args% %msbuild_args%" +if defined ccache_path set "extra_msbuild_args=%extra_msbuild_args% /p:TrackFileAccess=false /p:CLToolPath=%ccache_path% /p:ForceImportAfterCppProps=%CD%\tools\msvs\props_4_ccache.props" @rem Setup env variables to use multiprocessor build set UseMultiToolTask=True set EnforceProcessCountAcrossBuilds=True @@ -800,7 +804,7 @@ set exit_code=1 goto exit :help -echo vcbuild.bat [debug/release] [msi] [doc] [test/test-all/test-addons/test-doc/test-js-native-api/test-node-api/test-internet/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [ignore-flaky] [static/dll] [noprojgen] [projgen] [clang-cl] [small-icu/full-icu/without-intl] [nobuild] [nosnapshot] [nonpm] [nocorepack] [ltcg] [licensetf] [sign] [x64/arm64] [vs2022] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-md] [lint-md-build] [format-md] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [cctest] [no-cctest] [openssl-no-asm] +echo vcbuild.bat [debug/release] [msi] [doc] [test/test-all/test-addons/test-doc/test-js-native-api/test-node-api/test-internet/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [ignore-flaky] [static/dll] [noprojgen] [projgen] [clang-cl] [ccache path-to-ccache] [small-icu/full-icu/without-intl] [nobuild] [nosnapshot] [nonpm] [nocorepack] [ltcg] [licensetf] [sign] [x64/arm64] [vs2022] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-md] [lint-md-build] [format-md] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [cctest] [no-cctest] [openssl-no-asm] echo Examples: echo vcbuild.bat : builds release build echo vcbuild.bat debug : builds debug build @@ -811,6 +815,7 @@ echo vcbuild.bat enable-vtune : builds Node.js with Intel VTune pr echo vcbuild.bat link-module my_module.js : bundles my_module as built-in module echo vcbuild.bat lint : runs the C++, documentation and JavaScript linter echo vcbuild.bat no-cctest : skip building cctest.exe +echo vcbuild.bat ccache c:\ccache\ : use ccache to speed build goto exit :exit From 595ffe5b5d38d3e2a1b42c25a3e3ade316cf781d Mon Sep 17 00:00:00 2001 From: StefanStojanovic Date: Tue, 21 Jan 2025 14:01:44 +0100 Subject: [PATCH 02/11] doc,win: add ccache support --- BUILDING.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/BUILDING.md b/BUILDING.md index de224dfa6485ea..7728628701b48f 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -573,6 +573,20 @@ export CC="ccache cc" # add to ~/.zshrc or other shell config file export CXX="ccache c++" # add to ~/.zshrc or other shell config file ``` +On Windows: + +Tips: follow , and you +should notice that obj file will be bigger the normal one. + +First, install ccache, assume ccache install to c:\ccache, copy +c:\ccache\ccache.exe to c:\ccache\cl.exe + +When building Node.js provide a path to your ccache via the option + +```powershell +.\vcbuild.bat ccache c:\ccache\ +``` + This will allow for near-instantaneous rebuilds when switching branches back and forth that were built with cache. From 0dee0d954f77dfc72a405904335d9d4bc33eac13 Mon Sep 17 00:00:00 2001 From: StefanStojanovic Date: Tue, 21 Jan 2025 13:25:14 +0100 Subject: [PATCH 03/11] deps: change V8 generated .h files for ccache Prior to these changes compilation with ccache was broken because of the .h file regeneration in each compilation. --- common.gypi | 2 +- deps/v8/src/builtins/generate-bytecodes-builtins-list.cc | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/common.gypi b/common.gypi index 932b94f54ceb32..f15654fdaa6943 100644 --- a/common.gypi +++ b/common.gypi @@ -37,7 +37,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.10', + 'v8_embedder_string': '-node.11', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/builtins/generate-bytecodes-builtins-list.cc b/deps/v8/src/builtins/generate-bytecodes-builtins-list.cc index 57f100727c06d5..f1fedbc2f06714 100644 --- a/deps/v8/src/builtins/generate-bytecodes-builtins-list.cc +++ b/deps/v8/src/builtins/generate-bytecodes-builtins-list.cc @@ -41,6 +41,14 @@ void WriteBytecode(std::ofstream& out, Bytecode bytecode, void WriteHeader(const char* header_filename) { std::ofstream out(header_filename); +#ifdef CCACHE_USED + // Write a cache invalidator to ensure that ccache does not cache this file. + out << "#ifndef CACHE_INVALIDATOR\n" + << "#define CACHE_INVALIDATOR\n" + << "inline const char* cache_invalidator = __TIME__;\n" + << "#endif\n\n"; +#endif + out << "// Automatically generated from interpreter/bytecodes.h\n" << "// The following list macro is used to populate the builtins list\n" << "// with the bytecode handlers\n\n" From 11446b1d76677e9136885387fa87671060b48533 Mon Sep 17 00:00:00 2001 From: StefanStojanovic Date: Fri, 31 Jan 2025 15:23:39 +0100 Subject: [PATCH 04/11] fix: resolve PR comments Add cp command in building docs Remove CCACHE_USED macro Disable PCH when using Clang and ccache --- BUILDING.md | 6 +++++- common.gypi | 3 --- deps/v8/src/builtins/generate-bytecodes-builtins-list.cc | 8 -------- tools/v8_gypfiles/v8.gyp | 2 +- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/BUILDING.md b/BUILDING.md index 7728628701b48f..62e5cb79866019 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -579,7 +579,11 @@ Tips: follow , and you should notice that obj file will be bigger the normal one. First, install ccache, assume ccache install to c:\ccache, copy -c:\ccache\ccache.exe to c:\ccache\cl.exe +c:\ccache\ccache.exe to c:\ccache\cl.exe with this command + +```powershell +cp c:\ccache\ccache.exe c:\ccache\cl.exe +``` When building Node.js provide a path to your ccache via the option diff --git a/common.gypi b/common.gypi index f15654fdaa6943..1ad3c30629f394 100644 --- a/common.gypi +++ b/common.gypi @@ -484,9 +484,6 @@ 'NOMINMAX', ], }], - ['ccache_used == 1', { - 'defines': ['CCACHE_USED',], - }], [ 'OS in "linux freebsd openbsd solaris aix os400"', { 'cflags': [ '-pthread' ], 'ldflags': [ '-pthread' ], diff --git a/deps/v8/src/builtins/generate-bytecodes-builtins-list.cc b/deps/v8/src/builtins/generate-bytecodes-builtins-list.cc index f1fedbc2f06714..57f100727c06d5 100644 --- a/deps/v8/src/builtins/generate-bytecodes-builtins-list.cc +++ b/deps/v8/src/builtins/generate-bytecodes-builtins-list.cc @@ -41,14 +41,6 @@ void WriteBytecode(std::ofstream& out, Bytecode bytecode, void WriteHeader(const char* header_filename) { std::ofstream out(header_filename); -#ifdef CCACHE_USED - // Write a cache invalidator to ensure that ccache does not cache this file. - out << "#ifndef CACHE_INVALIDATOR\n" - << "#define CACHE_INVALIDATOR\n" - << "inline const char* cache_invalidator = __TIME__;\n" - << "#endif\n\n"; -#endif - out << "// Automatically generated from interpreter/bytecodes.h\n" << "// The following list macro is used to populate the builtins list\n" << "// with the bytecode handlers\n\n" diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp index 9eaa1d219db1b5..35875afc6375e5 100644 --- a/tools/v8_gypfiles/v8.gyp +++ b/tools/v8_gypfiles/v8.gyp @@ -61,7 +61,7 @@ 'type': 'none', 'toolsets': ['host', 'target'], 'conditions': [ - ['OS=="win"', { + ['OS == "win" and (clang != 1 or ccache_used != 1)', { 'direct_dependent_settings': { 'msvs_precompiled_header': '<(V8_ROOT)/../../tools/msvs/pch/v8_pch.h', 'msvs_precompiled_source': '<(V8_ROOT)/../../tools/msvs/pch/v8_pch.cc', From cf0a03740d61947f2aba8060a6a40bf584a9c502 Mon Sep 17 00:00:00 2001 From: Stefan Stojanovic Date: Tue, 4 Feb 2025 16:29:45 +0100 Subject: [PATCH 05/11] Update configure.py Co-authored-by: Joyee Cheung --- configure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.py b/configure.py index 5db658ad2ed830..02a7a72f035aba 100755 --- a/configure.py +++ b/configure.py @@ -995,7 +995,7 @@ default=None, help='Configure for clang-cl on Windows. This flag sets the GYP "clang" ' + 'variable to 1 and "llvm_version" to the specified value.') -parser.add_argument('--ccache-used', +parser.add_argument('--use-ccache-win', action='store_true', dest='ccache_used', default=None, From 8acf94c8ecf14c73eb83eed211a514c1458253b1 Mon Sep 17 00:00:00 2001 From: Stefan Stojanovic Date: Tue, 4 Feb 2025 16:29:55 +0100 Subject: [PATCH 06/11] Update configure.py Co-authored-by: Joyee Cheung --- configure.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.py b/configure.py index 02a7a72f035aba..19591f4dbf671f 100755 --- a/configure.py +++ b/configure.py @@ -997,9 +997,9 @@ 'variable to 1 and "llvm_version" to the specified value.') parser.add_argument('--use-ccache-win', action='store_true', - dest='ccache_used', + dest='use_ccache_win', default=None, - help='Ccache is used in compulation on Windows.') + help='Use ccache for compiling on Windows. ') (options, args) = parser.parse_known_args() From 2f711ac86ca11bfa466fba6e7ee7b24860411cfe Mon Sep 17 00:00:00 2001 From: Stefan Stojanovic Date: Tue, 4 Feb 2025 16:30:05 +0100 Subject: [PATCH 07/11] Update configure.py Co-authored-by: Joyee Cheung --- configure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.py b/configure.py index 19591f4dbf671f..8a355afad56e74 100755 --- a/configure.py +++ b/configure.py @@ -1176,7 +1176,7 @@ def get_gas_version(cc): # check involves checking the build number against an allowlist. I'm not # quite prepared to go that far yet. def check_compiler(o): - o['variables']['ccache_used'] = 0 + o['variables']['use_ccache_win'] = 0 if sys.platform == 'win32': if options.clang_cl: From be40ada0acc5131296cd5bab231b69d8c11497ee Mon Sep 17 00:00:00 2001 From: Stefan Stojanovic Date: Tue, 4 Feb 2025 16:30:15 +0100 Subject: [PATCH 08/11] Update configure.py Co-authored-by: Joyee Cheung --- configure.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.py b/configure.py index 8a355afad56e74..f88e5327007d8c 100755 --- a/configure.py +++ b/configure.py @@ -1186,8 +1186,8 @@ def check_compiler(o): o['variables']['clang'] = 0 o['variables']['llvm_version'] = '0.0' - if options.ccache_used: - o['variables']['ccache_used'] = 1 + if options.use_ccache_win: + o['variables']['use_ccache_win'] = 1 if not options.openssl_no_asm and options.dest_cpu in ('x86', 'x64'): nasm_version = get_nasm_version('nasm') From 7d8baa45bc54eba8136770bbe91d783daf90bf64 Mon Sep 17 00:00:00 2001 From: Stefan Stojanovic Date: Tue, 4 Feb 2025 16:30:25 +0100 Subject: [PATCH 09/11] Update tools/v8_gypfiles/v8.gyp Co-authored-by: Joyee Cheung --- tools/v8_gypfiles/v8.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp index 35875afc6375e5..c539c1814f7980 100644 --- a/tools/v8_gypfiles/v8.gyp +++ b/tools/v8_gypfiles/v8.gyp @@ -61,7 +61,7 @@ 'type': 'none', 'toolsets': ['host', 'target'], 'conditions': [ - ['OS == "win" and (clang != 1 or ccache_used != 1)', { + ['OS == "win" and (clang != 1 or use_ccache_win != 1)', { 'direct_dependent_settings': { 'msvs_precompiled_header': '<(V8_ROOT)/../../tools/msvs/pch/v8_pch.h', 'msvs_precompiled_source': '<(V8_ROOT)/../../tools/msvs/pch/v8_pch.cc', From 8382b1518d0cb82a47f148c1e0f487a3c4ca40ef Mon Sep 17 00:00:00 2001 From: Stefan Stojanovic Date: Tue, 4 Feb 2025 16:30:34 +0100 Subject: [PATCH 10/11] Update common.gypi Co-authored-by: Joyee Cheung --- common.gypi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.gypi b/common.gypi index 1ad3c30629f394..df1cf464134483 100644 --- a/common.gypi +++ b/common.gypi @@ -37,7 +37,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.11', + 'v8_embedder_string': '-node.10', ##### V8 defaults for Node.js ##### From 2e834a1c77c359ad6813b2ff872c4908453bac07 Mon Sep 17 00:00:00 2001 From: StefanStojanovic Date: Tue, 4 Feb 2025 17:01:08 +0100 Subject: [PATCH 11/11] Update vcbuild.bat --- vcbuild.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcbuild.bat b/vcbuild.bat index 4250935a28c362..eb8e5194f0fb8a 100644 --- a/vcbuild.bat +++ b/vcbuild.bat @@ -208,7 +208,7 @@ if defined debug_nghttp2 set configure_flags=%configure_flags% --debug-nghttp if defined openssl_no_asm set configure_flags=%configure_flags% --openssl-no-asm if defined no_shared_roheap set configure_flags=%configure_flags% --disable-shared-readonly-heap if defined DEBUG_HELPER set configure_flags=%configure_flags% --verbose -if defined ccache_path set configure_flags=%configure_flags% --ccache-used +if defined ccache_path set configure_flags=%configure_flags% --use-ccache-win if defined compile_commands set configure_flags=%configure_flags% -C if "%target_arch%"=="x86" (