mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-06 09:18:36 +01:00
build Windows with clang-cl instead of MSVC
clang-cl keeps the MSVC ABI, so the Windows SDK, the vcpkg packages and D3D12 all still link; only the front end changes. That front end is the one whose module support has been giving way - global module fragment merging and type completeness at a template's instantiation point. Switches the job to Ninja, which is where CMake's module scanning is best supported, with vcvars64 for the SDK paths. Ninja is single-config, so the artifacts move from build/bin/<config>/ to build/bin/. CMakeLists: the MSVC-only blocks tested CMAKE_CXX_COMPILER_ID, which clang-cl reports as Clang, so the version resource, the icon and /utf-8 would have been dropped silently. They test MSVC now, which is true for both. /MAP and /MP stay behind a real-MSVC check - the first is a link.exe spelling, the second clang-cl rejects.
This commit is contained in:
59
.github/workflows/build_bin.yml
vendored
59
.github/workflows/build_bin.yml
vendored
@@ -24,11 +24,11 @@ env:
|
|||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# Windows / MSVC
|
# Windows / Clang (clang-cl)
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
windows:
|
windows:
|
||||||
name: Windows x64 / MSVC
|
name: Windows x64 / Clang
|
||||||
runs-on: windows-2022
|
runs-on: windows-2022
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -45,16 +45,27 @@ jobs:
|
|||||||
python-version: "3.14"
|
python-version: "3.14"
|
||||||
architecture: "x64"
|
architecture: "x64"
|
||||||
|
|
||||||
|
# clang-cl rather than plain clang: it keeps the MSVC ABI, so it links
|
||||||
|
# against the same Windows SDK, vcpkg packages and D3D12 libraries, and
|
||||||
|
# only the front end changes. Pinned to the version the Linux job uses.
|
||||||
|
- name: Install LLVM and Ninja
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
choco install llvm --version=22.1.8 -y --no-progress
|
||||||
|
choco install ninja -y --no-progress
|
||||||
|
|
||||||
- name: Show environment
|
- name: Show environment
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
python --version
|
python --version
|
||||||
cmake --version
|
cmake --version
|
||||||
|
ninja --version
|
||||||
|
& "$env:ProgramFiles\LLVM\bin\clang-cl.exe" --version
|
||||||
|
|
||||||
Write-Host "Python:"
|
Write-Host "Python:"
|
||||||
Get-Command python
|
Get-Command python
|
||||||
|
|
||||||
Write-Host "MSVC:"
|
Write-Host "Visual Studio (for the SDK and the MSVC STL):"
|
||||||
& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" `
|
& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" `
|
||||||
-latest `
|
-latest `
|
||||||
-products * `
|
-products * `
|
||||||
@@ -67,30 +78,32 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
call setup.bat
|
call setup.bat
|
||||||
|
|
||||||
|
# Ninja, not MSBuild: CMake's module dependency scanning is best supported
|
||||||
|
# there, and vcvars64 supplies the SDK and library paths clang-cl needs.
|
||||||
- name: Configure
|
- name: Configure
|
||||||
shell: pwsh
|
shell: cmd
|
||||||
run: |
|
run: |
|
||||||
$pythonExe = "${{ steps.python.outputs.python-path }}"
|
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set VSPATH=%%i
|
||||||
$pythonRoot = Split-Path $pythonExe
|
call "%VSPATH%\VC\Auxiliary\Build\vcvars64.bat"
|
||||||
|
for %%p in ("${{ steps.python.outputs.python-path }}") do set PYROOT=%%~dpp
|
||||||
Write-Host "Python root: $pythonRoot"
|
cmake -S . -B build ^
|
||||||
|
-G Ninja ^
|
||||||
cmake -S . -B build `
|
-DCMAKE_BUILD_TYPE=%CONFIG_WIN% ^
|
||||||
-G "Visual Studio 17 2022" `
|
-DCMAKE_C_COMPILER="%ProgramFiles%/LLVM/bin/clang-cl.exe" ^
|
||||||
-A x64 `
|
-DCMAKE_CXX_COMPILER="%ProgramFiles%/LLVM/bin/clang-cl.exe" ^
|
||||||
"-DPython3_ROOT_DIR=$pythonRoot"
|
-DPython3_ROOT_DIR=%PYROOT%
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: pwsh
|
shell: cmd
|
||||||
run: |
|
run: |
|
||||||
cmake --build build `
|
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set VSPATH=%%i
|
||||||
--config $env:CONFIG_WIN `
|
call "%VSPATH%\VC\Auxiliary\Build\vcvars64.bat"
|
||||||
--parallel
|
cmake --build build --parallel
|
||||||
|
|
||||||
- name: Copy shaders
|
- name: Copy shaders
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
$output = "build/bin/$env:CONFIG_WIN"
|
$output = "build/bin"
|
||||||
|
|
||||||
New-Item `
|
New-Item `
|
||||||
-ItemType Directory `
|
-ItemType Directory `
|
||||||
@@ -108,7 +121,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: maszyna-windows-x64-${{ env.CONFIG_WIN }}
|
name: maszyna-windows-x64-${{ env.CONFIG_WIN }}
|
||||||
path: |
|
path: |
|
||||||
build/bin/${{ env.CONFIG_WIN }}/
|
build/bin/
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
retention-days: 14
|
retention-days: 14
|
||||||
|
|
||||||
@@ -117,18 +130,18 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: maszyna-windows-x64-symbols-${{ env.CONFIG_WIN }}
|
name: maszyna-windows-x64-symbols-${{ env.CONFIG_WIN }}
|
||||||
path: |
|
path: |
|
||||||
build/pdb/${{ env.CONFIG_WIN }}/*.pdb
|
build/pdb/*.pdb
|
||||||
build/bin/${{ env.CONFIG_WIN }}/*.map
|
build/bin/*.map
|
||||||
if-no-files-found: warn
|
if-no-files-found: warn
|
||||||
retention-days: 14
|
retention-days: 14
|
||||||
|
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# Linux / GCC
|
# Linux / Clang
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
linux:
|
linux:
|
||||||
name: Linux x64 / GCC
|
name: Linux x64 / Clang
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMake_modules/")
|
|||||||
set(DEPS_DIR ${DEPS_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/ref")
|
set(DEPS_DIR ${DEPS_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/ref")
|
||||||
project("eu07")
|
project("eu07")
|
||||||
|
|
||||||
# Clang is the only compiler this project is built and tested with on Linux
|
# Clang is the compiler this project is built and tested with: clang on Linux,
|
||||||
# (Clang 22 in CI); MSVC covers Windows. GCC is not supported: its lazy loading
|
# clang-cl on Windows, both pinned to 22 in CI. MSVC still configures and is not
|
||||||
# of module interfaces is broken here, and working around it costs roughly twice
|
# rejected, but nothing verifies it. GCC is not supported: its lazy loading of
|
||||||
|
# module interfaces is broken here, and working around it costs roughly twice
|
||||||
# the memory per compiler process.
|
# the memory per compiler process.
|
||||||
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang|MSVC")
|
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang|MSVC")
|
||||||
message(FATAL_ERROR
|
message(FATAL_ERROR
|
||||||
@@ -444,7 +445,12 @@ set(GLM_INCLUDE_DIR ${GLM_INCLUDE_DIR} "${DEPS_DIR}/glm/")
|
|||||||
configure_file(${CMAKE_SOURCE_DIR}/eu07.rc.in
|
configure_file(${CMAKE_SOURCE_DIR}/eu07.rc.in
|
||||||
${CMAKE_BINARY_DIR}/eu07.rc @ONLY)
|
${CMAKE_BINARY_DIR}/eu07.rc @ONLY)
|
||||||
|
|
||||||
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
|
# MSVC is true for clang-cl as well - it targets the same ABI and takes the same
|
||||||
|
# command line. Testing CMAKE_CXX_COMPILER_ID instead would silently drop the
|
||||||
|
# version resource and the icon from a clang-cl build.
|
||||||
|
if (MSVC)
|
||||||
|
# the Visual Studio generators enable RC on their own; Ninja does not
|
||||||
|
enable_language(RC)
|
||||||
set(SOURCES ${SOURCES} ${CMAKE_BINARY_DIR}/eu07.rc)
|
set(SOURCES ${SOURCES} ${CMAKE_BINARY_DIR}/eu07.rc)
|
||||||
set(SOURCES ${SOURCES} eu07.ico)
|
set(SOURCES ${SOURCES} eu07.ico)
|
||||||
add_compile_options("/utf-8")
|
add_compile_options("/utf-8")
|
||||||
@@ -508,18 +514,23 @@ target_include_directories(${PROJECT_NAME} PRIVATE
|
|||||||
"${CMAKE_BINARY_DIR}/geninc"
|
"${CMAKE_BINARY_DIR}/geninc"
|
||||||
"${GLOBAL_INCLUDE_DIR}")
|
"${GLOBAL_INCLUDE_DIR}")
|
||||||
|
|
||||||
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
|
if (MSVC)
|
||||||
# override cmake defaults
|
# override cmake defaults
|
||||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO " /MD /Zi /O2 /DNDEBUG")
|
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO " /MD /Zi /O2 /DNDEBUG")
|
||||||
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO " /DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF")
|
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO " /DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF")
|
||||||
|
|
||||||
target_link_options(${PROJECT_NAME} PRIVATE "/MAP")
|
|
||||||
|
|
||||||
# /wd4996: disable "deprecation" warnings
|
# /wd4996: disable "deprecation" warnings
|
||||||
# /wd4244: disable warnings for conversion with possible loss of data
|
# /wd4244: disable warnings for conversion with possible loss of data
|
||||||
# /wd5033: disable because it is all over Python headers
|
# /wd5033: disable because it is all over Python headers
|
||||||
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/wd4996 /wd4244 /wd5033")
|
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/wd4996 /wd4244 /wd5033")
|
||||||
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/LARGEADDRESSAWARE")
|
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/LARGEADDRESSAWARE")
|
||||||
|
|
||||||
|
# /MAP is a link.exe option; lld-link, which clang-cl usually drives, spells
|
||||||
|
# it differently. The map only feeds the debug-symbols artifact, whose upload
|
||||||
|
# tolerates it being absent.
|
||||||
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||||
|
target_link_options(${PROJECT_NAME} PRIVATE "/MAP")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set_target_properties( ${PROJECT_NAME}
|
set_target_properties( ${PROJECT_NAME}
|
||||||
@@ -724,7 +735,9 @@ if(GENERATE_PDB)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(ENABLE_MCC AND MSVC)
|
# /MP is an MSVC-only option; clang-cl rejects it, and under Ninja the generator
|
||||||
|
# already runs one compiler process per core.
|
||||||
|
if(ENABLE_MCC AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND NOT CMAKE_GENERATOR MATCHES "Ninja")
|
||||||
message(STATUS "Enabling multi-processor compilation for MSVC.")
|
message(STATUS "Enabling multi-processor compilation for MSVC.")
|
||||||
add_compile_options(/MP)
|
add_compile_options(/MP)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
Reference in New Issue
Block a user