Skip to content

Commit 2613627

Browse files
MarijnS95claude
andauthored
README: Add build instructions via CMake cache file, document test targets (#1031)
The README previously lacked instructions on how to invoke CMake to build the project from scratch. Add a CMake cache file (`cmake/caches/OffloadTest.cmake`) that sets `LLVM_EXTERNAL_OFFLOADTEST_SOURCE_DIR` and `LLVM_EXTERNAL_PROJECTS`, so that users can pass `-C` instead of specifying these variables manually, and show the full cmake invocation in the README. Also document the `clang-<platform>` test target prefix (for running without DXC) and subdirectory test targets. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 73d942b commit 2613627

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

README.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,28 @@ pip3 install pyyaml
3434

3535
On Windows, the [Graphics Tools](https://learn.microsoft.com/en-us/windows/win32/direct3d12/directx-12-programming-environment-set-up#debug-layer) optional feature is additionally required to run the test suite.
3636

37-
# Adding to LLVM Build
37+
# Building
3838

39-
Add the following to the CMake options:
39+
The LLVM project provides a CMake cache file,
40+
[`clang/cmake/caches/HLSL.cmake`](https://github.com/llvm/llvm-project/blob/main/clang/cmake/caches/HLSL.cmake),
41+
that configures the required projects and targets for HLSL development. You can
42+
use it with `-C` to set up a build that includes the offload test suite:
4043

4144
```shell
42-
-DLLVM_EXTERNAL_OFFLOADTEST_SOURCE_DIR=${workspaceRoot}\..\OffloadTest -DLLVM_EXTERNAL_PROJECTS="OffloadTest"
45+
cmake -G Ninja -Bbuild \
46+
-C <path to llvm-project>/clang/cmake/caches/HLSL.cmake \
47+
-C <path to OffloadTest>/cmake/caches/OffloadTest.cmake \
48+
<path to llvm-project>/llvm
49+
```
50+
51+
The `OffloadTest.cmake` cache file automatically sets
52+
`LLVM_EXTERNAL_OFFLOADTEST_SOURCE_DIR` and `LLVM_EXTERNAL_PROJECTS` based on its
53+
location in the source tree. If you already have an LLVM build configured, you
54+
can add the offload test suite to it by passing the same `-C` flag or by adding
55+
the following to your CMake options:
56+
57+
```shell
58+
-DLLVM_EXTERNAL_OFFLOADTEST_SOURCE_DIR=<path to OffloadTest> -DLLVM_EXTERNAL_PROJECTS="OffloadTest"
4359
```
4460

4561
If you do not have a build of dxc on your path you'll need to specify the shader
@@ -49,6 +65,20 @@ compiler to use by passing:
4965
-DDXC_DIR=<path to folder containing dxc & dxv>
5066
```
5167

68+
## Running Tests
69+
70+
```shell
71+
cmake --build build --target check-hlsl
72+
```
73+
74+
The `check-hlsl` target builds all required tools and runs the full test suite.
75+
You can also run tests for a specific platform with `check-hlsl-<platform>`
76+
(e.g. `check-hlsl-vk`, `check-hlsl-d3d12`). To only run `clang`-based tests
77+
(without requiring DXC), use `check-hlsl-clang-<platform>` (e.g.
78+
`check-hlsl-clang-mtl`). Subdirectories of the test suite are also available as
79+
targets with `check-hlsl-<platform>-<path>` where the path is lowercased with
80+
directory separators replaced by `-` (e.g. `check-hlsl-d3d12-feature-hlsllib`).
81+
5282
## Enabling clang-tidy
5383

5484
The offload test suite's code is clang-tidy clean for a limited ruleset.

cmake/caches/OffloadTest.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set(LLVM_EXTERNAL_OFFLOADTEST_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../ CACHE STRING "")
2+
set(LLVM_EXTERNAL_PROJECTS "${LLVM_EXTERNAL_PROJECTS};OffloadTest" CACHE STRING "")

0 commit comments

Comments
 (0)