[client/common] windows: fix native clang-cl build

This commit is contained in:
Geoffrey McRae
2026-10-02 20:07:38 +10:00
parent ad0207afc5
commit 78b6a31e7d
5 changed files with 53 additions and 8 deletions

View File

@@ -42,6 +42,13 @@ if(LG_CLIENT_PLATFORM_WINDOWS AND MSVC AND
"C++; use the windows-clangcl configure preset")
endif()
if(LG_CLIENT_PLATFORM_WINDOWS AND MSVC AND
NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
message(FATAL_ERROR
"The native Windows client requires an x64 clang-cl target; remove the "
"existing build directory and use the windows-clangcl configure preset")
endif()
set(OPTIMIZE_FOR_NATIVE_DEFAULT ON)
include(OptimizeForNative) # option(OPTIMIZE_FOR_NATIVE)
include(UninstallTarget)

View File

@@ -19,8 +19,6 @@
"rhs": "Windows"
},
"cacheVariables": {
"CMAKE_C_COMPILER": "clang-cl",
"CMAKE_CXX_COMPILER": "clang-cl",
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreadedDLL",
"ENABLE_AUDIO": true,
@@ -28,6 +26,7 @@
"ENABLE_NETWORK": true,
"ENABLE_WASAPI": true,
"OPTIMIZE_FOR_NATIVE": "OFF",
"VCPKG_CHAINLOAD_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/windows-clangcl.cmake",
"VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/cmake/vcpkg-triplets",
"VCPKG_TARGET_TRIPLET": "x64-windows-lg"
}

View File

@@ -0,0 +1,28 @@
if(NOT DEFINED ENV{VSCMD_VER} OR
NOT "$ENV{VSCMD_ARG_TGT_ARCH}" MATCHES "^(x64|amd64)$" OR
NOT "$ENV{VSCMD_ARG_HOST_ARCH}" MATCHES "^(x64|amd64)$")
message(FATAL_ERROR
"The windows-clangcl preset requires the x64 Native Tools environment; "
"open an x64 Native Tools command prompt and configure again")
endif()
find_program(LG_WINDOWS_CLANG_CL
NAMES clang-cl
PATHS "$ENV{VCINSTALLDIR}/Tools/Llvm/x64/bin"
NO_DEFAULT_PATH
REQUIRED)
execute_process(
COMMAND "${LG_WINDOWS_CLANG_CL}" -print-target-triple
RESULT_VARIABLE LG_WINDOWS_CLANG_RESULT
OUTPUT_VARIABLE LG_WINDOWS_CLANG_TARGET
ERROR_VARIABLE LG_WINDOWS_CLANG_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT LG_WINDOWS_CLANG_RESULT EQUAL 0 OR
NOT LG_WINDOWS_CLANG_TARGET MATCHES "^x86_64-")
message(FATAL_ERROR
"The x64 Native Tools environment selected an invalid clang-cl: "
"${LG_WINDOWS_CLANG_ERROR}${LG_WINDOWS_CLANG_TARGET}")
endif()
set(CMAKE_C_COMPILER "${LG_WINDOWS_CLANG_CL}" CACHE FILEPATH "" FORCE)
set(CMAKE_CXX_COMPILER "${LG_WINDOWS_CLANG_CL}" CACHE FILEPATH "" FORCE)

View File

@@ -22,6 +22,7 @@
#include "common/win32.h"
#include <share.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -144,7 +145,7 @@ FILE * lgOpenFile(const char * path, const char * mode)
return NULL;
}
FILE * result = _wfopen(widePathValue, wideMode);
FILE * result = _wfsopen(widePathValue, wideMode, _SH_DENYNO);
free(widePathValue);
free(wideMode);
return result;

View File

@@ -4,8 +4,8 @@ Build the Windows client
########################
The Windows client uses ``clang-cl`` and the MSVC ABI. ANGLE continues to
provide EGL and OpenGL ES, while MsQuic and its bundled OpenSSL are linked
statically.
provide EGL and OpenGL ES, while MsQuic and the vcpkg-provided OpenSSL are
linked statically.
Requirements
------------
@@ -14,7 +14,7 @@ Install the following tools:
- Visual Studio 2022 Build Tools with the Desktop development with C++
workload, Clang tools for Windows, and a Windows SDK
- CMake 3.21 or newer
- CMake 3.24 or newer
- Ninja, with ``ninja.exe`` available on ``PATH``
- Git
- vcpkg
@@ -30,13 +30,23 @@ works before configuring the client.
Building
--------
Open an x64 Native Tools command prompt or Developer PowerShell, then run:
Open an x64 Native Tools command prompt. Alternatively, initialize a regular
PowerShell session for an x64 host and target first (replace ``Community``
with the installed Visual Studio edition when necessary):
.. code:: powershell
$vsTools = 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools'
& "$vsTools\Launch-VsDevShell.ps1" `
-Arch amd64 -HostArch amd64 -SkipAutomaticLocation
Then run:
.. code:: powershell
git submodule update --init --recursive
cd client
cmake --preset windows-clangcl
cmake --fresh --preset windows-clangcl
cmake --build --preset windows-clangcl-release
The executable is written beneath ``client/build/windows-clangcl``. The