Skip to content

Commit 8f39f4a

Browse files
authored
[Docs] Add new docs on unified build workflow (microsoft#4890)
This document tries to capture the basics of a unified build and test workflow for all platforms. It is complete enough to start using but not yet ready to be the default build mode.
1 parent 93543b7 commit 8f39f4a

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed

docs/BuildingAndTestingDXC.rst

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
==========================================
2+
Building and Testing DirectXShaderCompiler
3+
==========================================
4+
5+
.. contents::
6+
:local:
7+
:depth: 3
8+
9+
.. warning::
10+
This document describes a new and slightly experimental build process
11+
building DXC and using LLVM's LIT tool to run DXC's tests. This workflow
12+
is complete on Linux and Unix platforms, but is incomplete but usable on
13+
Windows. Instructions for building on Windows are available in the repository
14+
`readme <https://github.com/microsoft/DirectXShaderCompiler/blob/main/README.md>`_.
15+
Instructions for the preexisting Linux and Unix workflow can be found here:
16+
:doc:`DxcOnUnix`
17+
18+
Introduction
19+
============
20+
21+
DXC's build is configured using CMake and should be buildable with any preferred
22+
generator. In subsequent sections we will describe workflows using Ninja and
23+
Visual Studio. The Ninja workflow should also apply to makefile generators with
24+
minimal adaption.
25+
26+
Basic CMake Usage
27+
-----------------
28+
29+
When building DXC there are a bunch of CMake options which must be set. To
30+
simplify configuration those options are collected into a CMake cache script
31+
which can be passed into the CMake tool using the ``-C`` flag. Cache scripts run
32+
before any other CMake script evaluation and can be used to initialize variables
33+
for the configuration process.
34+
35+
All of the most basic CMake configurations for DXC follow a similar format to:
36+
37+
.. code:: sh
38+
cmake <Repository Root> \
39+
-C <Repository Root>/cmake/caches/PredefinedParams.cmake \
40+
-DCMAKE_BUILD_TYPE=<Build Type> \
41+
-G <Generator>
42+
43+
Useful CMake Flags
44+
------------------
45+
46+
By default CMake will place the generated build output files in the directory
47+
you run CMake in. Our build system disallows running CMake in the root of the
48+
repository so you either need to create an alternate directory to run CMake in,
49+
or you can use the CMake ``-B <path>`` flag to direct CMake to place the
50+
generated files in a different location.
51+
52+
Generating a Visual Studio Solution
53+
-----------------------------------
54+
55+
Open a Visual Stuido command prompt and run:
56+
57+
.. code:: sh
58+
cmake <Repository Root> \
59+
-B <Path to Output> \
60+
-DDXC_USE_LIT=On \
61+
-C <Repository Root>/cmake/caches/PredefinedParams.cmake \
62+
-DCMAKE_BUILD_TYPE=<Build Type> \
63+
-G "Visual Studio 17 2022"
64+
65+
Open the resulting LLVM.sln placed under the ``<Path to Output>``. DXC should
66+
build successfully with either the ``Visual Studio 17 2022`` or ``Visual Studio
67+
16 2019`` generators.
68+
69+
Using Visual Studio's CMake Integration
70+
---------------------------------------
71+
72+
Open Visual Studio and select "Open a local folder". Open the folder DXC is
73+
cloned into. If Visual Studio does not start automatically configuring the build
74+
you may need to go to the "Project" menu and select "CMake Workspace Settings"
75+
and add ``"enableCMake"; true`` to the JSON configuration file.
76+
77+
After CMake configuration completes you should be able to toggle the "Solution
78+
Explorer" into "CMake Targets View" to see the available build targets.
79+
80+
Generating Ninja or Makefiles
81+
-----------------------------
82+
83+
In your preferred terminal run:
84+
85+
.. code:: sh
86+
cmake <Repository Root> \
87+
-B <Path to Output> \
88+
-DDXC_USE_LIT=On \
89+
-C <Repository Root>/cmake/caches/PredefinedParams.cmake \
90+
-DCMAKE_BUILD_TYPE=<Build Type> \
91+
-G Ninja
92+
93+
You may substitute ``Ninja`` for ``Unix Makefiles`` to generate a makefile
94+
build. After generation completes you can run ``ninja`` or ``make`` as
95+
appropriate.
96+
97+
Building and Running Tests
98+
--------------------------
99+
100+
With the LIT-based testing solution, builds and tests are all run through the
101+
generated build system. Regardless of which tool you use to build DXC you should
102+
have the following targets available:
103+
104+
**llvm-test-depends** Builds all the binaries used by the tests.
105+
**clang-test-depends** Builds all the binaries used by the clang tests.
106+
**test-depends** Builds all the binaries used by all the tests.
107+
**check-llvm** Runs the LLVM tests after rebuilding any required out-of-date targets.
108+
**check-clang** Runs the Clang tests after rebuilding any required out-of-date targets.
109+
**check-all** Runs all available tests after rebuilding any out-of-date targets.
110+
111+
Useful CMake Options
112+
--------------------
113+
114+
By convention CMake options are all capital, underscore separated words, and the
115+
first word signifies what the option applies to. In the DXC codebase there are
116+
four commonly used option prefixes:
117+
118+
#. CMAKE - For options defined by CMake itself which apply across the entire
119+
configuration.
120+
#. LLVM - For options defined by LLVM which DXC has inherited. These apply
121+
across the entire DXC codebase.
122+
#. CLANG - For options defined in the clang sub-project which DXC has inherited.
123+
These options apply across just the tools/clang subdirectory.
124+
#. DXC - For DXC-specific options, which may apply across the entire codebase.
125+
126+
**CMAKE_BUILD_TYPE**:STRING
127+
Sets the build type for single-configuration generators (i.e. Ninja and
128+
makefiles) Possible values are Release, Debug, RelWithDebInfo and MinSizeRel.
129+
On systems like Visual Studio or Xcode the user sets the build type with the
130+
IDE settings.
131+
132+
**LLVM_USE_LINKER**:STRING
133+
When building with Clang or GCC this option allows overriding the default
134+
linker used by setting the ``-fuse-ld=`` flag. This may be important for Linux
135+
users on systems where the system linker is ``ld.bfd`` as linking DXC with
136+
debug information can be very memory intensive.
137+
138+
**LLVM_PARALLEL_COMPILE_JOBS**:STRING
139+
When building with Ninja, this option can be used to limit the number of
140+
concurrent compilation jobs.
141+
142+
**LLVM_PARALLEL_LINK_JOBS**:STRING
143+
When building with Ninja, this option can be used to limit number of
144+
concurrent link jobs.
145+
146+
**DXC_COVERAGE**:BOOL
147+
This option must be passed before the ``-C`` flag to set the PredefinedParams
148+
cache script because it is handled by the cache script. This option enables
149+
building DXC with code coverage instrumentation and build targets to generate
150+
code coverage reports. With this setting enabled the
151+
``generate-coverage-report`` target is added to the build which produces a
152+
static HTML page with code coverage analysis results.
153+
154+
**DXC_USE_LIT**:BOOL
155+
This option must be passed before the ``-C`` flag to set the PredefinedParams
156+
cache script because it is handled by the cache script. This option enables
157+
building DXC with the LLVM-LIT testing infrastructure enabled. This generates
158+
check targets for each sub-project (i.e. ``check-llvm``, ``check-clang``...),
159+
and a ``check-all`` target to build and run DXC's tests.

0 commit comments

Comments
 (0)