Skip to content

Commit 339ee78

Browse files
committed
win-arm64-vulkan build
1 parent 8648a4f commit 339ee78

8 files changed

Lines changed: 61 additions & 18 deletions

File tree

cmake/arm64-windows-llvm.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
set( CMAKE_SYSTEM_NAME Windows )
2+
set( CMAKE_SYSTEM_PROCESSOR arm64 )
3+
4+
set( target arm64-pc-windows-msvc )
5+
6+
set( CMAKE_C_COMPILER_TARGET ${target} )
7+
set( CMAKE_CXX_COMPILER_TARGET ${target} )
8+
9+
set( arch_c_flags "-march=armv8.7-a -fvectorize -ffp-model=fast -fno-finite-math-only" )
10+
set( warn_c_flags "-Wno-format -Wno-unused-variable -Wno-unused-function -Wno-gnu-zero-variadic-macro-arguments" )
11+
12+
set( CMAKE_C_FLAGS_INIT "${arch_c_flags} ${warn_c_flags}" )
13+
set( CMAKE_CXX_FLAGS_INIT "${arch_c_flags} ${warn_c_flags}" )

cmake/x64-windows-llvm.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set( CMAKE_SYSTEM_NAME Windows )
2+
set( CMAKE_SYSTEM_PROCESSOR x86_64 )

scripts/build/common.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,20 +210,22 @@ def build_project(
210210
if not variants:
211211
variants = [{"name": "any", "compile_flags": []}]
212212

213+
# Get target for "any" variant to use for additional files
214+
target_any = get_target(get_platform_name_func, "any", arch)
215+
213216
# Get environment for cmake
214-
env = get_env_func() if get_env_func else None
217+
env = get_env_func(target_any) if get_env_func else None
215218

216219
# Build for each variant
217220
for variant in variants:
218221
variant_name = variant["name"]
219222
variant_compile_flags = variant.get("compile_flags", [])
220223

221224
target = get_target(get_platform_name_func, variant_name, arch)
222-
target_any = get_target(get_platform_name_func, "any", arch)
223225
project_root, build_dir = prepare_build(target, check_func)
224226

225227
# Combine base compile flags with variant-specific flags
226-
base_options = get_compile_flags_func()
228+
base_options = get_compile_flags_func(target_any)
227229
options = base_options + variant_compile_flags
228230

229231
# Resolve additional files if available

scripts/build/platform_cpu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def check_environment():
44
return True
55

66

7-
def get_compile_flags():
7+
def get_compile_flags(target_any):
88
"""Get compile flags for CPU."""
99
return []
1010

scripts/build/platform_cuda.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def check_environment():
1919
return False
2020

2121

22-
def get_compile_flags():
22+
def get_compile_flags(target_any):
2323
"""Get compile flags for CUDA."""
2424
return ["-DSD_CUDA=ON"]
2525

scripts/build/platform_metal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def check_environment():
1010
return False
1111

1212

13-
def get_compile_flags():
13+
def get_compile_flags(target_any):
1414
"""Get compile flags for Metal."""
1515
return ["-DSD_METAL=ON", "-DGGML_ACCELERATE=ON", "-DGGML_AVX2=ON", "-DCMAKE_OSX_ARCHITECTURES=arm64"]
1616

scripts/build/platform_vulkan.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
import platform
2+
import re
33
import subprocess
44

55

@@ -16,11 +16,36 @@ def check_environment():
1616
return False
1717

1818

19-
def get_compile_flags():
19+
def get_compile_flags(target_any):
2020
"""Get compile flags for Vulkan."""
21-
return ["-DSD_VULKAN=ON"]
21+
flags = ["-DSD_VULKAN=ON"]
22+
23+
if target_any.startswith("win-arm64"):
24+
vulkan_sdk_path = os.environ["VULKAN_SDK"].replace("\\", "/")
25+
26+
flags.append("-G Ninja")
27+
flags.append("-DCMAKE_TOOLCHAIN_FILE=cmake/arm64-windows-llvm.cmake")
28+
flags.append(f"-DVulkan_LIBRARY={vulkan_sdk_path}/Lib-ARM64/vulkan-1.lib")
29+
30+
return flags
2231

2332

2433
def get_platform_name():
2534
"""Get platform name for Vulkan."""
2635
return "vulkan"
36+
37+
38+
def get_env(target_any):
39+
"""Get environment variables for Vulkan build."""
40+
if target_any.startswith("win-arm64"):
41+
env = os.environ.copy()
42+
43+
print(env["PATH"])
44+
# Prevent ggml-vulkan's cmake from picking up MSVC tools
45+
env["PATH"] = re.sub(r"Tools\\MSVC\\[\d\.]+\\bin\\Hostx64\\x64", r"Tools\\Llvm\\x64\\bin", env["PATH"])
46+
47+
print("env", env["PATH"])
48+
49+
return env
50+
51+
return None

scripts/build_all.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66

77
BUILD_PLATFORMS = {
88
"Windows": [
9-
"cpu",
10-
"cuda",
11-
"vulkan",
9+
("cpu", "x64"),
10+
("cuda", "x64"),
11+
("vulkan", "x64"),
12+
("vulkan", "arm64"),
1213
],
1314
"Linux": [
14-
"cpu",
15-
"cuda",
16-
"vulkan",
15+
("cpu", "x64"),
16+
("cuda", "x64"),
17+
("vulkan", "x64"),
1718
],
1819
"Darwin": [
19-
"metal",
20+
("metal", "arm64"),
2021
],
2122
}
2223

@@ -26,8 +27,8 @@
2627

2728

2829
def main():
29-
for platform_name in platforms:
30-
cmd = [sys.executable, "-m", "scripts.build", "--platform", platform_name]
30+
for platform_name, arch in platforms:
31+
cmd = [sys.executable, "-m", "scripts.build", "--platform", platform_name, "--arch", arch]
3132

3233
print(f"Running build script: {cmd}")
3334
result = subprocess.run(cmd)

0 commit comments

Comments
 (0)