Skip to content

Commit bbd9ab8

Browse files
committed
[docs] Update the getting started guide and LLVM compilation guide.
1 parent 6fa9778 commit bbd9ab8

File tree

2 files changed

+74
-92
lines changed

2 files changed

+74
-92
lines changed

docs/BuildingLLVM.md

Lines changed: 35 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,88 +3,67 @@
33
This document explains how to build LLVM and Clang from source code.
44

55
It's a process only recommended for developers that need to make changes to LLVM or Clang, or
6-
build the binary packages needed for the CI system.
6+
build the binary packages needed for the CI system. If you just want to build CppSharp, then
7+
check out the getting started guide section on how to download our pre-compiled LLVM packages.
78

8-
Git repository URLs found here: [http://llvm.org/docs/GettingStarted.html#git-mirror]
9-
(http://llvm.org/docs/GettingStarted.html#git-mirror)
9+
## Compiling using the build script
1010

11-
1. Clone LLVM to `<CppSharp>\deps\llvm`
12-
2. Clone Clang to `<CppSharp>\deps\llvm\tools\clang`
11+
This is the preferred way to compile LLVM for usage by CppSharp.
1312

14-
Required LLVM/Clang commits:
13+
1. Before building, ensure Git, CMake and Ninja are installed and acessible from the command line.
1514

16-
[LLVM: see /build/LLVM-commit.](https://github.com/mono/CppSharp/tree/master/build/LLVM-commit)
17-
18-
[Clang: see /build/Clang-commit.](https://github.com/mono/CppSharp/tree/master/build/Clang-commit)
15+
Check the official download pages for each project for further instructions:
1916

20-
## Compiling on Windows/Visual Studio
17+
- [Git](https://git-scm.com/downloads)
18+
- [Ninja](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages)
19+
- [CMake](https://cmake.org/download/)
2120

22-
```shell
23-
cd <CppSharp>\deps\llvm\build
24-
25-
cmake -G "Visual Studio 12" -DCLANG_BUILD_EXAMPLES=false -DCLANG_INCLUDE_DOCS=false -DCLANG_INCLUDE_TESTS=false -DCLANG_INCLUDE_DOCS=false -DCLANG_BUILD_EXAMPLES=false -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_INCLUDE_EXAMPLES=false -DLLVM_INCLUDE_DOCS=false -DLLVM_INCLUDE_TESTS=false ..
26-
27-
msbuild LLVM.sln /p:Configuration=RelWithDebInfo;Platform=Win32 /m
21+
2. Navigate to the `<CppSharp>/build` directory
22+
3. Clone, build and package LLVM with
2823
```
29-
30-
Or, if you need 64-bit binaries:
31-
32-
```shell
33-
cd <CppSharp>\deps\llvm\build
34-
35-
cmake -G "Visual Studio 12 Win64" -DCLANG_BUILD_EXAMPLES=false -DCLANG_INCLUDE_DOCS=false -DCLANG_INCLUDE_TESTS=false -DCLANG_INCLUDE_DOCS=false -DCLANG_BUILD_EXAMPLES=false -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_INCLUDE_EXAMPLES=false -DLLVM_INCLUDE_DOCS=false -DLLVM_INCLUDE_TESTS=false ..
36-
37-
msbuild LLVM.sln /p:Configuration=RelWithDebInfo;Platform=x64 /m
24+
$PREMAKE --file=scripts/LLVM.lua clone_llvm
25+
$PREMAKE --file=scripts/LLVM.lua build_llvm
26+
$PREMAKE --file=scripts/LLVM.lua package_llvm
3827
```
3928

40-
## Compiling on Mac OS X
29+
`$PREMAKE` should be replaced with `premake5.exe`, `premake5-osx` or `premake5-linux-64` depending on environment.
4130

42-
### Compiling manually
31+
You can specify an `--arch=x86` or `--arch=x64` flag to the invocations above to specify an explicit build architecture.
4332

44-
1. Compile LLVM solution in *RelWithDebInfo* mode
45-
The following CMake variables should be enabled:
46-
- LLVM_ENABLE_LIBCXX (enables libc++ standard library support)
47-
- LLVM_BUILD_32_BITS for 32-bit builds (defaults to 64-bit)
33+
If the `clone_llvm` step fails, you can try to manually clone LLVM and Clang as explained below.
34+
You should still run clone_llvm to ensure that you are on the correct revision.
4835

49-
```shell
50-
mkdir -p deps/llvm/build && cd deps/llvm/build
36+
## Cloning from Git
5137

52-
cmake -G "Unix Makefiles" -DLLVM_ENABLE_LIBCXX=true -DLLVM_BUILD_32_BITS=true -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
38+
1. Clone LLVM to `<CppSharp>\deps\llvm`
5339

54-
make
40+
```
41+
git clone http://llvm.org/git/llvm.git
5542
```
5643

57-
### Compiling using the build script
58-
59-
Before building, ensure cmake is installed under Applications/Cmake.app and Ninja is installed in your PATH.
44+
2. Clone Clang to `<CppSharp>\deps\llvm\tools\clang`
6045

61-
1. Navigate to `build/scripts`
62-
2. Clone, build and package LLVM with
6346
```
64-
../premake5-osx --file=LLVM.lua clone_llvm
65-
../premake5-osx --file=LLVM.lua build_llvm
66-
../premake5-osx --file=LLVM.lua package_llvm
47+
cd llvm/tools
48+
git clone http://llvm.org/git/clang.git
6749
```
6850

69-
You can specify an `--arch=x86` or `--arch=x64` flag to the invocations above to specify an explicit build architecture.
51+
Official LLVM instructions can be found here: [http://llvm.org/docs/GettingStarted.html#git-mirror]
52+
(http://llvm.org/docs/GettingStarted.html#git-mirror)
7053

71-
If the clone_llvm step fails, you can try to manually clone LLVM and Clang as explained above. You should still run clone_llvm to ensure that you are on the correct revision.
54+
Make sure to use the revisions specified below, or you will most likely get compilation errors.
7255

56+
Required LLVM/Clang commits:
7357

74-
## Compiling on Linux
58+
[LLVM: see /build/LLVM-commit.](https://github.com/mono/CppSharp/tree/master/build/LLVM-commit)
59+
[Clang: see /build/Clang-commit.](https://github.com/mono/CppSharp/tree/master/build/Clang-commit)
7560

76-
If you do not have native build tools you can install them first with:
61+
To change to the revisions specified above you can run the following commands:
7762

78-
```shell
79-
sudo apt-get install cmake ninja-build build-essential
63+
```
64+
git -C deps/llvm reset --hard <llvm-rev>
65+
git -C deps/llvm/tools/clang reset --hard <clang-rev>
8066
```
8167

82-
And then build LLVM with:
83-
84-
```shell
85-
cd deps/llvm/build
8668

87-
cmake -G Ninja -DCLANG_BUILD_EXAMPLES=false -DCLANG_INCLUDE_DOCS=false -DCLANG_INCLUDE_TESTS=false -DCLANG_INCLUDE_DOCS=false -DCLANG_BUILD_EXAMPLES=false -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_INCLUDE_EXAMPLES=false -DLLVM_INCLUDE_DOCS=false -DLLVM_INCLUDE_TESTS=false ..
8869

89-
ninja
90-
```

docs/GettingStarted.md

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ premake5-osx --file=scripts/LLVM.lua download_llvm # on OSX
3636
premake5-linux-64 --file=scripts/LLVM.lua download_llvm # on Linux
3737
```
3838

39-
Alternatively, if on Windows, just double click on `<CppSharp>/build/DownloadDeps.bat`.
39+
Alternatively, if on Windows, just run `<CppSharp>/build/DownloadDeps.bat` from a Visual Studio command prompt
40+
corresponding to the VS version you want to use.
4041

4142
After this, you should end up with one or multiple `<CppSharp>/build/scripts/llvm-<revision>-<os>-<configuration>` folders
4243
containing the headers and libraries for LLVM.
@@ -50,64 +51,66 @@ Please check the guide in [Compiling LLVM and Clang from source](BuildingLLVM.md
5051

5152
## Compiling on Windows/Visual Studio
5253

54+
1. Generate the VS solution and project files
55+
5356
```shell
5457
cd <CppSharp>\build
55-
5658
GenerateProjects.bat
57-
msbuild vs2013\CppSharp.sln /p:Configuration=Release;Platform=x86
5859
```
5960

60-
Building in *Release* is recommended because else the Clang parser will be
61-
excruciatingly slow.
61+
2. Compile the project
6262

63-
It has been reported that running the solution upgrade process under VS 2013 breaks the build due
64-
to an incompatibility of .NET versions between projects (4.5 and 4.0). If you experience this
65-
problem you can change the targetted .NET version of the projects to be the same or just do not
66-
run the upgrade process after generation.
63+
You can open `CppSharp.sln` and hit F5 or compile via the command line:
6764

68-
## Compiling on Mac OS X
65+
```
66+
msbuild vs2017\CppSharp.sln /p:Configuration=Release;Platform=x86
67+
```
6968

70-
1. Run `./premake5-osx gmake` in `<CppSharp>\build`
71-
2. Build the generated makefiles:
72-
- 32-bit builds: `config=release_x86 make -C gmake`
73-
- 64-bit builds: `config=release_x64 make -C gmake`
69+
Building in *Release* is recommended because else we will use the Clang parser
70+
debug configuration, which will be too slow for practical use beyond debugging.
7471

75-
The version you compile needs to match the version of the Mono VM installed on your
76-
system which you can find by running `mono --version`. The reason for this is because
77-
a 32-bit VM will only be able to load 32-bit shared libraries and vice-versa for 64-bits.
72+
## Compiling on macOS or Linux
7873

79-
## Compiling on Linux
74+
1. Change directory to `<CppSharp>\build`
75+
2. Run `./Compile.sh` to generate the project files and compile the code.
8076

81-
Only 64-bits builds are supported at the moment.
77+
If the above script fails, you can try these equivalent manual steps:
8278

83-
We depend on a somewhat recent version of Mono (.NET 4.5).
84-
Ubuntu 14.04 contains recent enough Mono by default, which you can install with:
79+
1. Generate the Makefiles
8580

86-
```shell
87-
sudo apt-get install mono-devel
81+
```
82+
./premake5-osx gmake # if on OSX
83+
./premake5-linux-64 gmake # if on Linux
8884
```
8985

90-
If you are using another distribution then please look into the [download page](http://www.mono-project.com/download/#download-lin) on the Mono website.
91-
92-
Generate the makefiles, and build CppSharp:
86+
2. Build the generated makefiles:
87+
- 32-bit builds: `make -C gmake config=release_x86`
88+
- 64-bit builds: `make -C gmake config=release_x64`
9389

94-
```shell
95-
cd <CppSharp>/build
96-
./premake5-linux-64 gmake
97-
make -C gmake config=release_x64
98-
```
90+
The version you compile needs to match the version of the Mono VM installed on your
91+
system which you can find by running `mono --version`. The reason for this is because
92+
a 32-bit VM will only be able to load 32-bit shared libraries and vice-versa for 64-bits.
9993

10094
If you need more verbosity from the builds invoke `make` as:
10195

10296
```shell
103-
verbose=true make -C gmake config=release_x64
97+
make -C gmake config=release_x64 verbose=true
10498
```
10599

106-
If you get the following error, please see [issue #625](https://github.com/mono/CppSharp/issues/625#issuecomment-189283549):
100+
## Running the testsuite
107101

108-
```
109-
/usr/include/wchar.h(39,11): fatal: 'stdarg.h' file not found CppSharp has encountered an error while parsing code.
110-
```
102+
1. Change directory to `<CppSharp>\build`
103+
2. Run `./InstallNugets.sh` to install the NUnit test runner from Nuget.
104+
3. Run `./RunTests.sh` to run the tests.
105+
106+
## Linux notes
107+
108+
Only 64-bits builds are supported.
109+
110+
We depend on a recent version of Mono.
111+
112+
Please look into the [download page](http://www.mono-project.com/download/#download-lin) on the
113+
Mono website for official install instructions.
111114

112115
# Generating bindings
113116

0 commit comments

Comments
 (0)