Skip to content

Commit 9548dc7

Browse files
committed
Add Windows ARM64 support
* Adds CMake presets for the MSVC ARM64 toolchain. * Updates setup.py to detect and configure for the ARM64 architecture. * Makes warnings-as-errors optional to handle platform-specific warnings. * Adjusts ci.py to recognize the new platform.
1 parent f350d2c commit 9548dc7

File tree

7 files changed

+86
-12
lines changed

7 files changed

+86
-12
lines changed

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ black . --line-length 100
8282

8383
## Development Tips
8484

85-
- The project uses CMake with presets for different platforms (windows-msvc, linux-gcc, macos-arm64-clang)
85+
- The project uses CMake with presets for different platforms (windows-msvc, windows-arm64-msvc, linux-gcc, macos-arm64-clang)
8686
- PyTorch integration is automatic when PyTorch is installed
8787
- Hot-reload is supported for shader development
8888
- Use `python tools/ci.py` for most build/test tasks - it handles platform-specific configuration

CMakePresets.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,40 @@
9191
"windows-clang-base"
9292
]
9393
},
94+
{
95+
"name": "windows-arm64-base",
96+
"description": "Base Windows ARM64 configuration.",
97+
"hidden": true,
98+
"inherits": "windows-base",
99+
"cacheVariables": {
100+
"VCPKG_TARGET_TRIPLET": "arm64-windows-static-md-fix"
101+
}
102+
},
103+
{
104+
"name": "windows-arm64-msvc-base",
105+
"description": "Base Visual Studio 2022 ARM64 configuration.",
106+
"hidden": true,
107+
"inherits": "windows-arm64-base",
108+
"generator": "Ninja Multi-Config",
109+
"architecture": {
110+
"value": "ARM64",
111+
"strategy": "external"
112+
},
113+
"cacheVariables": {
114+
"CMAKE_C_COMPILER": "cl",
115+
"CMAKE_CXX_COMPILER": "cl"
116+
}
117+
},
118+
{
119+
"name": "windows-arm64-msvc",
120+
"inherits": [
121+
"windows-arm64-msvc-base"
122+
],
123+
"cacheVariables": {
124+
"CMAKE_CXX_FLAGS": "/EHsc",
125+
"SGL_WARNINGS_AS_ERRORS": "OFF"
126+
}
127+
},
94128
{
95129
"name": "linux-base",
96130
"description": "Base Linux configuration.",
@@ -190,6 +224,18 @@
190224
"configurePreset": "windows-clang",
191225
"configuration": "Debug"
192226
},
227+
{
228+
"name": "windows-arm64-msvc-release",
229+
"displayName": "Release",
230+
"configurePreset": "windows-arm64-msvc",
231+
"configuration": "Release"
232+
},
233+
{
234+
"name": "windows-arm64-msvc-debug",
235+
"displayName": "Debug",
236+
"configurePreset": "windows-arm64-msvc",
237+
"configuration": "Debug"
238+
},
193239
{
194240
"name": "linux-clang-release",
195241
"displayName": "Release",

external/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ if(SGL_WINDOWS)
118118
sgl_copy_binary(${SLANG_DIR}/bin/slang.dll .)
119119
sgl_copy_binary(${SLANG_DIR}/bin/slang-glslang.dll .)
120120
sgl_copy_binary(${SLANG_DIR}/bin/slang-glsl-module.dll .)
121-
sgl_copy_binary(${SLANG_DIR}/bin/slang-llvm.dll .)
121+
# slang-llvm.dll is available in x64 prebuilt packages but not in ARM64 packages.
122+
# Use conditional copy to support both architectures.
123+
if(EXISTS ${SLANG_DIR}/bin/slang-llvm.dll)
124+
sgl_copy_binary(${SLANG_DIR}/bin/slang-llvm.dll .)
125+
endif()
122126
sgl_copy_binary(${SLANG_DIR}/bin/slang-rt.dll .)
123127
elseif(SGL_LINUX)
124128
add_library(slang SHARED IMPORTED GLOBAL)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set(VCPKG_TARGET_ARCHITECTURE arm64)
2+
set(VCPKG_CRT_LINKAGE dynamic)
3+
set(VCPKG_LIBRARY_LINKAGE static)
4+
# _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR avoids the use of constexpr mutex constructor
5+
# in vcpkg packages, which can lead to binary incompatibility issues.
6+
set(VCPKG_C_FLAGS "-D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR")
7+
set(VCPKG_CXX_FLAGS "-D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR")

setup.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from __future__ import print_function
66

7-
import sys, re, os, subprocess, shutil
7+
import sys, re, os, subprocess, shutil, platform
88
from pathlib import Path
99

1010
try:
@@ -31,11 +31,24 @@
3131
else:
3232
raise Exception(f"Unsupported platform: {sys.platform}")
3333

34-
CMAKE_PRESET = {
35-
"windows": "windows-msvc",
36-
"linux": "linux-gcc",
37-
"macos": "macos-arm64-clang",
38-
}[PLATFORM]
34+
# Detect architecture for platform-specific CMake presets
35+
if PLATFORM == "windows":
36+
python_arch = platform.machine().lower()
37+
is_arm64 = python_arch in ("arm64", "aarch64")
38+
if is_arm64:
39+
CMAKE_PRESET = "windows-arm64-msvc"
40+
MSVC_PLAT_SPEC = "x86_arm64"
41+
else:
42+
CMAKE_PRESET = "windows-msvc"
43+
MSVC_PLAT_SPEC = "x64"
44+
elif PLATFORM == "linux":
45+
CMAKE_PRESET = "linux-gcc"
46+
MSVC_PLAT_SPEC = None
47+
elif PLATFORM == "macos":
48+
CMAKE_PRESET = "macos-arm64-clang"
49+
MSVC_PLAT_SPEC = None
50+
else:
51+
raise RuntimeError(f"Unsupported platform: {PLATFORM}")
3952

4053
CMAKE_CONFIG = "RelWithDebInfo"
4154

@@ -67,7 +80,7 @@ def build_extension(self, ext: CMakeExtension) -> None:
6780
sys.path.append(str(Path(__file__).parent / "tools"))
6881
import msvc # type: ignore
6982

70-
env = msvc.msvc14_get_vc_env("x64")
83+
env = msvc.msvc14_get_vc_env(MSVC_PLAT_SPEC)
7184

7285
build_dir = str(SOURCE_DIR / "build/pip")
7386

src/sgl/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
add_library(sgl SHARED)
33

4+
option(SGL_WARNINGS_AS_ERRORS "Treat compiler warnings as errors" ON)
5+
46
target_sources(sgl PRIVATE
57
sgl.natvis
68

@@ -193,7 +195,7 @@ target_compile_options(sgl
193195
/MP # enable multi-processor compilation
194196
/Zi # generate debug symbols
195197
# Configure warnings
196-
/WX # warnings as errors
198+
$<$<BOOL:${SGL_WARNINGS_AS_ERRORS}>:/WX> # warnings as errors
197199
/W4 # increase warning level
198200
/wd4251 # 'type' : class 'type1' needs to have dll-interface to be used by clients of class 'type2'
199201
/wd4201 # nonstandard extension used: nameless struct/union
@@ -214,7 +216,7 @@ target_compile_options(sgl
214216
-fvisibility=hidden # hide symbols by default
215217
-Wall # set warning level
216218
-Wextra # enable extra warnings
217-
-Werror # treat warnings as errors
219+
$<$<BOOL:${SGL_WARNINGS_AS_ERRORS}>:-Werror> # treat warnings as errors
218220
-Wno-unused-function
219221
-Wno-unused-variable
220222
-Wno-unused-but-set-variable

tools/ci.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_platform():
3838
machine = platform.machine()
3939
if machine == "x86_64" or machine == "AMD64":
4040
return "x86_64"
41-
elif machine == "aarch64" or machine == "arm64":
41+
elif machine == "aarch64" or machine == "arm64" or machine == "ARM64":
4242
return "aarch64"
4343
else:
4444
raise NameError(f"Unsupported platform: {machine}")
@@ -316,6 +316,8 @@ def main():
316316
preset = preset.replace("macos", "macos-x64")
317317
elif args["platform"] == "aarch64":
318318
preset = preset.replace("macos", "macos-arm64")
319+
elif args["os"] == "windows" and args["platform"] == "aarch64":
320+
preset = "windows-arm64-" + args["compiler"]
319321
args["preset"] = preset
320322

321323
# Determine binary directory.

0 commit comments

Comments
 (0)