Skip to content

Commit c04c3a5

Browse files
Prepare Windows HIP/ROCm builds for distribution releases (0xShug0#153)
* Harden Windows HIP build script for distribution builds - Add -NoNativeCpu: keep ggml CPU kernels off the build machine's native ISA. A distribution binary built with the default (native) can crash with 'illegal instruction' on older CPUs. - Add -DeploymentBuild: forward AUDIOCPP_DEPLOYMENT_BUILD so model_specs are compiled into the binary for self-contained packages. - Add -BuildDir: allow side-by-side build trees (e.g. ROCm 6.4 and 7.1). - Clear stale GPU_BUILD_TARGETS/AMDGPU_TARGETS cache entries (-U): hip-config-amd.cmake caches GPU_BUILD_TARGETS, so a previous configure's arch list silently overrode a new -GpuTargets value. - Force -DGGML_OPENMP=OFF: ggml probes for OpenMP on its own and, in a vcvars environment, finds LLVM libomp, adding a libomp140.x86_64.dll runtime dependency to otherwise-clean HIP binaries. * Fix sentencepiece -fPIC build failure with Windows clang ROCm clang (GNU driver) targets x86_64-pc-windows-msvc and rejects -fPIC ('unsupported option'), which breaks every Windows HIP build at the sentencepiece protobuf-lite sources. PIC is meaningless on Windows, so skip the flag on WIN32. * Add Windows HIP/ROCm distribution guide Documents how to build and package Windows HIP binaries that run on end user machines without a ROCm SDK installation: - Dual release tracks: ROCm 6.4 (8 arches incl. gfx1102) and ROCm 7.1 (7 arches; 7.1 hipBLASLt ships no gfx1102 kernels). - Runtime DLL bundling, including the hipblaslt kernel library (fatal to omit: it is the default GEMM path and the only one covering gfx1103) and the bundled HIP runtime (Adrenalin 26.5.1+ drivers no longer ship the ROCm 6 runtime, so relying on the driver is not viable for either track). - Kernel library filtering per architecture with measured sizes. - Build environment requirements: MSVC 14.44 toolset (14.51 breaks ROCm clang), -NoNativeCpu, GGML_OPENMP off, dumpbin dependency verification checklist. Also documents the -NoNativeCpu option in HIP.md. Both tracks were verified locally with side-by-side builds. * Polish sentencepiece Windows HIP CMake hunk --------- Co-authored-by: 0xShug0 <231717474+0xShug0@users.noreply.github.com>
1 parent 98c8d32 commit c04c3a5

4 files changed

Lines changed: 361 additions & 4 deletions

File tree

docs/HIP.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ powershell -ExecutionPolicy Bypass -File scripts\build_windows_hip.ps1
245245
# -NoHipblasLt use hipBLAS (rocBLAS) instead of hipBLASLt
246246
# -ForceMmq route quantized matmul through GGML MMQ kernels
247247
# -WithVmm enable HIP virtual memory management
248+
# -NoNativeCpu portable CPU kernels (no native ISA); required for distribution builds
248249
# -ConfigureOnly / -Clean / -Target audiocpp_cli / -Jobs 8
249250
```
250251
Lines changed: 329 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,329 @@
1+
# Windows HIP/ROCm Distribution Guide
2+
3+
This document explains how to build and package audio.cpp HIP/ROCm binaries on Windows so that other AMD GPU users can run them **without installing the ROCm SDK**.
4+
5+
The approach mirrors the llama.cpp Windows HIP release (`.github/workflows/release.yml`, `windows-hip` job), adjusted for audio.cpp and verified against a local ROCm 6.4 / 7.1 installation.
6+
7+
For HIP build instructions (compiler setup, MSVC toolset compatibility, iGPU vs dGPU tuning), see [docs/HIP.md](../HIP.md).
8+
9+
---
10+
11+
## 1. Build with Multiple GPU Architectures
12+
13+
The default `build_windows_hip.ps1` auto-detects only the **local** GPU via `amdgpu-arch`. For distribution, pass all target architectures explicitly.
14+
15+
### Two Release Tracks
16+
17+
The project publishes two HIP packages (decided after verifying both build tracks locally):
18+
19+
| Track | ROCm | GPU Targets | Notes |
20+
|---|---|---|---|
21+
| `audiocpp-windows-hip-rocm6` | 6.4 | gfx1100/1101/**1102**/1103/1150/1151/1200/1201 (8) | Full coverage, conservative choice; required for RX 7600 (gfx1102) |
22+
| `audiocpp-windows-hip-rocm7` | 7.1 | gfx1100/1101/1103/1150/1151/1200/1201 (7) | Smaller kernel libraries, better-tuned RDNA4 kernels; **no gfx1102** (7.1 hipBLASLt ships no gfx1102 kernels) |
23+
24+
Both tracks cover gfx1103 (780M) via hipBLASLt. The 7.1 package README must state: "RX 7600 series users: use the ROCm 6 package."
25+
26+
Both tracks were verified locally (2026-07-29): 145 `.cu` files compiled for every target arch, dependency chains match §2 (`amdhip64_6` + `hipblas` + `hipblaslt` on 6.4; `amdhip64_7` + `libhipblas` + `libhipblaslt` on 7.1), no `libomp140.x86_64.dll`, embedded model specs resolve.
27+
28+
> **Two build-environment requirements** (both documented in [docs/HIP.md](../HIP.md)):
29+
>
30+
> 1. Run the build from a prompt that selects the **MSVC 14.44 toolset** (`vcvarsall.bat x64 -vcvars_ver=14.44`). ROCm's HIP clang cannot parse the `cmath` of MSVC 14.51 (VS 2026) — every `.cu` compile fails.
31+
> 2. Pass `-NoNativeCpu` so the CPU backend is not compiled with the build machine's native ISA (see "CPU Portability" below).
32+
33+
**ROCm 6.4 track** (`build\hip`):
34+
35+
```powershell
36+
powershell -ExecutionPolicy Bypass -File scripts\build_windows_hip.ps1 `
37+
-RocmPath "C:\Program Files\AMD\ROCm\6.4" `
38+
-GpuTargets "gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1200;gfx1201" `
39+
-NoNativeCpu -DeploymentBuild -Target audiocpp_cli -Jobs 16
40+
41+
powershell -ExecutionPolicy Bypass -File scripts\build_windows_hip.ps1 `
42+
-RocmPath "C:\Program Files\AMD\ROCm\6.4" `
43+
-GpuTargets "gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1200;gfx1201" `
44+
-NoNativeCpu -DeploymentBuild -Target audiocpp_server -Jobs 16
45+
```
46+
47+
`-DeploymentBuild` compiles the `model_specs/*.json` catalog into the binary (`AUDIOCPP_DEPLOYMENT_BUILD`), so end users do not need the `model_specs/` directory. Without it the server/CLI fails with `model spec not found for family ...` unless `--model-spec-override` is given.
48+
49+
**ROCm 7.1 track** (side-by-side in `build\hip71`, gfx1102 excluded):
50+
51+
```powershell
52+
powershell -ExecutionPolicy Bypass -File scripts\build_windows_hip.ps1 `
53+
-RocmPath "C:\Program Files\AMD\ROCm\7.1" -BuildDir build\hip71 `
54+
-GpuTargets "gfx1100;gfx1101;gfx1103;gfx1150;gfx1151;gfx1200;gfx1201" `
55+
-NoNativeCpu -DeploymentBuild -Target audiocpp_cli -Jobs 16
56+
57+
powershell -ExecutionPolicy Bypass -File scripts\build_windows_hip.ps1 `
58+
-RocmPath "C:\Program Files\AMD\ROCm\7.1" -BuildDir build\hip71 `
59+
-GpuTargets "gfx1100;gfx1101;gfx1103;gfx1150;gfx1151;gfx1200;gfx1201" `
60+
-NoNativeCpu -DeploymentBuild -Target audiocpp_server -Jobs 16
61+
```
62+
63+
### Supported Architecture Matrix
64+
65+
| GPU Target | Type | Example Hardware |
66+
|---|---|---|
67+
| gfx1100 | RDNA3 discrete | RX 7900 XTX / XT |
68+
| gfx1101 | RDNA3 discrete | RX 7900 GRE |
69+
| gfx1102 | RDNA3 discrete | RX 7600 XT |
70+
| gfx1103 | RDNA3 iGPU | Radeon 780M |
71+
| gfx1150 | RDNA3.5 iGPU | Strix Point |
72+
| gfx1151 | RDNA3.5 iGPU | Strix Halo |
73+
| gfx1200 | RDNA4 discrete | RX 9070 XT |
74+
| gfx1201 | RDNA4 discrete | RX 9070 |
75+
76+
Omit architectures you do not need to reduce compile time and package size.
77+
78+
> **RDNA2 (gfx1030/1031/1032):** llama.cpp ships these targets, but the hipBLASLt libraries in ROCm 6.4 and 7.1 contain **no gfx1030 kernels** (verified locally). Since audio.cpp routes all GEMM through hipBLASLt at compile time, RDNA2 would fail at runtime. Do not add gfx103x targets unless you have verified the GEMM path on real RDNA2 hardware.
79+
80+
> **gfx1102 on ROCm 7.1:** the 7.1 hipBLASLt library has no gfx1102 kernels (6.4 has 16 MB). If you build against ROCm 7.1, verify RX 7600-class cards before shipping; ROCm 6.4 covers gfx1102 in hipBLASLt.
81+
82+
### Recommended Build Flags for Distribution
83+
84+
The script defaults are already tuned for broad compatibility:
85+
86+
| Flag | Default | Reason |
87+
|---|---|---|
88+
| hipBLASLt GEMM | ON | gfx1103 has no rocBLAS Tensile kernels on Windows (verified in both ROCm 6.4 and 7.1); hipBLASLt covers all listed arches |
89+
| CUDA graphs | OFF | Each cached graph reserves its own VRAM; exhausts shared memory on UMA iGPUs |
90+
| HIP VMM | OFF (`GGML_HIP_NO_VMM=ON`) | Required on Windows iGPUs |
91+
92+
Do **not** change these defaults unless the package targets only discrete GPUs with 8+ GB VRAM.
93+
94+
### CPU Portability (Important)
95+
96+
`ENGINE_ENABLE_NATIVE_CPU` defaults to **ON** (`CMakeLists.txt:87`), which compiles the ggml CPU backend with the build machine's native ISA (e.g. AVX512). A distribution binary built this way can crash with `illegal instruction` on older CPUs.
97+
98+
Pass `-NoNativeCpu` to `scripts/build_windows_hip.ps1` (it forwards `-DENGINE_ENABLE_NATIVE_CPU=OFF`) when producing release binaries. llama.cpp does the same with `-DGGML_NATIVE=OFF`.
99+
100+
### CI Automation Reference
101+
102+
The llama.cpp `windows-hip` release job is a proven template for CI:
103+
104+
1. Download the AMD HIP SDK installer (`AMD-Software-PRO-Edition-<version>-Win11-For-HIP.exe`) and run it with `-install` (silent).
105+
2. Cache `C:\Program Files\AMD\ROCm` between runs; use ccache for the build.
106+
3. Build, copy runtime DLLs and both kernel libraries next to the binaries (see below), zip with 7z.
107+
108+
---
109+
110+
## 2. Collect Runtime DLLs
111+
112+
The executables dynamically link against ROCm math libraries and the MSVC CRT. Direct dependencies of `audiocpp_cli.exe` (verified with `dumpbin /DEPENDENTS` on a ROCm 6.4 build):
113+
114+
```
115+
audiocpp_cli.exe / audiocpp_server.exe
116+
├── amdhip64_6.dll (usually provided by the AMD driver — see below)
117+
├── hipblas.dll
118+
│ └── rocblas.dll
119+
├── hipblaslt.dll
120+
└── MSVC CRT (see below)
121+
```
122+
123+
All other dependencies (`KERNEL32.dll`, `ADVAPI32.dll`, `api-ms-win-crt-*`) are Windows system DLLs and do not need to be bundled.
124+
125+
### HIP Runtime: Bundle It
126+
127+
The HIP runtime (`amdhip64_*.dll`) and compiler runtime (`amd_comgr_*.dll`) are installed into `C:\Windows\System32` by the Adrenalin graphics driver — but **which major version a user has depends on their driver generation**:
128+
129+
- Drivers from 2024 through early 2026 ship the ROCm 6 runtime (`amdhip64_6.dll`, `amd_comgr_2.dll`).
130+
- Adrenalin 26.5.1 (May 2026) and later **dropped the ROCm 6 runtime** and ship only ROCm 7 (`amdhip64_7.dll`, `amd_comgr_3.dll`). This broke applications compiled against ROCm 6, e.g. [Blender Cycles](https://videocardz.com/newz/blender-cycles-has-issues-with-amd-adrenalin-26-5-1-after-rocm-runtime-change).
131+
132+
Since the executables link against exactly one major version, relying on the driver-provided runtime fails for a large share of users either way. **Copy both DLLs from the ROCm `bin` directory used for the build into the package** (~130 MB) so the driver version stops mattering — the driver only needs to support the GPU itself:
133+
134+
| DLL (ROCm 6.4) | DLL (ROCm 7.x) | Approx. Size | Role |
135+
|---|---|---|---|
136+
| `amdhip64_6.dll` | `amdhip64_7.dll` | 17 MB | HIP runtime |
137+
| `amd_comgr_2.dll` | `amd_comgr_3.dll` | 116 MB | AMD compiler runtime (dependency of `amdhip64_*.dll`) |
138+
139+
(llama.cpp gets away without bundling only because it builds against ROCm 7 and accepts the new-driver requirement.)
140+
141+
### Math Library DLLs (Must Bundle)
142+
143+
Copy from the ROCm `bin` directory (e.g. `C:\Program Files\AMD\ROCm\6.4\bin`) into the same directory as the `.exe` files:
144+
145+
| DLL (ROCm 6.4) | DLL (ROCm 7.1) | Approx. Size | Role |
146+
|---|---|---|---|
147+
| `hipblas.dll` | `libhipblas.dll` | 1 MB | BLAS interface layer |
148+
| `rocblas.dll` | `rocblas.dll` | 42 MB | rocBLAS backend (dependency of `hipblas.dll`) |
149+
| `hipblaslt.dll` | `libhipblaslt.dll` | 5 MB | hipBLASLt GEMM (default path) |
150+
151+
The DLL names must match what the executables were linked against, i.e. they must come from the **same ROCm installation used for the build**. Do not mix versions.
152+
153+
### MSVC CRT DLLs
154+
155+
Copy from the Visual Studio Build Tools redistributable directory (e.g. `C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Redist\MSVC\<version>\x64\Microsoft.VC143.CRT`):
156+
157+
- `MSVCP140.dll`
158+
- `VCRUNTIME140.dll`
159+
- `VCRUNTIME140_1.dll`
160+
161+
> OpenMP is disabled in HIP builds (`ENGINE_ENABLE_OPENMP=OFF` plus `-DGGML_OPENMP=OFF`), so `VCOMP140.DLL` is **not** needed. The second flag matters: ggml probes for OpenMP on its own (`GGML_OPENMP` defaults ON), and in a vcvars environment it will find LLVM libomp and silently add a **`libomp140.x86_64.dll`** runtime dependency. After any distribution build, run `dumpbin /DEPENDENTS` on the executables — `libomp140.x86_64.dll` must **not** appear. `scripts/build_windows_hip.ps1` passes both flags.
162+
163+
### HSA Runtime
164+
165+
There is no `hsa-runtime64_1.dll` in the Windows ROCm SDK. On Windows the HSA runtime is provided by the **AMD GPU driver** (Adrenalin Edition). Users only need a normally installed AMD driver.
166+
167+
---
168+
169+
## 3. Copy the Kernel Libraries (rocBLAS **and** hipBLASLt)
170+
171+
Both `rocblas.dll` and `hipblaslt.dll` load GPU kernel binaries from a directory next to the DLL at runtime. **Both must be shipped.** llama.cpp copies both in its release packaging (`release.yml`: `cp ...\bin\rocblas\library\*` and `cp ...\bin\hipblaslt\library\*`).
172+
173+
Copy from the ROCm `bin` directory:
174+
175+
```
176+
C:\Program Files\AMD\ROCm\<version>\bin\rocblas\library\
177+
C:\Program Files\AMD\ROCm\<version>\bin\hipblaslt\library\
178+
```
179+
180+
Place them next to the executables as:
181+
182+
```
183+
<package>\rocblas\library\
184+
<package>\hipblaslt\library\
185+
```
186+
187+
> The hipBLASLt library is easy to overlook and fatal to omit: hipBLASLt is the **default GEMM path**, and it is the **only** GEMM path that covers gfx1103. Without `hipblaslt\library\`, GEMM initialization fails on every GPU.
188+
189+
### Library Sizes by ROCm Version (measured locally)
190+
191+
| Library | ROCm 6.4 | ROCm 7.1 |
192+
|---|---|---|
193+
| `rocblas\library` (full) | ~1060 MB | ~191 MB |
194+
| `rocblas\library` (8 target arches + fallback) | ~783 MB | ~143 MB |
195+
| `hipblaslt\library` (8 target arches) | ~147 MB | ~407 MB |
196+
| **Total, 8 arches** | **~930 MB** | **~550 MB** |
197+
198+
ROCm 7.1 shrinks rocBLAS dramatically (lazy-loading index only) but inflates hipBLASLt for RDNA4 (gfx1200: 189 MB, gfx1201: 131 MB). With the HIP runtime bundled (see §2), driver generation is no longer a differentiator. The remaining trade-offs: ROCm 6.4 covers gfx1102 in hipBLASLt (7.1 does not) and is the conservative choice for the first release; ROCm 7.x yields a ~380 MB smaller package and is the maintained line with better RDNA4/Strix support, but must be verified on gfx1102 hardware first.
199+
200+
### Filtering by Architecture
201+
202+
Delete files whose names contain architectures you do not target. **Do not remove `fallback` files** — they are architecture-independent kernels used when no arch-specific kernel is available.
203+
204+
rocBLAS per-architecture breakdown (ROCm 6.4):
205+
206+
| Architecture | Size | Keep? |
207+
|---|---|---|
208+
| gfx906 (Vega) | 130 MB | No |
209+
| gfx1030 (RDNA2) | 147 MB | No |
210+
| gfx1100 | 280 MB | Yes |
211+
| gfx1101 | 157 MB | Yes |
212+
| gfx1102 | 159 MB | Yes |
213+
| gfx1150 | 159 MB | Yes |
214+
| gfx1151 | 9 MB | Yes |
215+
| gfx1200 | 9 MB | Yes |
216+
| gfx1201 | 9 MB | Yes |
217+
| fallback | 76 MB | Yes (always) |
218+
219+
hipBLASLt per-architecture breakdown:
220+
221+
| Architecture | ROCm 6.4 | ROCm 7.1 |
222+
|---|---|---|
223+
| gfx1100 | 16 MB | 17 MB |
224+
| gfx1101 | 17 MB | 19 MB |
225+
| gfx1102 | 16 MB | **0 MB (missing!)** |
226+
| gfx1103 | 16 MB | 17 MB |
227+
| gfx1150 | 16 MB | 17 MB |
228+
| gfx1151 | 16 MB | 17 MB |
229+
| gfx1200 | 23 MB | 189 MB |
230+
| gfx1201 | 27 MB | 131 MB |
231+
232+
To filter with PowerShell:
233+
234+
```powershell
235+
$rocmBin = "C:\Program Files\AMD\ROCm\6.4\bin"
236+
foreach ($lib in @("rocblas", "hipblaslt")) {
237+
$src = Join-Path $rocmBin "$lib\library"
238+
$dst = ".\package\$lib\library"
239+
New-Item -ItemType Directory -Force -Path $dst | Out-Null
240+
Get-ChildItem $src -File | Where-Object {
241+
$_.Name -notmatch "gfx906|gfx1030"
242+
} | Copy-Item -Destination $dst
243+
}
244+
```
245+
246+
> **Optional size optimization (verify before using):** with hipBLASLt enabled, every GEMM in ggml is routed to hipBLASLt at compile time (`external/ggml/src/ggml-cuda/ggml-cuda.cu`), so the rocBLAS Tensile kernels in `rocblas\library` are never exercised. `rocblas.dll` itself must still ship (it is statically linked by `hipblas.dll`), but the ~780 MB (6.4) of Tensile kernels may be dead weight. llama.cpp ships the full library; if you drop it, test every model family on several architectures first.
247+
248+
---
249+
250+
## 4. Final Package Layout
251+
252+
```
253+
audiocpp-windows-hip/
254+
├── audiocpp_cli.exe
255+
├── audiocpp_server.exe
256+
├── amdhip64_6.dll (amdhip64_7.dll on ROCm 7.x)
257+
├── amd_comgr_2.dll (amd_comgr_3.dll on ROCm 7.x)
258+
├── hipblas.dll (libhipblas.dll on ROCm 7.x)
259+
├── hipblaslt.dll (libhipblaslt.dll on ROCm 7.x)
260+
├── rocblas.dll
261+
├── MSVCP140.dll
262+
├── VCRUNTIME140.dll
263+
├── VCRUNTIME140_1.dll
264+
├── rocblas/
265+
│ └── library/ (filtered to target architectures + fallback)
266+
├── hipblaslt/
267+
│ └── library/ (filtered to target architectures)
268+
└── README.md
269+
```
270+
271+
### Estimated Size (8 architectures, ROCm 6.4)
272+
273+
| Component | Size |
274+
|---|---|
275+
| Executables | ~160 MB |
276+
| ROCm DLLs (incl. HIP runtime) | ~181 MB |
277+
| rocBLAS library (filtered) | ~783 MB |
278+
| hipBLASLt library | ~147 MB |
279+
| MSVC CRT | ~2 MB |
280+
| **Total (uncompressed)** | **~1.3 GB** |
281+
| **Total (zip)** | **~700–900 MB** |
282+
283+
With ROCm 7.1 the kernel libraries total ~550 MB instead of ~930 MB.
284+
285+
---
286+
287+
## 5. End-User Requirements
288+
289+
- 64-bit Windows
290+
- AMD GPU matching one of the compiled target architectures
291+
- AMD GPU driver (Adrenalin Edition) normally installed — the HIP runtime itself is bundled, so the driver only needs to support the GPU
292+
- Model files downloaded separately
293+
294+
The following are **not** required:
295+
296+
- ROCm SDK / AMD HIP SDK
297+
- Visual Studio or MSVC Build Tools
298+
- CUDA Toolkit
299+
300+
### Quick Start for Users
301+
302+
```powershell
303+
.\audiocpp_cli.exe --backend hip --task tts --family <family> --model C:\path\to\model [options]
304+
.\audiocpp_cli.exe --backend cpu --task tts --family <family> --model C:\path\to\model [options]
305+
```
306+
307+
`rocm` is accepted as an alias for `hip`:
308+
309+
```powershell
310+
.\audiocpp_cli.exe --backend rocm --task tts --family <family> --model C:\path\to\model
311+
```
312+
313+
Server:
314+
315+
```powershell
316+
.\audiocpp_server.exe --config C:\path\to\server.json
317+
```
318+
319+
---
320+
321+
## 6. Notes
322+
323+
- The HIP build also includes the CPU backend, so users can fall back to `--backend cpu`.
324+
- Keep all DLL files and the `rocblas/` and `hipblaslt/` directories next to the `.exe` files. The libraries locate their kernel files relative to the DLL path.
325+
- If GPU initialization fails, the user should update their AMD driver first.
326+
- gfx1103 (Radeon 780M) works via the hipBLASLt GEMM path without any `HSA_OVERRIDE_GFX_VERSION` workaround. That override is [not supported on Windows](https://github.com/ROCm/ROCm/issues/2654) and is not needed when hipBLASLt is enabled (the default).
327+
- On memory-constrained iGPUs (780M, Strix Point/Halo), CUDA graphs are disabled by default to avoid `out of memory` during graph warmup. This is the correct default for a distribution package.
328+
- Redistribution: rocBLAS/hipBLASLt are MIT-licensed open source, but the Windows HIP SDK binaries are governed by the AMD EULA. Verify that the EULA permits redistributing the runtime DLLs with an application before publishing.
329+
- Packaging automation: `scripts/package_windows_prebuilt.ps1` currently supports only `cpu` and `cuda` packages; extending it with a `hip` package kind would automate the DLL/library collection steps above.

external/sentencepiece/src/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,15 @@ endif()
263263
set_target_properties(sentencepiece-static PROPERTIES OUTPUT_NAME "sentencepiece")
264264
set_target_properties(sentencepiece_train-static PROPERTIES OUTPUT_NAME "sentencepiece_train")
265265

266-
if (NOT MSVC)
267-
set(CMAKE_CXX_FLAGS "-O3 -Wall -fPIC ${CMAKE_CXX_FLAGS}")
266+
if (NOT MSVC)
267+
if (WIN32)
268+
# clang with the GNU driver targeting windows-msvc rejects -fPIC
269+
# ("unsupported option for target 'x86_64-pc-windows-msvc'"); PIC is
270+
# meaningless on Windows anyway. Keep the rest of the flags.
271+
set(CMAKE_CXX_FLAGS "-O3 -Wall ${CMAKE_CXX_FLAGS}")
272+
else()
273+
set(CMAKE_CXX_FLAGS "-O3 -Wall -fPIC ${CMAKE_CXX_FLAGS}")
274+
endif()
268275
if (SPM_NO_THREADLOCAL)
269276
add_definitions(-DSPM_NO_THREADLOCAL=1)
270277
add_definitions(-DGOOGLE_PROTOBUF_NO_THREADLOCAL=1)

0 commit comments

Comments
 (0)