• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Building modified LLVM library from source
2
3## Sources
4
5Sources are available at [gitee](https://gitee.com/openharmony/third_party_llvm-project)
6
7## Build script
8
9The [script](build_llvm.sh) does not take command line arguments, instead build parameters should be set using environment variables.
10
11Some variables are mandatory, others are optional.
12
13### Environment variables list
14
15```bash
16### Required variables
17BUILD_DIR=<directory where building process takes place>
18LLVM_SOURCES=<directory with sources>/llvm
19VERSION=<version string, which is included in build/install directory names>(default: "main")
20PACKAGE_VERSION=<kit version>(default: $VERSION) # must match REQUIRED_LLVM_VERSION in libllvmbackend/CMakeLists.txt
21
22### Select targets to build, at least one must be set to "true"
23BUILD_X86_DEBUG=<debug version for x86_64 architecure>(default: false)
24BUILD_X86_RELEASE=<release version for x86_64 architecure>(default: false)
25BUILD_AARCH64_DEBUG=<debug version for arm64 architecure>(default: false)
26BUILD_AARCH64_RELEASE=<release version for arm64 architecure>(default: false)
27
28### Optional variables
29INSTALL_DIR=<directory for installation, empty means "do not install"> (default: "")
30
31DO_STRIPPING=<when install, strip libraries before installation>(default: true)
32DO_TAR=<when install, also pack llvm-$VERSION-*-*.tar.xz archives for corresponding folders>(default: true)
33
34### Build tools
35CC=<C compiler> (default: "/usr/bin/clang-14")
36CXX=<C++ compiler> (default: "/usr/bin/clang++-14")
37STRIP=<strip utility> (default: "/usr/bin/llvm-strip-14")
38OPTIMIZE_DEBUG=<compile debug version with -O2>(default: true)
39```
40
41**Note! `PACKAGE_VERSION` must be properly set during build to match string
42constant `REQUIRED_LLVM_VERSION` from `libllvmbackend/CMakeLists.txt`.**
43
44## Example for local user build
45
46```bash
47cd /home/user/src
48git clone https://gitee.com/openharmony/third_party_llvm-project.git
49
50BUILD_DIR="/home/user/build" \
51LLVM_SOURCES="/home/user/src/llvm-for-ark/llvm" \
52VERSION="15.0.4-ark99-beta9" \
53PACKAGE_VERSION="15.0.4-ark99" \
54OPTIMIZE_DEBUG=false \
55BUILD_X86_DEBUG=true \
56BUILD_AARCH64_DEBUG=true \
57bash -x ./build_llvm.sh
58```
59
60In this example, only `x86_64` and `arm64` debug versions are built. Then, they can be specified for Ark build, like:
61* host build: `-DLLVM_TARGET_PATH=/home/user/build/llvm-15.0.4-ark99-beta9-debug-x86_64`
62* cross-arm64 build:
63   * `-DLLVM_TARGET_PATH=/home/user/build/llvm-15.0.4-ark99-beta9-debug-aarch64`
64   * `-DLLVM_HOST_PATH=/home/user/build/llvm-15.0.4-ark99-beta9-debug-x86_64`
65
66## Example with packaging all necessary versions
67
68```bash
69INSTALL_DIR="/mnt/scratch/install" \
70BUILD_DIR="/mnt/scratch/build" \
71LLVM_SOURCES="/mnt/scratch/src/llvm-for-ark/llvm" \
72VERSION="15.0.4-ark99-beta9" \
73PACKAGE_VERSION="15.0.4-ark99" \
74BUILD_X86_DEBUG=true \
75BUILD_X86_RELEASE=true \
76BUILD_AARCH64_DEBUG=true \
77BUILD_AARCH64_RELEASE=true \
78bash -x ./build_llvm.sh
79```
80