From 444920dc6338d031b0e2f268a95affd06190eb25 Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Fri, 7 Apr 2017 08:53:45 -0400 Subject: [PATCH] win: make buildable on VS2017 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Set default to `vs2015` since `vs2017` is not CI-green yet * changes vcbuild.bat arg from `vc2015` to `vs2015`/`vs2017` `vc` as in Visual C++ is actually versions 14.0 or 14.10 `vs` as in Visual Studio is 2015 or 2017 Ref: http://lists.boost.org/Archives/boost/2017/03/233597.php 🤦 * keep `vc2015` for backward compatibility but "undocumented" * tools: transplant vswhere wrapper from `msvs-com-helper` Ref: https://github.com/node4good/msvs-com-helper --- BUILDING.md | 4 ++- tools/msvs/vswhere_usability_wrapper.cmd | 20 +++++++++++ vcbuild.bat | 42 +++++++++++++++++++++--- 3 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 tools/msvs/vswhere_usability_wrapper.cmd diff --git a/BUILDING.md b/BUILDING.md index eb68b22370d87d..6adf3e5cda60d8 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -37,7 +37,7 @@ Support is divided into three tiers: |--------------|--------------|----------------------------------|----------------------|------------------| | GNU/Linux | Tier 1 | kernel >= 2.6.18, glibc >= 2.5 | x86, x64, arm, arm64 | | | macOS | Tier 1 | >= 10.10 | x64 | | -| Windows | Tier 1 | >= Windows 7 or >= Windows2008R2 | x86, x64 | | +| Windows | Tier 1 | >= Windows 7 / 2008 R2 | x86, x64 | vs2015 or vs2017 | | SmartOS | Tier 2 | >= 15 < 16.4 | x86, x64 | see note1 | | FreeBSD | Tier 2 | >= 10 | x64 | | | GNU/Linux | Tier 2 | kernel >= 3.13.0, glibc >= 2.19 | ppc64le >=power8 | | @@ -175,6 +175,8 @@ Prerequisites: * [Visual Studio 2015 Update 3](https://www.visualstudio.com/), all editions including the Community edition (remember to select "Common Tools for Visual C++ 2015" feature during installation). + * [Visual Studio 2017](https://www.visualstudio.com/downloads/), any edition (including the Build Tools SKU). + __Required Components:__ "MSbuild", "VC++ 2017 v141 toolset" and one of the Windows SDKs (10 or 8.1). * Basic Unix tools required for some tests, [Git for Windows](http://git-scm.com/download/win) includes Git Bash and tools which can be included in the global `PATH`. diff --git a/tools/msvs/vswhere_usability_wrapper.cmd b/tools/msvs/vswhere_usability_wrapper.cmd new file mode 100644 index 00000000000000..b5e5653ad6812e --- /dev/null +++ b/tools/msvs/vswhere_usability_wrapper.cmd @@ -0,0 +1,20 @@ +:: Copyright 2017 - Refael Ackermann +:: Distributed under MIT style license +:: See accompanying file LICENSE at https://github.com/node4good/windows-autoconf +:: version: 1.14.0 + +@if not defined DEBUG_HELPER @ECHO OFF +setlocal +set VSWHERE_REQ=-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 +set VSWHERE_PRP=-property installationPath +set VSWHERE_LMT=-version "[15.0,16.0)" +SET VSWHERE_ARGS=-latest -products * %VSWHERE_REQ% %VSWHERE_PRP% %VSWHERE_LMT% +set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer" +if not exist "%VSWHERE%" set "VSWHERE=%ProgramFiles%\Microsoft Visual Studio\Installer" +if not exist "%VSWHERE%" exit /B 1 +set Path=%Path%;%VSWHERE% +for /f "usebackq tokens=*" %%i in (`vswhere %VSWHERE_ARGS%`) do ( + endlocal + set "VCINSTALLDIR=%%i\VC\" + set "VS150COMNTOOLS=%%i\Common7\Tools\" + exit /B 0) diff --git a/vcbuild.bat b/vcbuild.bat index f0f68e64496145..ac2bf7f72ab53b 100644 --- a/vcbuild.bat +++ b/vcbuild.bat @@ -15,7 +15,7 @@ if /i "%1"=="/?" goto help set config=Release set target=Build set target_arch=x64 -set target_env= +set target_env=vs2015 set noprojgen= set nobuild= set sign= @@ -53,7 +53,10 @@ if /i "%1"=="clean" set target=Clean&goto arg-ok if /i "%1"=="ia32" set target_arch=x86&goto arg-ok if /i "%1"=="x86" set target_arch=x86&goto arg-ok if /i "%1"=="x64" set target_arch=x64&goto arg-ok -if /i "%1"=="vc2015" set target_env=vc2015&goto arg-ok +@rem args should be vs2017 and vs2015. keeping vc2015 for backward combatibility (undocumented) +if /i "%1"=="vc2015" set target_env=vs2015&goto arg-ok +if /i "%1"=="vs2015" set target_env=vs2015&goto arg-ok +if /i "%1"=="vs2017" set target_env=vs2017&goto arg-ok if /i "%1"=="noprojgen" set noprojgen=1&goto arg-ok 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 @@ -88,7 +91,7 @@ if /i "%1"=="upload" set upload=1&goto arg-ok if /i "%1"=="small-icu" set i18n_arg=%1&goto arg-ok if /i "%1"=="full-icu" set i18n_arg=%1&goto arg-ok if /i "%1"=="intl-none" set i18n_arg=%1&goto arg-ok -if /i "%1"=="without-intl" set i18n_arg=%1&goto arg-ok +if /i "%1"=="without-intl" set i18n_arg=%1&goto arg-ok if /i "%1"=="download-all" set download_arg="--download=all"&goto arg-ok if /i "%1"=="ignore-flaky" set test_args=%test_args% --flaky-tests=dontcare&goto arg-ok if /i "%1"=="enable-vtune" set enable_vtune_arg=1&goto arg-ok @@ -149,7 +152,33 @@ if defined noprojgen if defined nobuild if not defined sign if not defined msi g @rem Set environment for msbuild +set msvs_host_arch=x86 +if _%PROCESSOR_ARCHITECTURE%_==_AMD64_ set msvs_host_arch=amd64 +if _%PROCESSOR_ARCHITEW6432%_==_AMD64_ set msvs_host_arch=amd64 +@rem usualy vcvarsall takes an argument: host + '_' + target +set vcvarsall_arg=%msvs_host_arch%_%target_arch% +@rem unless both host and taget are x64 +if %target_arch%==x64 if %msvs_host_arch%==amd64 set vcvarsall_arg=amd64 + +@rem Look for Visual Studio 2017 +:vs-set-2017 +if "%target_env%" NEQ "vs2017" goto vs-set-2015 +echo Looking for Visual Studio 2017 +if "_%VSCMD_ARG_TGT_ARCH%_"=="_%target_arch%_" goto found_vs2017 +call tools\msvs\vswhere_usability_wrapper.cmd +if "_%VCINSTALLDIR%_" == "__" goto vs-set-2015 +set vcvars_call="%VCINSTALLDIR%\Auxiliary\Build\vcvarsall.bat" %vcvarsall_arg% +echo calling: %vcvars_call% +call %vcvars_call% +:found_vs2017 +echo Found MSVS version %VisualStudioVersion% +set GYP_MSVS_VERSION=2017 +set PLATFORM_TOOLSET=v141 +goto msbuild-found + @rem Look for Visual Studio 2015 +:vs-set-2015 +if "%target_env%" NEQ "vs2015" goto msbuild-not-found echo Looking for Visual Studio 2015 if not defined VS140COMNTOOLS goto msbuild-not-found if not exist "%VS140COMNTOOLS%\..\..\vc\vcvarsall.bat" goto msbuild-not-found @@ -172,7 +201,9 @@ set PLATFORM_TOOLSET=v140 goto msbuild-found :msbuild-not-found -echo Failed to find Visual Studio installation. +echo Failed to find a suitable Visual Studio installation. +echo Try to run in a "Developer Command Prompt" or consult +echo https://github.com/nodejs/node/blob/master/BUILDING.md#windows-1 goto exit :wix-not-found @@ -298,6 +329,7 @@ if not defined SSHCONFIG ( echo SSHCONFIG is not set for upload exit /b 1 ) + if not defined STAGINGSERVER set STAGINGSERVER=node-www ssh -F %SSHCONFIG% %STAGINGSERVER% "mkdir -p nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%" scp -F %SSHCONFIG% Release\node.exe %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%/node.exe @@ -455,7 +487,7 @@ echo Failed to create vc project files. goto exit :help -echo vcbuild.bat [debug/release] [msi] [test-all/test-uv/test-inspector/test-internet/test-pummel/test-simple/test-message] [clean] [noprojgen] [small-icu/full-icu/without-intl] [nobuild] [sign] [x86/x64] [vc2015] [download-all] [enable-vtune] [lint/lint-ci] [no-NODE-OPTIONS] +echo vcbuild.bat [debug/release] [msi] [test-all/test-uv/test-inspector/test-internet/test-pummel/test-simple/test-message] [clean] [noprojgen] [small-icu/full-icu/without-intl] [nobuild] [sign] [x86/x64] [vs2015/vs2017] [download-all] [enable-vtune] [lint/lint-ci] [no-NODE-OPTIONS] echo Examples: echo vcbuild.bat : builds release build echo vcbuild.bat debug : builds debug build