From 0e35ab812d890fb75cf89a19ea72bc93dd6ba186 Mon Sep 17 00:00:00 2001 From: tr-takatsuka Date: Wed, 18 Oct 2023 20:39:07 +0900 Subject: [PATCH] feat: add VCToolsVersion for msvs (#209) * Add the ability to specify the 'MSVC toolset version' for the VisualStudio platform. Usage example for binding.gyp ``` 'targets': [ { 'configurations': { 'Debug': { "msvs_configuration_attributes": { "VCToolsVersion": "14.36.32532", ``` * chore: update build-windows runs-on to windows-latest extract from comments by PR #209:add VCToolsVersion for msvs ``` The Node.js Windows integration / build-windows workflow runs on windows-2019 which from what I know uses VS2019. However, after this landed in Node.js, it no longer supports building on VS2019 and requires VS2022. Luckily for us, fix should be as simple as changing the line I referenced in a workflow file to windows-2022 or even simpler to windows-latest. ``` --- .github/workflows/nodejs-windows.yml | 2 +- pylib/gyp/easy_xml_test.py | 4 +++- pylib/gyp/generator/msvs.py | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nodejs-windows.yml b/.github/workflows/nodejs-windows.yml index 4e6c9548..bfbfb9f1 100644 --- a/.github/workflows/nodejs-windows.yml +++ b/.github/workflows/nodejs-windows.yml @@ -9,7 +9,7 @@ on: jobs: build-windows: - runs-on: windows-2019 + runs-on: windows-latest steps: - name: Clone gyp-next uses: actions/checkout@v3 diff --git a/pylib/gyp/easy_xml_test.py b/pylib/gyp/easy_xml_test.py index c5808b84..2d9b1521 100755 --- a/pylib/gyp/easy_xml_test.py +++ b/pylib/gyp/easy_xml_test.py @@ -77,6 +77,7 @@ def test_EasyXml_complex(self): "Application" "Unicode" "SpectreLoadCF" + "14.36.32532" "" "" ) @@ -100,7 +101,8 @@ def test_EasyXml_complex(self): }, ["ConfigurationType", "Application"], ["CharacterSet", "Unicode"], - ["SpectreMitigation", "SpectreLoadCF"] + ["SpectreMitigation", "SpectreLoadCF"], + ["VCToolsVersion", "14.36.32532"], ], ] ) diff --git a/pylib/gyp/generator/msvs.py b/pylib/gyp/generator/msvs.py index 0e7ec4d9..1f9e2497 100644 --- a/pylib/gyp/generator/msvs.py +++ b/pylib/gyp/generator/msvs.py @@ -3004,6 +3004,7 @@ def _GetMSBuildConfigurationDetails(spec, build_file): msbuild_attributes = _GetMSBuildAttributes(spec, settings, build_file) condition = _GetConfigurationCondition(name, settings, spec) character_set = msbuild_attributes.get("CharacterSet") + vctools_version = msbuild_attributes.get("VCToolsVersion") config_type = msbuild_attributes.get("ConfigurationType") _AddConditionalProperty(properties, condition, "ConfigurationType", config_type) spectre_mitigation = msbuild_attributes.get('SpectreMitigation') @@ -3019,6 +3020,10 @@ def _GetMSBuildConfigurationDetails(spec, build_file): _AddConditionalProperty( properties, condition, "CharacterSet", character_set ) + if vctools_version and "msvs_enable_winrt" not in spec: + _AddConditionalProperty( + properties, condition, "VCToolsVersion", vctools_version + ) return _GetMSBuildPropertyGroup(spec, "Configuration", properties) @@ -3100,6 +3105,8 @@ def _ConvertMSVSBuildAttributes(spec, config, build_file): msbuild_attributes[a] = _ConvertMSVSConfigurationType(msvs_attributes[a]) elif a == "SpectreMitigation": msbuild_attributes[a] = msvs_attributes[a] + elif a == "VCToolsVersion": + msbuild_attributes[a] = msvs_attributes[a] else: print("Warning: Do not know how to convert MSVS attribute " + a) return msbuild_attributes