• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1@if not defined DEBUG_HELPER @ECHO OFF
2
3:: Other scripts rely on the environment variables set in this script, so we
4:: explicitly allow them to persist in the calling shell.
5endlocal
6
7if /i "%1"=="help" goto help
8if /i "%1"=="--help" goto help
9if /i "%1"=="-help" goto help
10if /i "%1"=="/help" goto help
11if /i "%1"=="?" goto help
12if /i "%1"=="-?" goto help
13if /i "%1"=="--?" goto help
14if /i "%1"=="/?" goto help
15
16cd %~dp0
17
18set JS_SUITES=default
19set NATIVE_SUITES=addons js-native-api node-api
20@rem CI_* variables should be kept synchronized with the ones in Makefile
21set "CI_NATIVE_SUITES=%NATIVE_SUITES% benchmark"
22set "CI_JS_SUITES=%JS_SUITES% pummel"
23set CI_DOC=doctool
24@rem Same as the test-ci target in Makefile
25set "common_test_suites=%JS_SUITES% %NATIVE_SUITES%&set build_addons=1&set build_js_native_api_tests=1&set build_node_api_tests=1"
26
27@rem Process arguments.
28set config=Release
29set target=Build
30set target_arch=x64
31set ltcg=
32set target_env=
33set noprojgen=
34set projgen=
35set nobuild=
36set sign=
37set nosnapshot=
38set nonpm=
39set nocorepack=
40set cctest_args=
41set test_args=
42set stage_package=
43set package=
44set msi=
45set upload=
46set licensertf=
47set lint_js=
48set lint_cpp=
49set lint_md=
50set lint_md_build=
51set noetw=
52set noetw_msi_arg=
53set i18n_arg=
54set download_arg=
55set build_release=
56set configure_flags=
57set enable_vtune_arg=
58set build_addons=
59set dll=
60set enable_static=
61set build_js_native_api_tests=
62set build_node_api_tests=
63set test_node_inspect=
64set test_check_deopts=
65set v8_test_options=
66set v8_build_options=
67set http2_debug=
68set nghttp2_debug=
69set link_module=
70set no_cctest=
71set cctest=
72set openssl_no_asm=
73set no_shared_roheap=
74set doc=
75set extra_msbuild_args=
76set exit_code=0
77
78:next-arg
79if "%1"=="" goto args-done
80if /i "%1"=="debug"         set config=Debug&goto arg-ok
81if /i "%1"=="release"       set config=Release&set ltcg=1&set cctest=1&goto arg-ok
82if /i "%1"=="clean"         set target=Clean&goto arg-ok
83if /i "%1"=="testclean"     set target=TestClean&goto arg-ok
84if /i "%1"=="ia32"          set target_arch=x86&goto arg-ok
85if /i "%1"=="x86"           set target_arch=x86&goto arg-ok
86if /i "%1"=="x64"           set target_arch=x64&goto arg-ok
87if /i "%1"=="arm64"         set target_arch=arm64&goto arg-ok
88if /i "%1"=="vs2019"        set target_env=vs2019&goto arg-ok
89if /i "%1"=="vs2022"        set target_env=vs2022&goto arg-ok
90if /i "%1"=="noprojgen"     set noprojgen=1&goto arg-ok
91if /i "%1"=="projgen"       set projgen=1&goto arg-ok
92if /i "%1"=="nobuild"       set nobuild=1&goto arg-ok
93if /i "%1"=="nosign"        set "sign="&echo Note: vcbuild no longer signs by default. "nosign" is redundant.&goto arg-ok
94if /i "%1"=="sign"          set sign=1&goto arg-ok
95if /i "%1"=="nosnapshot"    set nosnapshot=1&goto arg-ok
96if /i "%1"=="nonpm"         set nonpm=1&goto arg-ok
97if /i "%1"=="nocorepack"    set nocorepack=1&goto arg-ok
98if /i "%1"=="noetw"         set noetw=1&goto arg-ok
99if /i "%1"=="ltcg"          set ltcg=1&goto arg-ok
100if /i "%1"=="licensertf"    set licensertf=1&goto arg-ok
101if /i "%1"=="test"          set test_args=%test_args% %common_test_suites%&set lint_cpp=1&set lint_js=1&set lint_md=1&goto arg-ok
102if /i "%1"=="test-ci-native" set test_args=%test_args% %test_ci_args% -p tap --logfile test.tap %CI_NATIVE_SUITES% %CI_DOC%&set build_addons=1&set build_js_native_api_tests=1&set build_node_api_tests=1&set cctest_args=%cctest_args% --gtest_output=xml:cctest.junit.xml&goto arg-ok
103if /i "%1"=="test-ci-js"    set test_args=%test_args% %test_ci_args% -p tap --logfile test.tap %CI_JS_SUITES%&set no_cctest=1&goto arg-ok
104if /i "%1"=="build-addons"   set build_addons=1&goto arg-ok
105if /i "%1"=="build-js-native-api-tests"   set build_js_native_api_tests=1&goto arg-ok
106if /i "%1"=="build-node-api-tests"   set build_node_api_tests=1&goto arg-ok
107if /i "%1"=="test-addons"   set test_args=%test_args% addons&set build_addons=1&goto arg-ok
108if /i "%1"=="test-doc"      set test_args=%test_args% %CI_DOC%&set doc=1&&set lint_js=1&set lint_md=1&goto arg-ok
109if /i "%1"=="test-js-native-api"   set test_args=%test_args% js-native-api&set build_js_native_api_tests=1&goto arg-ok
110if /i "%1"=="test-node-api"   set test_args=%test_args% node-api&set build_node_api_tests=1&goto arg-ok
111if /i "%1"=="test-benchmark" set test_args=%test_args% benchmark&goto arg-ok
112if /i "%1"=="test-simple"   set test_args=%test_args% sequential parallel&goto arg-ok
113if /i "%1"=="test-message"  set test_args=%test_args% message&goto arg-ok
114if /i "%1"=="test-tick-processor" set test_args=%test_args% tick-processor&goto arg-ok
115if /i "%1"=="test-internet" set test_args=%test_args% internet&goto arg-ok
116if /i "%1"=="test-pummel"   set test_args=%test_args% pummel&goto arg-ok
117if /i "%1"=="test-known-issues" set test_args=%test_args% known_issues&goto arg-ok
118if /i "%1"=="test-async-hooks"  set test_args=%test_args% async-hooks&goto arg-ok
119if /i "%1"=="test-all"      set test_args=%test_args% gc internet pummel %common_test_suites%&set lint_cpp=1&set lint_js=1&goto arg-ok
120if /i "%1"=="test-node-inspect" set test_node_inspect=1&goto arg-ok
121if /i "%1"=="test-check-deopts" set test_check_deopts=1&goto arg-ok
122if /i "%1"=="test-npm"      set test_npm=1&goto arg-ok
123if /i "%1"=="test-v8"       set test_v8=1&set custom_v8_test=1&goto arg-ok
124if /i "%1"=="test-v8-intl"  set test_v8_intl=1&set custom_v8_test=1&goto arg-ok
125if /i "%1"=="test-v8-benchmarks" set test_v8_benchmarks=1&set custom_v8_test=1&goto arg-ok
126if /i "%1"=="test-v8-all"       set test_v8=1&set test_v8_intl=1&set test_v8_benchmarks=1&set custom_v8_test=1&goto arg-ok
127if /i "%1"=="lint-cpp"      set lint_cpp=1&goto arg-ok
128if /i "%1"=="lint-js"       set lint_js=1&goto arg-ok
129if /i "%1"=="jslint"        set lint_js=1&echo Please use lint-js instead of jslint&goto arg-ok
130if /i "%1"=="lint-md"       set lint_md=1&goto arg-ok
131if /i "%1"=="lint-md-build" set lint_md_build=1&goto arg-ok
132if /i "%1"=="lint"          set lint_cpp=1&set lint_js=1&set lint_md=1&goto arg-ok
133if /i "%1"=="lint-ci"       set lint_cpp=1&set lint_js_ci=1&goto arg-ok
134if /i "%1"=="package"       set package=1&goto arg-ok
135if /i "%1"=="msi"           set msi=1&set licensertf=1&set download_arg="--download=all"&set i18n_arg=full-icu&goto arg-ok
136if /i "%1"=="build-release" set build_release=1&set sign=1&goto arg-ok
137if /i "%1"=="upload"        set upload=1&goto arg-ok
138if /i "%1"=="small-icu"     set i18n_arg=%1&goto arg-ok
139if /i "%1"=="full-icu"      set i18n_arg=%1&goto arg-ok
140if /i "%1"=="intl-none"     set i18n_arg=none&goto arg-ok
141if /i "%1"=="without-intl"  set i18n_arg=none&goto arg-ok
142if /i "%1"=="download-all"  set download_arg="--download=all"&goto arg-ok
143if /i "%1"=="ignore-flaky"  set test_args=%test_args% --flaky-tests=dontcare&goto arg-ok
144if /i "%1"=="dll"           set dll=1&goto arg-ok
145if /i "%1"=="enable-vtune" set enable_vtune_arg=1&goto arg-ok
146if /i "%1"=="static"           set enable_static=1&goto arg-ok
147if /i "%1"=="no-NODE-OPTIONS"	set no_NODE_OPTIONS=1&goto arg-ok
148if /i "%1"=="debug-nghttp2" set debug_nghttp2=1&goto arg-ok
149if /i "%1"=="link-module"   set "link_module= --link-module=%2%link_module%"&goto arg-ok-2
150if /i "%1"=="no-cctest"     set no_cctest=1&goto arg-ok
151if /i "%1"=="cctest"        set cctest=1&goto arg-ok
152if /i "%1"=="openssl-no-asm"   set openssl_no_asm=1&goto arg-ok
153if /i "%1"=="no-shared-roheap" set no_shared_roheap=1&goto arg-ok
154if /i "%1"=="doc"           set doc=1&goto arg-ok
155if /i "%1"=="binlog"        set extra_msbuild_args=/binaryLogger:%config%\node.binlog&goto arg-ok
156
157echo Error: invalid command line option `%1`.
158exit /b 1
159
160:arg-ok-2
161shift
162:arg-ok
163shift
164goto next-arg
165
166:args-done
167
168if defined build_release (
169  set config=Release
170  set package=1
171  set msi=1
172  set licensertf=1
173  set download_arg="--download=all"
174  set i18n_arg=full-icu
175  set projgen=1
176  set cctest=1
177  set ltcg=1
178)
179
180if defined msi     set stage_package=1
181if defined package set stage_package=1
182
183:: assign path to node_exe
184set "node_exe=%config%\node.exe"
185set "node_gyp_exe="%node_exe%" deps\npm\node_modules\node-gyp\bin\node-gyp"
186set "npm_exe="%~dp0%node_exe%" %~dp0deps\npm\bin\npm-cli.js"
187if "%target_env%"=="vs2019" set "node_gyp_exe=%node_gyp_exe% --msvs_version=2019"
188if "%target_env%"=="vs2022" set "node_gyp_exe=%node_gyp_exe% --msvs_version=2022"
189
190:: skip building if the only argument received was lint
191if "%*"=="lint" if exist "%node_exe%" goto lint-cpp
192
193if "%config%"=="Debug"      set configure_flags=%configure_flags% --debug
194if defined nosnapshot       set configure_flags=%configure_flags% --without-snapshot
195if defined nonpm            set configure_flags=%configure_flags% --without-npm
196if defined nocorepack       set configure_flags=%configure_flags% --without-corepack
197if defined noetw            set configure_flags=%configure_flags% --without-etw& set noetw_msi_arg=/p:NoETW=1
198if defined ltcg             set configure_flags=%configure_flags% --with-ltcg
199if defined release_urlbase  set configure_flags=%configure_flags% --release-urlbase=%release_urlbase%
200if defined download_arg     set configure_flags=%configure_flags% %download_arg%
201if defined enable_vtune_arg set configure_flags=%configure_flags% --enable-vtune-profiling
202if defined dll              set configure_flags=%configure_flags% --shared
203if defined enable_static    set configure_flags=%configure_flags% --enable-static
204if defined no_NODE_OPTIONS  set configure_flags=%configure_flags% --without-node-options
205if defined link_module      set configure_flags=%configure_flags% %link_module%
206if defined i18n_arg         set configure_flags=%configure_flags% --with-intl=%i18n_arg%
207if defined config_flags     set configure_flags=%configure_flags% %config_flags%
208if defined target_arch      set configure_flags=%configure_flags% --dest-cpu=%target_arch%
209if defined debug_nghttp2    set configure_flags=%configure_flags% --debug-nghttp2
210if defined openssl_no_asm   set configure_flags=%configure_flags% --openssl-no-asm
211if defined no_shared_roheap set configure_flags=%configure_flags% --disable-shared-readonly-heap
212if defined DEBUG_HELPER     set configure_flags=%configure_flags% --verbose
213if "%target_arch%"=="x86" if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set configure_flags=%configure_flags% --no-cross-compiling
214
215if not exist "%~dp0deps\icu" goto no-depsicu
216if "%target%"=="Clean" echo deleting %~dp0deps\icu
217if "%target%"=="Clean" rmdir /S /Q %~dp0deps\icu
218:no-depsicu
219
220if "%target%"=="TestClean" (
221  echo deleting test/.tmp*
222  if exist "test\.tmp*" for /f %%i in ('dir /a:d /s /b test\.tmp*') do rmdir /S /Q "%%i"
223  goto exit
224)
225
226
227call tools\msvs\find_python.cmd
228if errorlevel 1 goto :exit
229
230REM NASM is only needed on IA32 and x86_64.
231if not defined openssl_no_asm if "%target_arch%" NEQ "arm64" call tools\msvs\find_nasm.cmd
232if errorlevel 1 echo Could not find NASM, install it or build with openssl-no-asm. See BUILDING.md.
233
234call :getnodeversion || exit /b 1
235
236if defined TAG set configure_flags=%configure_flags% --tag=%TAG%
237
238if not "%target%"=="Clean" goto skip-clean
239rmdir /Q /S "%~dp0%config%\%TARGET_NAME%" > nul 2> nul
240:skip-clean
241
242if defined noprojgen if defined nobuild goto :after-build
243
244@rem Set environment for msbuild
245
246set msvs_host_arch=x86
247if _%PROCESSOR_ARCHITECTURE%_==_AMD64_ set msvs_host_arch=amd64
248if _%PROCESSOR_ARCHITEW6432%_==_AMD64_ set msvs_host_arch=amd64
249if _%PROCESSOR_ARCHITECTURE%_==_ARM64_ set msvs_host_arch=arm64
250@rem usually vcvarsall takes an argument: host + '_' + target
251set vcvarsall_arg=%msvs_host_arch%_%target_arch%
252@rem unless both the host and the target are the same
253if %target_arch%==x64 if %msvs_host_arch%==amd64 set vcvarsall_arg=amd64
254if %target_arch%==%msvs_host_arch% set vcvarsall_arg=%target_arch%
255
256@rem Look for Visual Studio 2022
257:vs-set-2022
258if defined target_env if "%target_env%" NEQ "vs2022" goto vs-set-2019
259echo Looking for Visual Studio 2022
260@rem VCINSTALLDIR may be set if run from a VS Command Prompt and needs to be
261@rem cleared first as vswhere_usability_wrapper.cmd doesn't when it fails to
262@rem detect the version searched for
263if not defined target_env set "VCINSTALLDIR="
264call tools\msvs\vswhere_usability_wrapper.cmd "[17.0,18.0)" %target_arch% "prerelease"
265if "_%VCINSTALLDIR%_" == "__" goto vs-set-2019
266set "WIXSDKDIR=%WIX%\SDK\VS2017"
267if defined msi (
268  echo Looking for WiX installation for Visual Studio 2022...
269  if not exist "%WIXSDKDIR%" (
270    echo Failed to find WiX install for Visual Studio 2022
271    echo VS2022 support for WiX is only present starting at version 3.XX
272    goto vs-set-2019
273  )
274  if not exist "%VCINSTALLDIR%\..\MSBuild\Microsoft\WiX" (
275    echo Failed to find the WiX Toolset Visual Studio 2022 Extension
276    goto vs-set-2019
277  )
278)
279@rem check if VS2022 is already setup, and for the requested arch
280if "_%VisualStudioVersion%_" == "_17.0_" if "_%VSCMD_ARG_TGT_ARCH%_"=="_%target_arch%_" goto found_vs2022
281@rem need to clear VSINSTALLDIR for vcvarsall to work as expected
282set "VSINSTALLDIR="
283@rem prevent VsDevCmd.bat from changing the current working directory
284set "VSCMD_START_DIR=%CD%"
285set vcvars_call="%VCINSTALLDIR%\Auxiliary\Build\vcvarsall.bat" %vcvarsall_arg%
286echo calling: %vcvars_call%
287call %vcvars_call%
288if errorlevel 1 goto vs-set-2019
289if defined DEBUG_HELPER @ECHO ON
290:found_vs2022
291echo Found MSVS version %VisualStudioVersion%
292set GYP_MSVS_VERSION=2022
293set PLATFORM_TOOLSET=v143
294goto msbuild-found
295
296@rem Look for Visual Studio 2019
297:vs-set-2019
298if defined target_env if "%target_env%" NEQ "vs2019" goto msbuild-not-found
299echo Looking for Visual Studio 2019
300@rem VCINSTALLDIR may be set if run from a VS Command Prompt and needs to be
301@rem cleared first as vswhere_usability_wrapper.cmd doesn't when it fails to
302@rem detect the version searched for
303if not defined target_env set "VCINSTALLDIR="
304call tools\msvs\vswhere_usability_wrapper.cmd "[16.0,17.0)" %target_arch% "prerelease"
305if "_%VCINSTALLDIR%_" == "__" goto msbuild-not-found
306set "WIXSDKDIR=%WIX%\SDK\VS2017"
307if defined msi (
308  echo Looking for WiX installation for Visual Studio 2019...
309  if not exist "%WIXSDKDIR%" (
310    echo Failed to find WiX install for Visual Studio 2019
311    echo VS2019 support for WiX is only present starting at version 3.11
312    goto msbuild-not-found
313  )
314  if not exist "%VCINSTALLDIR%\..\MSBuild\Microsoft\WiX" (
315    echo Failed to find the WiX Toolset Visual Studio 2019 Extension
316    goto msbuild-not-found
317  )
318)
319@rem check if VS2019 is already setup, and for the requested arch
320if "_%VisualStudioVersion%_" == "_16.0_" if "_%VSCMD_ARG_TGT_ARCH%_"=="_%target_arch%_" goto found_vs2019
321@rem need to clear VSINSTALLDIR for vcvarsall to work as expected
322set "VSINSTALLDIR="
323@rem prevent VsDevCmd.bat from changing the current working directory
324set "VSCMD_START_DIR=%CD%"
325set vcvars_call="%VCINSTALLDIR%\Auxiliary\Build\vcvarsall.bat" %vcvarsall_arg%
326echo calling: %vcvars_call%
327call %vcvars_call%
328if errorlevel 1 goto msbuild-not-found
329if defined DEBUG_HELPER @ECHO ON
330:found_vs2019
331echo Found MSVS version %VisualStudioVersion%
332set GYP_MSVS_VERSION=2019
333set PLATFORM_TOOLSET=v142
334goto msbuild-found
335
336:msbuild-not-found
337echo Failed to find a suitable Visual Studio installation.
338echo Try to run in a "Developer Command Prompt" or consult
339echo https://github.com/nodejs/node/blob/HEAD/BUILDING.md#windows
340goto exit
341
342:msbuild-found
343
344set project_generated=
345:project-gen
346@rem Skip project generation if requested.
347if defined noprojgen goto msbuild
348if defined projgen goto run-configure
349if not exist node.sln goto run-configure
350if not exist .gyp_configure_stamp goto run-configure
351echo %configure_flags% > .tmp_gyp_configure_stamp
352where /R . /T *.gyp* >> .tmp_gyp_configure_stamp
353fc .gyp_configure_stamp .tmp_gyp_configure_stamp >NUL 2>&1
354if errorlevel 1 goto run-configure
355
356:skip-configure
357del .tmp_gyp_configure_stamp 2> NUL
358echo Reusing solution generated with %configure_flags%
359goto msbuild
360
361:run-configure
362del .tmp_gyp_configure_stamp 2> NUL
363del .gyp_configure_stamp 2> NUL
364@rem Generate the VS project.
365echo configure %configure_flags%
366echo %configure_flags%> .used_configure_flags
367python configure %configure_flags%
368if errorlevel 1 goto create-msvs-files-failed
369if not exist node.sln goto create-msvs-files-failed
370set project_generated=1
371echo Project files generated.
372echo %configure_flags% > .gyp_configure_stamp
373where /R . /T *.gyp* >> .gyp_configure_stamp
374
375:msbuild
376@rem Skip build if requested.
377if defined nobuild goto :after-build
378
379@rem Build the sln with msbuild.
380set "msbcpu=/m:2"
381if "%NUMBER_OF_PROCESSORS%"=="1" set "msbcpu=/m:1"
382set "msbplatform=Win32"
383if "%target_arch%"=="x64" set "msbplatform=x64"
384if "%target_arch%"=="arm64" set "msbplatform=ARM64"
385if "%target%"=="Build" (
386  if defined no_cctest set target=node
387  if "%test_args%"=="" set target=node
388  if defined cctest set target="Build"
389)
390if "%target%"=="node" if exist "%config%\cctest.exe" del "%config%\cctest.exe"
391if defined msbuild_args set "extra_msbuild_args=%extra_msbuild_args% %msbuild_args%"
392@rem Setup env variables to use multiprocessor build
393set UseMultiToolTask=True
394set EnforceProcessCountAcrossBuilds=True
395set MultiProcMaxCount=%NUMBER_OF_PROCESSORS%
396msbuild node.sln %msbcpu% /t:%target% /p:Configuration=%config% /p:Platform=%msbplatform% /clp:NoItemAndPropertyList;Verbosity=minimal /nologo %extra_msbuild_args%
397if errorlevel 1 (
398  if not defined project_generated echo Building Node with reused solution failed. To regenerate project files use "vcbuild projgen"
399  exit /B 1
400)
401if "%target%" == "Clean" goto exit
402
403:after-build
404rd %config%
405if errorlevel 1 echo "Old build output exists at 'out\%config%'. Please remove." & exit /B
406:: Use /J because /D (symlink) requires special permissions.
407if EXIST out\%config% mklink /J %config% out\%config%
408if errorlevel 1 echo "Could not create junction to 'out\%config%'." & exit /B
409
410:sign
411@rem Skip signing unless the `sign` option was specified.
412if not defined sign goto licensertf
413
414call tools\sign.bat Release\node.exe
415if errorlevel 1 echo Failed to sign exe, got error code %errorlevel%&goto exit
416
417:licensertf
418@rem Skip license.rtf generation if not requested.
419if not defined licensertf goto stage_package
420
421set "use_x64_node_exe=false"
422if "%target_arch%"=="arm64" if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set "use_x64_node_exe=true"
423set "x64_node_exe=temp-vcbuild\node-x64-cross-compiling.exe"
424if "%use_x64_node_exe%"=="true" (
425  echo Cross-compilation to ARM64 detected. We'll use the x64 Node executable for license2rtf.
426  if not exist "%x64_node_exe%" (
427    echo Downloading x64 node.exe...
428    if not exist "temp-vcbuild" mkdir temp-vcbuild
429    powershell -c "Invoke-WebRequest -Uri 'https://nodejs.org/dist/latest/win-x64/node.exe' -OutFile '%x64_node_exe%'"
430  )
431  if not exist "%x64_node_exe%" (
432    echo Could not find the Node executable at the given x64_node_exe path. Aborting.
433    set exit_code=1
434    goto exit
435  )
436  %x64_node_exe% tools\license2rtf.mjs < LICENSE > %config%\license.rtf
437) else (
438  %node_exe% tools\license2rtf.mjs < LICENSE > %config%\license.rtf
439)
440
441if errorlevel 1 echo Failed to generate license.rtf, got error code %errorlevel%&goto exit
442
443:stage_package
444if not defined stage_package goto install-doctools
445
446echo Creating package...
447cd Release
448rmdir /S /Q %TARGET_NAME% > nul 2> nul
449mkdir %TARGET_NAME% > nul 2> nul
450mkdir %TARGET_NAME%\node_modules > nul 2>nul
451
452copy /Y node.exe %TARGET_NAME%\ > nul
453if errorlevel 1 echo Cannot copy node.exe && goto package_error
454copy /Y ..\LICENSE %TARGET_NAME%\ > nul
455if errorlevel 1 echo Cannot copy LICENSE && goto package_error
456copy /Y ..\README.md %TARGET_NAME%\ > nul
457if errorlevel 1 echo Cannot copy README.md && goto package_error
458copy /Y ..\CHANGELOG.md %TARGET_NAME%\ > nul
459if errorlevel 1 echo Cannot copy CHANGELOG.md && goto package_error
460
461if not defined nonpm (
462  robocopy ..\deps\npm %TARGET_NAME%\node_modules\npm /e /xd test > nul
463  if errorlevel 8 echo Cannot copy npm package && goto package_error
464  copy /Y ..\deps\npm\bin\npm %TARGET_NAME%\ > nul
465  if errorlevel 1 echo Cannot copy npm && goto package_error
466  copy /Y ..\deps\npm\bin\npm.cmd %TARGET_NAME%\ > nul
467  if errorlevel 1 echo Cannot copy npm.cmd && goto package_error
468  copy /Y ..\deps\npm\bin\npx %TARGET_NAME%\ > nul
469  if errorlevel 1 echo Cannot copy npx && goto package_error
470  copy /Y ..\deps\npm\bin\npx.cmd %TARGET_NAME%\ > nul
471  if errorlevel 1 echo Cannot copy npx.cmd && goto package_error
472)
473
474if not defined nocorepack (
475  robocopy ..\deps\corepack %TARGET_NAME%\node_modules\corepack /e /xd test > nul
476  if errorlevel 8 echo Cannot copy corepack package && goto package_error
477  copy /Y ..\deps\corepack\shims\nodewin\corepack %TARGET_NAME%\ > nul
478  if errorlevel 1 echo Cannot copy corepack && goto package_error
479  copy /Y ..\deps\corepack\shims\nodewin\corepack.cmd %TARGET_NAME%\ > nul
480  if errorlevel 1 echo Cannot copy corepack.cmd && goto package_error
481)
482
483copy /Y ..\tools\msvs\nodevars.bat %TARGET_NAME%\ > nul
484if errorlevel 1 echo Cannot copy nodevars.bat && goto package_error
485copy /Y ..\tools\msvs\install_tools\*.* %TARGET_NAME%\ > nul
486if errorlevel 1 echo Cannot copy install_tools scripts && goto package_error
487if not defined noetw (
488    copy /Y ..\src\res\node_etw_provider.man %TARGET_NAME%\ > nul
489    if errorlevel 1 echo Cannot copy node_etw_provider.man && goto package_error
490)
491if defined dll (
492  copy /Y libnode.dll %TARGET_NAME%\ > nul
493  if errorlevel 1 echo Cannot copy libnode.dll && goto package_error
494
495  mkdir %TARGET_NAME%\Release > nul
496  copy /Y node.def %TARGET_NAME%\Release\ > nul
497  if errorlevel 1 echo Cannot copy node.def && goto package_error
498
499  set HEADERS_ONLY=1
500  python ..\tools\install.py install %CD%\%TARGET_NAME% \ > nul
501  if errorlevel 1 echo Cannot install headers && goto package_error
502  set HEADERS_ONLY=
503)
504cd ..
505
506:package
507if not defined package goto msi
508cd Release
509echo Creating %TARGET_NAME%.7z
510del %TARGET_NAME%.7z > nul 2> nul
5117z a -r -mx9 -t7z %TARGET_NAME%.7z %TARGET_NAME% > nul
512if errorlevel 1 echo Cannot create %TARGET_NAME%.7z && goto package_error
513
514echo Creating %TARGET_NAME%.zip
515del %TARGET_NAME%.zip > nul 2> nul
5167z a -r -mx9 -tzip %TARGET_NAME%.zip %TARGET_NAME% > nul
517if errorlevel 1 echo Cannot create %TARGET_NAME%.zip && goto package_error
518
519echo Creating node_pdb.7z
520del node_pdb.7z > nul 2> nul
5217z a -mx9 -t7z node_pdb.7z node.pdb > nul
522
523echo Creating node_pdb.zip
524del node_pdb.zip  > nul 2> nul
5257z a -mx9 -tzip node_pdb.zip node.pdb > nul
526
527cd ..
528echo Package created!
529goto package_done
530:package_error
531cd ..
532exit /b 1
533:package_done
534
535:msi
536@rem Skip msi generation if not requested
537if not defined msi goto install-doctools
538
539:msibuild
540echo Building node-v%FULLVERSION%-%target_arch%.msi
541set "msbsdk="
542if defined WindowsSDKVersion set "msbsdk=/p:WindowsTargetPlatformVersion=%WindowsSDKVersion:~0,-1%"
543msbuild "%~dp0tools\msvs\msi\nodemsi.sln" /m /t:Clean,Build %msbsdk% /p:PlatformToolset=%PLATFORM_TOOLSET% /p:WixSdkDir="%WIXSDKDIR%" /p:Configuration=%config% /p:Platform=%target_arch% /p:NodeVersion=%NODE_VERSION% /p:FullVersion=%FULLVERSION% /p:DistTypeDir=%DISTTYPEDIR% %noetw_msi_arg% /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo
544if errorlevel 1 goto exit
545
546if not defined sign goto upload
547call tools\sign.bat node-v%FULLVERSION%-%target_arch%.msi
548if errorlevel 1 echo Failed to sign msi, got error code %errorlevel%&goto exit
549
550:upload
551@rem Skip upload if not requested
552if not defined upload goto install-doctools
553
554if not defined SSHCONFIG (
555  echo SSHCONFIG is not set for upload
556  exit /b 1
557)
558
559if not defined STAGINGSERVER set STAGINGSERVER=node-www
560ssh -F %SSHCONFIG% %STAGINGSERVER% "mkdir -p nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%"
561if errorlevel 1 goto exit
562scp -F %SSHCONFIG% Release\node.exe %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%/node.exe
563if errorlevel 1 goto exit
564scp -F %SSHCONFIG% Release\node.lib %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%/node.lib
565if errorlevel 1 goto exit
566scp -F %SSHCONFIG% Release\node_pdb.zip %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%/node_pdb.zip
567if errorlevel 1 goto exit
568scp -F %SSHCONFIG% Release\node_pdb.7z %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%/node_pdb.7z
569if errorlevel 1 goto exit
570scp -F %SSHCONFIG% Release\%TARGET_NAME%.7z %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/%TARGET_NAME%.7z
571if errorlevel 1 goto exit
572scp -F %SSHCONFIG% Release\%TARGET_NAME%.zip %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/%TARGET_NAME%.zip
573if errorlevel 1 goto exit
574scp -F %SSHCONFIG% node-v%FULLVERSION%-%target_arch%.msi %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/
575if errorlevel 1 goto exit
576ssh -F %SSHCONFIG% %STAGINGSERVER% "touch nodejs/%DISTTYPEDIR%/v%FULLVERSION%/node-v%FULLVERSION%-%target_arch%.msi.done nodejs/%DISTTYPEDIR%/v%FULLVERSION%/%TARGET_NAME%.zip.done nodejs/%DISTTYPEDIR%/v%FULLVERSION%/%TARGET_NAME%.7z.done nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%.done && chmod -R ug=rw-x+X,o=r+X nodejs/%DISTTYPEDIR%/v%FULLVERSION%/node-v%FULLVERSION%-%target_arch%.* nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%*"
577if errorlevel 1 goto exit
578
579
580:install-doctools
581REM only install if building doc OR testing doctool OR building addons
582if not defined doc if not defined build_addons (
583  echo.%test_args% | findstr doctool 1>nul
584  if errorlevel 1 goto :skip-install-doctools
585)
586if exist "tools\doc\node_modules\unified\package.json" goto skip-install-doctools
587SETLOCAL
588cd tools\doc
589%npm_exe% ci
590cd ..\..
591if errorlevel 1 goto exit
592ENDLOCAL
593:skip-install-doctools
594@rem Clear errorlevel from echo.%test_args% | findstr doctool 1>nul
595cd .
596
597:build-doc
598@rem Build documentation if requested
599if not defined doc goto run
600if not exist %node_exe% (
601  echo Failed to find node.exe
602  goto run
603)
604mkdir %config%\doc
605robocopy /e doc\api %config%\doc\api
606robocopy /e doc\api_assets %config%\doc\api\assets
607
608for %%F in (%config%\doc\api\*.md) do (
609  %node_exe% tools\doc\generate.mjs --node-version=v%FULLVERSION% %%F --output-directory=%%~dF%%~pF
610)
611
612:run
613@rem Run tests if requested.
614
615if not defined build_addons goto build-js-native-api-tests
616if not exist "%node_exe%" (
617  echo Failed to find node.exe
618  goto build-js-native-api-tests
619)
620echo Building addons
621:: clear
622for /d %%F in (test\addons\??_*) do (
623  rd /s /q %%F
624)
625:: generate
626"%node_exe%" tools\doc\addon-verify.mjs
627if %errorlevel% neq 0 exit /b %errorlevel%
628:: building addons
629setlocal
630set npm_config_nodedir=%~dp0
631"%node_exe%" "%~dp0tools\build-addons.mjs" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\addons"
632if errorlevel 1 exit /b 1
633endlocal
634
635:build-js-native-api-tests
636if not defined build_js_native_api_tests goto build-node-api-tests
637if not exist "%node_exe%" (
638  echo Failed to find node.exe
639  goto build-node-api-tests
640)
641echo Building js-native-api
642:: clear
643for /d %%F in (test\js-native-api\??_*) do (
644  rd /s /q %%F
645)
646:: building js-native-api
647setlocal
648set npm_config_nodedir=%~dp0
649"%node_exe%" "%~dp0tools\build-addons.mjs" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\js-native-api"
650if errorlevel 1 exit /b 1
651endlocal
652goto build-node-api-tests
653
654:build-node-api-tests
655if not defined build_node_api_tests goto run-tests
656if not exist "%node_exe%" (
657  echo Failed to find node.exe
658  goto run-tests
659)
660echo Building node-api
661:: clear
662for /d %%F in (test\node-api\??_*) do (
663  rd /s /q %%F
664)
665:: building node-api
666setlocal
667set npm_config_nodedir=%~dp0
668"%node_exe%" "%~dp0tools\build-addons.mjs" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\node-api"
669if errorlevel 1 exit /b 1
670endlocal
671goto run-tests
672
673:run-tests
674if defined test_check_deopts goto node-check-deopts
675if defined test_node_inspect goto node-test-inspect
676goto node-tests
677
678:node-check-deopts
679python tools\test.py --mode=release --check-deopts parallel sequential
680if defined test_node_inspect goto node-test-inspect
681goto node-tests
682
683:node-test-inspect
684set USE_EMBEDDED_NODE_INSPECT=1
685%node_exe% tools\test-npm-package.js --install deps\node-inspect test
686goto node-tests
687
688:node-tests
689if not defined test_npm goto no-test-npm
690set npm_test_cmd="%node_exe%" tools\test-npm-package.js --install --logfile=test-npm.tap deps\npm test-node
691echo %npm_test_cmd%
692%npm_test_cmd%
693if errorlevel 1 goto exit
694:no-test-npm
695
696if "%test_args%"=="" goto test-v8
697if "%config%"=="Debug" set test_args=--mode=debug %test_args%
698if "%config%"=="Release" set test_args=--mode=release %test_args%
699if defined no_cctest echo Skipping cctest because no-cctest was specified && goto run-test-py
700if not exist "%config%\cctest.exe" echo cctest.exe not found. Run "vcbuild test" or "vcbuild cctest" to build it. && goto run-test-py
701echo running 'cctest %cctest_args%'
702"%config%\cctest" %cctest_args%
703if %errorlevel% neq 0 set exit_code=%errorlevel%
704:run-test-py
705echo running 'python tools\test.py %test_args%'
706python tools\test.py %test_args%
707if %errorlevel% neq 0 set exit_code=%errorlevel%
708goto test-v8
709
710:test-v8
711if not defined custom_v8_test goto lint-cpp
712call tools/test-v8.bat
713if errorlevel 1 goto exit
714goto lint-cpp
715
716:lint-cpp
717if not defined lint_cpp goto lint-js
718if defined NODEJS_MAKE goto run-make-lint
719where make > NUL 2>&1 && make -v | findstr /C:"GNU Make" 1> NUL
720if "%ERRORLEVEL%"=="0" set "NODEJS_MAKE=make PYTHON=python" & goto run-make-lint
721where wsl > NUL 2>&1
722if "%ERRORLEVEL%"=="0" set "NODEJS_MAKE=wsl make" & goto run-make-lint
723echo Could not find GNU Make, needed for linting C/C++
724goto lint-js
725
726:run-make-lint
727%NODEJS_MAKE% lint-cpp
728goto lint-js
729
730:lint-js
731if not defined lint_js goto lint-md-build
732if not exist tools\node_modules\eslint goto no-lint
733echo running lint-js
734%node_exe% tools\node_modules\eslint\bin\eslint.js --cache --max-warnings=0 --report-unused-disable-directives --rule "linebreak-style: 0" .eslintrc.js benchmark doc lib test tools
735goto lint-md-build
736
737:no-lint
738echo Linting is not available through the source tarball.
739echo Use the git repo instead: $ git clone https://github.com/nodejs/node.git
740goto lint-md-build
741
742:lint-md-build
743if not defined lint_md_build goto lint-md
744echo "Deprecated no-op target 'lint_md_build'"
745goto lint-md
746
747:lint-md
748if not defined lint_md goto exit
749echo Running Markdown linter on docs...
750SETLOCAL ENABLEDELAYEDEXPANSION
751set lint_md_files=
752for /D %%D IN (doc\*) do (
753  for %%F IN (%%D\*.md) do (
754    set "lint_md_files="%%F" !lint_md_files!"
755  )
756)
757%node_exe% tools\lint-md\lint-md.mjs %lint_md_files%
758ENDLOCAL
759goto exit
760
761:format-md
762if not defined lint_md goto exit
763echo Running Markdown formatter on docs...
764SETLOCAL ENABLEDELAYEDEXPANSION
765set lint_md_files=
766for /D %%D IN (doc\*) do (
767  for %%F IN (%%D\*.md) do (
768    set "lint_md_files="%%F" !lint_md_files!"
769  )
770)
771%node_exe% tools\lint-md\lint-md.mjs --format %lint_md_files%
772ENDLOCAL
773goto exit
774
775:create-msvs-files-failed
776echo Failed to create vc project files.
777del .used_configure_flags
778set exit_code=1
779goto exit
780
781:help
782echo vcbuild.bat [debug/release] [msi] [doc] [test/test-all/test-addons/test-doc/test-js-native-api/test-node-api/test-benchmark/test-internet/test-pummel/test-simple/test-message/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-async-hooks/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [ignore-flaky] [static/dll] [noprojgen] [projgen] [small-icu/full-icu/without-intl] [nobuild] [nosnapshot] [nonpm] [nocorepack] [noetw] [ltcg] [licensetf] [sign] [ia32/x86/x64/arm64] [vs2019/vs2022] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-md] [lint-md-build] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [cctest] [no-cctest] [openssl-no-asm]
783echo Examples:
784echo   vcbuild.bat                          : builds release build
785echo   vcbuild.bat debug                    : builds debug build
786echo   vcbuild.bat release msi              : builds release build and MSI installer package
787echo   vcbuild.bat test                     : builds debug build and runs tests
788echo   vcbuild.bat build-release            : builds the release distribution as used by nodejs.org
789echo   vcbuild.bat enable-vtune             : builds Node.js with Intel VTune profiling support to profile JavaScript
790echo   vcbuild.bat link-module my_module.js : bundles my_module as built-in module
791echo   vcbuild.bat lint                     : runs the C++, documentation and JavaScript linter
792echo   vcbuild.bat no-cctest                : skip building cctest.exe
793goto exit
794
795:exit
796if %errorlevel% neq 0 exit /b %errorlevel%
797exit /b %exit_code%
798
799
800rem ***************
801rem   Subroutines
802rem ***************
803
804:getnodeversion
805set NODE_VERSION=
806set TAG=
807set FULLVERSION=
808
809for /F "usebackq tokens=*" %%i in (`python "%~dp0tools\getnodeversion.py"`) do set NODE_VERSION=%%i
810if not defined NODE_VERSION (
811  echo Cannot determine current version of Node.js
812  exit /b 1
813)
814
815if not defined DISTTYPE set DISTTYPE=release
816if "%DISTTYPE%"=="release" (
817  set FULLVERSION=%NODE_VERSION%
818  goto distexit
819)
820if "%DISTTYPE%"=="custom" (
821  if not defined CUSTOMTAG (
822    echo "CUSTOMTAG is not set for DISTTYPE=custom"
823    exit /b 1
824  )
825  set TAG=%CUSTOMTAG%
826)
827if not "%DISTTYPE%"=="custom" (
828  if not defined DATESTRING (
829    echo "DATESTRING is not set for nightly"
830    exit /b 1
831  )
832  if not defined COMMIT (
833    echo "COMMIT is not set for nightly"
834    exit /b 1
835  )
836  if not "%DISTTYPE%"=="nightly" (
837    if not "%DISTTYPE%"=="next-nightly" (
838      echo "DISTTYPE is not release, custom, nightly or next-nightly"
839      exit /b 1
840    )
841  )
842  set TAG=%DISTTYPE%%DATESTRING%%COMMIT%
843)
844set FULLVERSION=%NODE_VERSION%-%TAG%
845
846:distexit
847if not defined DISTTYPEDIR set DISTTYPEDIR=%DISTTYPE%
848set TARGET_NAME=node-v%FULLVERSION%-win-%target_arch%
849goto :EOF
850