Skip to content

Commit 6734cbe

Browse files
authored
Add build instructions to the README (#27)
1 parent b909ff3 commit 6734cbe

1 file changed

Lines changed: 128 additions & 0 deletions

File tree

README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
This is the code repository for a series of articles
44
on the [MLIR framework](https://mlir.llvm.org/) for building compilers.
55

6+
## Articles
7+
68
1. [Build System (Getting Started)](https://jeremykun.com/2023/08/10/mlir-getting-started/)
79
2. [Running and Testing a Lowering](https://jeremykun.com/2023/08/10/mlir-running-and-testing-a-lowering/)
810
3. [Writing Our First Pass](https://jeremykun.com/2023/08/10/mlir-writing-our-first-pass/)
@@ -14,3 +16,129 @@ on the [MLIR framework](https://mlir.llvm.org/) for building compilers.
1416
9. [Canonicalizers and Declarative Rewrite Patterns](https://jeremykun.com/2023/09/20/mlir-canonicalizers-and-declarative-rewrite-patterns/)
1517
10. [Dialect Conversion](https://jeremykun.com/2023/10/23/mlir-dialect-conversion/)
1618
11. Lowering through LLVM
19+
20+
21+
## Bazel build
22+
23+
Bazel is one of two supported build systems for this tutorial. The other is
24+
CMake. If you're unfamiliar with Bazel, you can read the tutorials at
25+
[https://bazel.build/start](https://bazel.build/start). Familiarity with Bazel
26+
is not required to build or test, but it is required to follow the articles in
27+
the tutorial series and explained in the first article, [Build System (Getting
28+
Started)](https://jeremykun.com/2023/08/10/mlir-getting-started/). The CMake
29+
build is maintained, but was added at article 10 (Dialect Conversion) and will
30+
not be explained in the articles.
31+
32+
### Prerequisites
33+
34+
Install Bazelisk via instructions at
35+
[https://github.com/bazelbuild/bazelisk#installation](https://github.com/bazelbuild/bazelisk#installation).
36+
This should create the `bazel` command on your system.
37+
38+
You should also have a modern C++ compiler on your system, either `gcc` or
39+
`clang`, which Bazel will detect.
40+
41+
### Build and test
42+
43+
Run
44+
45+
```bash
46+
bazel build ...:all
47+
bazel test ...:all
48+
```
49+
50+
## CMake build
51+
52+
CMake is one of two supported build systems for this tutorial. The other is
53+
Bazel. If you're unfamiliar with CMake, you can read the tutorials at
54+
[https://cmake.org/getting-started/](https://cmake.org/getting-started/).
55+
The CMake build is maintained, but was added at article 10 (Dialect Conversion)
56+
and will not be explained in the articles.
57+
58+
### Prerequisites
59+
60+
* Make sure you have installed everything needed to build LLVM
61+
https://llvm.org/docs/GettingStarted.html#software
62+
* For this recipe Ninja is used so be sure to have it as well installed
63+
https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages
64+
65+
### Checking out the code
66+
67+
Checkout the tutorial including the LLVM dependency (submodules):
68+
69+
```bash
70+
git clone --recurse-submodules https://github.com/j2kun/mlir-tutorial.git
71+
cd mlir-tutorial
72+
```
73+
74+
### Building dependencies
75+
76+
Note: The following steps are suitable for macOs and use ninja as building
77+
system, they should not be hard to adapt for your environment.
78+
79+
*Build LLVM/MLIR*
80+
81+
```bash
82+
#!/bin/sh
83+
84+
BUILD_SYSTEM=Ninja
85+
BUILD_TAG=ninja
86+
THIRDPARTY_LLVM_DIR=$PWD/externals/llvm-project
87+
BUILD_DIR=$THIRDPARTY_LLVM_DIR/build
88+
INSTALL_DIR=$THIRDPARTY_LLVM_DIR/install
89+
90+
mkdir -p $BUILD_DIR
91+
mkdir -p $INSTALL_DIR
92+
93+
pushd $BUILD_DIR
94+
95+
cmake ../llvm -G $BUILD_SYSTEM \
96+
-DCMAKE_CXX_COMPILER="$(xcrun --find clang++)" \
97+
-DCMAKE_C_COMPILER="$(xcrun --find clang)" \
98+
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \
99+
-DLLVM_LOCAL_RPATH=$INSTALL_DIR/lib \
100+
-DLLVM_PARALLEL_COMPILE_JOBS=7 \
101+
-DLLVM_PARALLEL_LINK_JOBS=1 \
102+
-DLLVM_BUILD_EXAMPLES=OFF \
103+
-DLLVM_INSTALL_UTILS=ON \
104+
-DCMAKE_OSX_ARCHITECTURES="$(uname -m)" \
105+
-DCMAKE_BUILD_TYPE=Release \
106+
-DLLVM_ENABLE_ASSERTIONS=ON \
107+
-DLLVM_CCACHE_BUILD=ON \
108+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
109+
-DLLVM_ENABLE_PROJECTS='mlir' \
110+
-DDEFAULT_SYSROOT="$(xcrun --show-sdk-path)" \
111+
-DCMAKE_OSX_SYSROOT="$(xcrun --show-sdk-path)"
112+
113+
cmake --build . --target check-mlir
114+
115+
popd
116+
```
117+
118+
### Build and test
119+
120+
```bash
121+
#!/bin/sh
122+
123+
BUILD_SYSTEM="Ninja"
124+
BUILD_DIR=./build-`echo ${BUILD_SYSTEM}| tr '[:upper:]' '[:lower:]'`
125+
126+
rm -rf $BUILD_DIR
127+
mkdir $BUILD_DIR
128+
pushd $BUILD_DIR
129+
130+
LLVM_BUILD_DIR=externals/llvm-project/build
131+
cmake -G $BUILD_SYSTEM .. \
132+
-DLLVM_DIR="$LLVM_BUILD_DIR/lib/cmake/llvm" \
133+
-DMLIR_DIR="$LLVM_BUILD_DIR/lib/cmake/mlir" \
134+
-DCMAKE_BUILD_TYPE=Debug
135+
136+
popd
137+
138+
cmake --build $BUILD_DIR --target MLIRAffineFullUnrollPasses
139+
cmake --build $BUILD_DIR --target MLIRMulToAddPasses
140+
cmake --build $BUILD_DIR --target mlir-headers
141+
cmake --build $BUILD_DIR --target mlir-doc
142+
cmake --build $BUILD_DIR --target tutorial-opt
143+
cmake --build $BUILD_DIR --target check-mlir-tutorial
144+
```

0 commit comments

Comments
 (0)