Skip to content

Commit f9bb238

Browse files
author
Mandeep Singh Grang
authored
Update docs to reflect the new automation script changes (#801)
The automation scripts used to build and test the Checked C compiler have now been moved to their own repo. For Windows builds we have deprecated msbuild and have now switched to using CMake with Ninja. We have accordingly updated the setup, build and testing docs here.
1 parent 60d3e01 commit f9bb238

File tree

2 files changed

+112
-149
lines changed

2 files changed

+112
-149
lines changed

Diff for: clang/docs/checkedc/Setup-and-Build.md

+100-122
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,56 @@
11
# Setting up your machine and building clang
22

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+
38
## Setting up your machine
49

510
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.
812

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.
1016

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
1318

1419
We recommend that you use a 64-bit version of Windows. We have found that the 32-bit hosted
1520
Visual Studio linker tends to run out of memory when linking clang or clang tools. You will
1621
want to use the 64-bit hosted Visual Studio toolset instead, which will require a 64-bit version
1722
of Windows too.
1823

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/)
3947
to figure out what number to use.
4048
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
4250
set the maximum number of parallel project builds to be 3/4 of the actual number of CPU cores on
4351
your machine.
4452

53+
A note about line endings:
4554
LLVM/Clang have some tests that depend on using UNIX line ending conventions
4655
(line feeds only). This means that the sources you will be working with
4756
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
132141
4. Make sure to set the following CMake flag to enable clang in your builds: -DLLVM_ENABLE_PROJECTS=clang
133142
5. Make sure that you are using whatever shell you normally do compiles in.
134143

135-
On Linux, cd your build directory and invoke CMake
136-
with:
144+
On Windows and Linux, cd your build directory and invoke CMake:
137145
```
138-
cmake {llvm-path}
146+
cmake -G Ninja {llvm-path}
139147
```
140148
where `{llvm-path}` is the path to the root of your LLVM repo.
141149

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-
187150
### 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:
191156
```
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
193158
```
194159
On UNIX you can add,
195160
```
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
197162
```
198163

199164
## Building
200165

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).
208173

209174
### On UNIX
210-
211175
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+
```
216179

217180
### On Windows
218181

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.
222186

223187
#### 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).
226192

227-
To build
193+
To configure:
194+
- Project->Generate Cache for LLVM
228195

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
231200

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
234203

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.
236207

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
238211

239-
msbuild tools\clang\tools\driver\clang.vcxproj /p:CL_MPCount=3 /m
212+
#### Command-shell
240213

241-
To build everything:
214+
Follow the earlier instructions to set up the build system.
242215

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+
```
244220

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+
```
246225

247-
msbuild /t:clean LLVM.sln
226+
From the build directory, use the following command to build clang only:
227+
```
228+
ninja clang
229+
```
248230

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+
```
252235

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+
```
254240

255241
## Testing
256242

@@ -260,16 +246,8 @@ are testing the Checked C version of clang on x86 and x64 Windows and on x64 Lin
260246
## Building an LLVM package.
261247

262248
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
273251

274252
## Updating sources to the latest sources for LLVM/Clang
275253

Diff for: clang/docs/checkedc/Testing.md

+12-27
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,20 @@ Checked C and clang tests.
2121
## Running developer regressions tests
2222

2323
### From Visual Studio
24-
Load the solution and the open it using the Solution explorer (View->Solution
25-
Explorer). To run tests, you can right click and build the following targets:
26-
27-
- Checked C tests: go to _CheckedC tests->check-checkedc_
28-
- clang tests: go to _Clang tests->check-clang_
29-
- All LLVM and clang tests: select the check-all solution (at the top level)
30-
31-
### From a command shell using msbuild
32-
Set up the build system and then change to your new object directory. Use the
33-
following commands to run tests:
34-
35-
- Checked C tests: `msbuild projects\checkedc-wrapper\check-checkedc.vcxproj /p:CL_MPCount=3 /m`
36-
- Clang tests: `msbuild tools\clang\test\check-clang.vcxproj /p:CL_MPCount=3 /m`
37-
- All LLVM and clang tests: `msbuild check-all.vcxproj /p:CL_MPCount=3 /m`
38-
39-
### Using make
24+
- Open Project->Cmake Settings
25+
- Add the following to "Build command arguments" box:
26+
- To run Checked C unit tests: `check-checkec`
27+
- To run Checked C unit tests (for ARM target): `ninja check-checkedc-arm`
28+
- To run Clang unit tests: `check-clang`
29+
- To run all unit tests: `check-all`
30+
31+
### From a command shell using ninja
4032
In your build directory,
4133

42-
- Checked C tests: `make -j nnn check-checkedc`
43-
- Checked C tests (for ARM target): `make -j nnn check-checkedc-arm`
44-
- clang tests: `make -j nnn check-clang`
45-
- All tests: `make -j nnn check-all`
46-
47-
where `nnn` is replaced by the number of CPU cores that your computer has.
48-
49-
Note: If you use CMake with ninja, then you can simply replace `make -j nnn` in
50-
the above commands with `ninja`. For example:
51-
52-
`ninja check-checkedc`
34+
- Checked C tests: `ninja check-checkedc`
35+
- Checked C tests (for ARM target): `ninja check-checkedc-arm`
36+
- Clang tests: `ninja check-clang`
37+
- All unit tests: `ninja check-all`
5338

5439
### From a command shell using the testing harness
5540
You can use the testing harness to run individual tests or sets of tests.

0 commit comments

Comments
 (0)