From 2618b053148bd3827f3eb05db07f6b69cf249bbc Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Mon, 1 Jul 2024 09:25:21 -0700 Subject: [PATCH] Fix building with MSVC 14.4 --- .github/workflows/build.yml | 12 ++++++------ bfg9000/backends/msbuild/syntax.py | 21 +++++++++++++++++---- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4d8f371f..fb360baa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,7 @@ jobs: include: - {os: ubuntu-latest, extra-tests: [mingw-cross], backends: [ninja, make], flags: -Wall -Werror} - - {os: windows-latest, msvc-version: '14.3', win-sdk: '10.0.20348.0', + - {os: windows-latest, msvc-version: '14.4', win-sdk: '10.0.20348.0', boost-version: '1.80.0', qt-version: '5.15.2', skipped-tests: [fortran, objc, scala], backends: [ninja, make, msbuild], flags: /WX} @@ -66,13 +66,13 @@ jobs: # VS 2022 x86 builds - {os: windows-latest, python-version: '3.11', compiler: default-x86, - msvc-version: '14.3', msvc-arch: 'x86', win-sdk: '10.0.20348.0', + msvc-version: '14.4', msvc-arch: 'x86', win-sdk: '10.0.20348.0', boost-version: '1.80.0', skipped-tests: [fortran, objc, qt, scala], backends: [ninja, make, msbuild], flags: /WX} # VS 2022 clang-cl builds - {os: windows-latest, python-version: '3.11', compiler: clang-cl, - msvc-version: '14.3', win-sdk: '10.0.20348.0', + msvc-version: '14.4', win-sdk: '10.0.20348.0', boost-version: '1.80.0', qt-version: '5.15.2', skipped-tests: [boost, fortran, objc, scala], backends: [ninja, make], flags: /WX -Wno-microsoft-include @@ -80,7 +80,7 @@ jobs: # MinGW builds - {os: windows-latest, python-version: '3.11', compiler: mingw, - msvc-version: '14.3', win-sdk: '10.0.20348.0', + msvc-version: '14.4', win-sdk: '10.0.20348.0', qt-version: '5.15.2', qt-arch: 'win64_mingw81', skipped-tests: [boost, fortran, objc, pch, scala], backends: [ninja, make], flags: -Wall -Werror} @@ -133,7 +133,7 @@ jobs: if: startsWith(matrix.os, 'windows-') && matrix.boost-version run: | ${boostroot} = "C:\boost-${{ matrix.boost-version }}" - ${msvcver} = "${{ matrix.msvc-version }}" -replace '(\d+\.\d).*','$1' + ${msvcver} = "${{ matrix.msvc-version }}" -replace '14.4','14.3' ${arch} = if ("${{ matrix.msvc-arch }}" -eq "x86") {"32"} else {"64"} if ("${{ steps.cache-boost.outputs.cache-hit }}" -ne "true" ) { ${boost_ver} = "${{ matrix.boost-version }}" -replace '\.','_' @@ -190,7 +190,7 @@ jobs: 7z x -y libogg-1.3.5.zip ${arch} = "${{ matrix.msvc-arch || 'x64' }}" if(${arch} -eq 'x86') { ${arch} = "Win32" } - ${toolset} = "${{ matrix.msvc-version }}" -replace '(\d+)\.(\d).*','$1$2' + ${toolset} = "${{ matrix.msvc-version }}" -replace '14.4','14.3' -replace '(\d+)\.(\d+).*','$1$2' msbuild libogg-1.3.5\win32\VS2015\libogg.sln /p:Configuration=ReleaseDLL /p:Platform=${arch} /p:PlatformToolset=v${toolset} /p:WindowsTargetPlatformVersion=${{ matrix.win-sdk }} mkdir lib ${liboggbase} = "libogg-1.3.5\win32\VS2015\${arch}\ReleaseDLL" diff --git a/bfg9000/backends/msbuild/syntax.py b/bfg9000/backends/msbuild/syntax.py index 6f7c70b5..76190f5d 100644 --- a/bfg9000/backends/msbuild/syntax.py +++ b/bfg9000/backends/msbuild/syntax.py @@ -1,5 +1,6 @@ import ntpath import os +import re from collections import defaultdict from enum import Enum from itertools import chain @@ -170,6 +171,12 @@ class VcxProject(Project): 'dynamic-debug': 'MultiThreadedDebugDLL', } + # By default, toolsets map the compiler version from MM.N to vMMN, but 14.4 + # breaks that convention. + _toolsets = { + '14.4': 'v143', + } + def __init__(self, env, name, mode='Application', configuration=None, output_file=None, files=None, objs=None, compile_options=None, link_options=None, dependencies=None): @@ -181,11 +188,17 @@ def __init__(self, env, name, mode='Application', configuration=None, self.compile_options = compile_options or {} self.link_options = link_options or {} - version = env.getvar( - 'VSCMD_ARG_VCVARS_VER', - env.getvar('VCTOOLSVERSION', self.version) + version = env.getvar('VSCMD_ARG_VCVARS_VER') + if version is None: + m = re.match('(\d+\.\d)', env.getvar('VCTOOLSVERSION', + self.version)) + if not m: + raise ValueError('unable to guess toolset version; ' + + 'run from a Visual Studio prompt?') + version = m.group(1) + self.toolset = self._toolsets.get( + version, 'v' + version.replace('.', '') ) - self.toolset = 'v' + version.replace('.', '')[0:3] self.windows_sdk = (env.getvar('WINDOWSSDKVERSION', '') .replace('\\', '') or None)