1
1
# Setting up your machine and building clang
2
2
3
+ Note: The automation scripts used to build and test the Checked C compiler have
4
+ now been moved to their own [ repo] ( https://github.com/microsoft/checkedc-automation ) .
5
+ For Windows builds we have deprecated msbuild and have now switched to using
6
+ CMake with Ninja.
7
+
3
8
## Setting up your machine
4
9
5
10
See the clang [ Getting started guide] ( http://clang.llvm.org/get_started.html ) for information
6
- on how to set up your machine. For Linux, you should install CMake 3.8 or later.
7
- If you will be developing on Windows, you should install CMake 3.14 or later on your machine.
11
+ on how to set up your machine.
8
12
9
- ### Developing on Windows
13
+ We now use CMake and Ninja for Clang builds on both Windows and Linux. For
14
+ Linux, install CMake 3.8 or later. For Windows, CMake is bundled as
15
+ part of your Visual Studio install.
10
16
11
- We are doing the development work for Checked C on Windows. We have a few recommendations for developing
12
- clang on Windows using Visual Studio.
17
+ ### Developing on Windows
13
18
14
19
We recommend that you use a 64-bit version of Windows. We have found that the 32-bit hosted
15
20
Visual Studio linker tends to run out of memory when linking clang or clang tools. You will
16
21
want to use the 64-bit hosted Visual Studio toolset instead, which will require a 64-bit version
17
22
of Windows too.
18
23
19
- You will need to install the following before building:
20
-
21
- - Visual Studio 2017 or later, CMake (version 3.14 or later), Python (version 2.7), and versions of UNIX command
22
- line tools. We recommend using Visual Studio 2019.
23
- - For UNIX command-line tools, we recommend installing them via Cygwin because these are well-maintained.
24
- Go to [ http://www.cygwin.com ] ( http://www.cygwin.com ) and download the installer (put it in a known place).
25
- Then run it and use the GUI to install the coreutils and diffutils packages. Add the bin subdirectory to your system path.
26
-
27
- If you plan to use Visual Studio to build projects, you must limit the amount
28
- of parallelism that will be used during builds. By default, the Visual Studio solution
29
- for clang has [ too much parallelism] ( https:/github.com/Microsoft/checkedc-clang/issues/268 ) .
30
- The parallelism will cause your build to use too much physical memory and cause your machine
31
- to start paging. This will make your machine unresponsive and slow down your build too.
32
- See the Wiki page on [ Parallel builds of clang on Windows] ( https://github.com/Microsoft/checkedc-clang/wiki/Parallel-builds-of-clang-on-Windows/ )
33
- for more details.
34
-
35
- in VS 2017 or VS 2019, go to _ Debug->Options->Projects and Solutions->VC++ Project Settings_ and set
36
- the ` Maximum Number of concurrent C++ compilations ` to 3, if your development machine has
37
- 1 GByte of memory or more per core. If not, see the
38
- [ Wiki page] ( https://github.com/Microsoft/checkedc-clang/wiki/Parallel-builds-of-clang-on-Windows/ )
24
+ Prerequisites:
25
+
26
+ - Visual Studio 2017 or later, Python (version 2.7), and versions of UNIX
27
+ command-line tools. We recommend using Visual Studio 2019.
28
+ - For VS2019, go to Tools -> Get Tools and Features (this opens the VS installer)
29
+ - Go to Individual Components
30
+ - Scroll to the “SDKs, libraries, and frameworks” section (near the bottom of the list)
31
+ - Check “C++ ATL for latest v142 build tools (x86 and x64)”
32
+ - Install
33
+
34
+ - For UNIX command-line tools, install them via [ GnuWin32] ( https://sourceforge.net/projects/getgnuwin32/postdownload )
35
+ - In cmd prompt, cd to the download dir and run:
36
+ - download.bat
37
+ - install.bat C:\GnuWin32
38
+ - set PATH=C:\GnuWin32\bin;%PATH%
39
+
40
+ - If Ninja is not already available on your machine, you can download it from [ here] ( https://github.com/ninja-build/ninja/releases ) .
41
+ Remember to set path to the ninja executable.
42
+
43
+ In order to limit the amount of build parallelism with Visual Studio:
44
+ - Debug->Options->Projects and Solutions->VC++ Project Settings
45
+ - Set ` Maximum Number of concurrent C++ compilations ` to 3, if your development machine has
46
+ 1 GByte of memory or more per core. If not, see the [ Wiki page] ( https://github.com/Microsoft/checkedc-clang/wiki/Parallel-builds-of-clang-on-Windows/ )
39
47
to figure out what number to use.
40
48
By default, 0 causes it to be the number of available CPU cores on your machine, which is too much.
41
- You should also to go to _ Debug ->Options->Projects and Solutions->Build and Run _ and
49
+ You should also to go to Debug ->Options->Projects and Solutions->Build and Run and
42
50
set the maximum number of parallel project builds to be 3/4 of the actual number of CPU cores on
43
51
your machine.
44
52
53
+ A note about line endings:
45
54
LLVM/Clang have some tests that depend on using UNIX line ending conventions
46
55
(line feeds only). This means that the sources you will be working with
47
56
need to end with line feeds. Visual Studio preserves line endings for files, so
@@ -132,125 +141,102 @@ git clone https://github.com/Microsoft/checkedc
132
141
4 . Make sure to set the following CMake flag to enable clang in your builds: -DLLVM_ENABLE_PROJECTS=clang
133
142
5 . Make sure that you are using whatever shell you normally do compiles in.
134
143
135
- On Linux, cd your build directory and invoke CMake
136
- with:
144
+ On Windows and Linux, cd your build directory and invoke CMake:
137
145
```
138
- cmake {llvm-path}
146
+ cmake -G Ninja {llvm-path}
139
147
```
140
148
where ` {llvm-path} ` is the path to the root of your LLVM repo.
141
149
142
- The directions for generating a build system for Visual Studio depend on which
143
- version of CMake you are using. You must use CMake 3.14 or higher to
144
- generate a build system for Visual Studio 2019.
145
-
146
- ### Visual Studio with CMake 3.14 or higher
147
-
148
- If you are using CMake 3.14 or higher, you use the -G option to specify
149
- the generator (the target build system) and the -A option to specify
150
- the architecture. The clang tests will build and run for that architecture
151
- and the architecture will be the default target architecture for clang (these options
152
- are explained [ here] ( https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2016%202019.html ) ).
153
- By default, CMake uses the 64-bit toolset on 64-bit Windows systems, so you
154
- do not have to worry about that.
155
-
156
- To generate a build system for Visual Studio 2019 targeting x86, use
157
- ```
158
- cmake -G "Visual Studio 16 2019" -A Win32 {llvm-path}
159
- ```
160
- For x64, use
161
- ```
162
- cmake -G "Visual Studio 16 2019" -A x64 {llvm-path}
163
- ```
164
- To target Visual Studio 2017, substitute "Visual Studio 15 2017" for "Visual Studio 16 2019".
165
- ` cmake --help ` will list all the available generators on your platform.
166
-
167
- ### Visual Studio with earlier versions of CMake
168
-
169
- On Windows, when using Visual Studio, you should specify that the 64-bit hosted toolset be used.
170
- Visual Studio has both 32-bit hosted and 64-bit hosted versions of tools.
171
- You can do that by adding the option ` -T "host=x64" ` to the command-line (note that this
172
- option is only available using CMake version 3.8 or later).
173
- ```
174
- cmake -T "host=x64" {llvm-path}
175
- ```
176
-
177
- On Windows, when using Visual Studio, CMake versions earlier than 3.14
178
- by default produce a build system for x86. This means that the clang tests
179
- will run in 32-bit compatiblity mode, even on a 64-bit version of Windows.
180
- To build and run tests on x64, specify a different generator using the ` -G `
181
- option. For Visual Studio 2017, you can use:
182
- ```
183
- cmake -T "host=x64" -G "Visual Studio 15 2017 Win64" {llvm-path}
184
- ```
185
- ` cmake --help ` will list all the available generators on your platform.
186
-
187
150
### Building an LLVM package (advanced topic)
188
- If you are just trying out Checked C, you can safely ignore this section. If you plan to build an LLVM package for installation
189
- on other machines, we recommend that you build a release build of clang with assertions on and only include the toolchain in
190
- the package. On Windows, you can add the following flags to your cmake command line:
151
+ If you are just trying out Checked C, you can safely ignore this section. If
152
+ you plan to build an LLVM package for installation on other machines, we
153
+ recommend that you build a release build of clang with assertions on and only
154
+ include the toolchain in
155
+ the package. On Windows, you can add the following flags to your CMake options:
191
156
```
192
- -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_INSTALL_TOOLCHAIN_ONLY=ON -DLLVM_USE_CRT_RELEASE=MT
157
+ -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_INSTALL_TOOLCHAIN_ONLY=ON -DLLVM_USE_CRT_RELEASE=MT
193
158
```
194
159
On UNIX you can add,
195
160
```
196
- -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_INSTALL_TOOLCHAIN_ONLY=ON
161
+ -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_INSTALL_TOOLCHAIN_ONLY=ON
197
162
```
198
163
199
164
## Building
200
165
201
- You can build ` clang ` the usual way that it is built. The earlier build system directions will create a Debug build,
202
- so ` clang ` will be placed in your build directory under ` Debug\bin ` .
203
-
204
- Note that the first time that you build clang, it may take over an hour to build. This is because LLVM is being
205
- built . The debug build of LLVM is particularly slow because it bottlenecks on table generation. LLVM generates architecture-specific
206
- tables at build time that are used during code generation. The default table generation algorithm is very slow in debug builds.
207
- Subsequent builds during development will be much faster (minutes, not an hour).
166
+ Note that the first time that you build clang, it may take over an hour to
167
+ build. This is because LLVM is being built. The debug build of LLVM is
168
+ particularly slow because it bottlenecks on table generation. LLVM generates
169
+ architecture-specific tables at build time that are used during code
170
+ generation . The default table generation algorithm is very slow in debug
171
+ builds. Subsequent builds during development will be much faster (minutes, not
172
+ an hour).
208
173
209
174
### On UNIX
210
-
211
175
Change to your build directory and build ` clang ` :
212
-
213
- make -j nnn clang
214
-
215
- where ` nnn ` is replaced by the number of CPU cores that your computer has.
176
+ ```
177
+ ninja clang
178
+ ```
216
179
217
180
### On Windows
218
181
219
- For day-to-day development, we recommend building from Visual Studio. This will improve your productivity significantly because it will give you
220
- all the capabilities of Visual Studio for navigating the code base, code browsing, and Intellisense. Note that VS launches a multi-threaded build
221
- by default. Be sure you have throttled down the number of processes following earlier directions.
182
+ For day-to-day development, we recommend building from Visual Studio. This
183
+ will improve your productivity significantly because it will give you all the
184
+ capabilities of Visual Studio for navigating the code base, code browsing, and
185
+ Intellisense.
222
186
223
187
#### Visual Studio
224
- Follow the earlier instructions to set up the build system. After you've done that, there should be a solution file LLVM.sln in
225
- your build directory. Use Visual Studio to load the solution file. Then open the solution explorer (under View->Solution Explorer).
188
+ After you have followed the earlier instructions to set up the build system:
189
+ - Start Visual Studio->Open a Local Folder.
190
+ - To build llvm and clang: Open the src/llvm directory (because this contains the llvm CMakeLists file).
191
+ - To build only clang: Open the src/clang directory (because this contains the clang CMakeLists file).
226
192
227
- To build
193
+ To configure:
194
+ - Project->Generate Cache for LLVM
228
195
229
- - clang only: go to _ clang executables directory -> clang_ and right click to build `clang'.
230
- - Everything: right click on the solution and select build.
196
+ To add options to CMake:
197
+ - Project->CMake Settings for LLVM
198
+ - Add your options to "Cmake command arguments" and save
199
+ - Project->CMake Cache->Delete Cache, and configure again
231
200
232
- By default, the build type will be a Debug build. You can switch to another build configuration in VS 2017
233
- by selecting the Build->Configuration Manager menu item and choosing a different solution configuration.
201
+ To build:
202
+ - Build->Build All
234
203
235
- #### Command-shell
204
+ The above instructions would build an X64 Release version of clang and the
205
+ default build dir is build dir is src/llvm/out. You can change this (and many
206
+ other settings) from Project->CMake Settings for LLVM.
236
207
237
- Follow the earlier instructions to set up the build system. From the build directory, use the following comamnd to build clang only:
208
+ To build an X86 version of clang:
209
+ - Project->CMake Settings for LLVM
210
+ - Toolset->msvc_x86_x64
238
211
239
- msbuild tools\clang\tools\driver\clang.vcxproj /p:CL_MPCount=3 /m
212
+ #### Command-shell
240
213
241
- To build everything:
214
+ Follow the earlier instructions to set up the build system.
242
215
243
- msbuild LLVM.sln /p:CL_MPCount=3 /m
216
+ To build X64 version of clang:
217
+ ```
218
+ "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
219
+ ```
244
220
245
- To clean the build directory:
221
+ To build X86 version of clang:
222
+ ```
223
+ "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x86
224
+ ```
246
225
247
- msbuild /t:clean LLVM.sln
226
+ From the build directory, use the following command to build clang only:
227
+ ```
228
+ ninja clang
229
+ ```
248
230
249
- By default, the build type is a Debug build. You can specify the build type by adding ` /p:Configuration=nnn `
250
- to the ` msbuild ` command line, where ` nnn ` is one of ` Debug ` , ` Release ` , or ` RelWithDebInfo ` . For example,
251
- for a Release build, use:
231
+ To build everything:
232
+ ```
233
+ ninja
234
+ ```
252
235
253
- msbuild tools\clang\tools\driver\clang.vcxproj /p:Configuration=Release /p:CL_MPCount=3 /m
236
+ To clean the build directory:
237
+ ```
238
+ ninja clean
239
+ ```
254
240
255
241
## Testing
256
242
@@ -260,16 +246,8 @@ are testing the Checked C version of clang on x86 and x64 Windows and on x64 Lin
260
246
## Building an LLVM package.
261
247
262
248
If you would like to build an LLVM package, first follow the steps in setting up a build directory for
263
- building a package. On Windows, install [ NSIS] ( http://nsis.sourceforge.net ) . Change directory to your
264
- build directory, and run
265
-
266
- msbuild PACKAGE.sln /p:Configuration=Release /p:CL_MPCount=3 /m
267
-
268
- On UNIX, run
269
-
270
- make -j nnn package
271
-
272
- where ` nnn ` is replaced by the number of CPU cores that your computer has.
249
+ building a package. On both Windows and Linux, change directory to the build directory, and run
250
+ ninja package
273
251
274
252
## Updating sources to the latest sources for LLVM/Clang
275
253
0 commit comments