# Building modified LLVM library from source ## Sources Sources are available at [gitee](https://gitee.com/openharmony/third_party_llvm-project) ## Build script The [script](build_llvm.sh) does not take command line arguments, instead build parameters should be set using environment variables. Some variables are mandatory, others are optional. ### Environment variables list ```bash ### Required variables BUILD_DIR= LLVM_SOURCES=/llvm VERSION=(default: "main") PACKAGE_VERSION=(default: $VERSION) # must match REQUIRED_LLVM_VERSION in libllvmbackend/CMakeLists.txt ### Select targets to build, at least one must be set to "true" BUILD_X86_DEBUG=(default: false) BUILD_X86_RELEASE=(default: false) BUILD_AARCH64_DEBUG=(default: false) BUILD_AARCH64_RELEASE=(default: false) ### Optional variables INSTALL_DIR= (default: "") DO_STRIPPING=(default: true) DO_TAR=(default: true) ### Build tools CC= (default: "/usr/bin/clang-14") CXX= (default: "/usr/bin/clang++-14") STRIP= (default: "/usr/bin/llvm-strip-14") OPTIMIZE_DEBUG=(default: true) ``` **Note! `PACKAGE_VERSION` must be properly set during build to match string constant `REQUIRED_LLVM_VERSION` from `libllvmbackend/CMakeLists.txt`.** ## Example for local user build ```bash cd /home/user/src git clone https://gitee.com/openharmony/third_party_llvm-project.git BUILD_DIR="/home/user/build" \ LLVM_SOURCES="/home/user/src/llvm-for-ark/llvm" \ VERSION="15.0.4-ark99-beta9" \ PACKAGE_VERSION="15.0.4-ark99" \ OPTIMIZE_DEBUG=false \ BUILD_X86_DEBUG=true \ BUILD_AARCH64_DEBUG=true \ bash -x ./build_llvm.sh ``` In this example, only `x86_64` and `arm64` debug versions are built. Then, they can be specified for Ark build, like: * host build: `-DLLVM_TARGET_PATH=/home/user/build/llvm-15.0.4-ark99-beta9-debug-x86_64` * cross-arm64 build: * `-DLLVM_TARGET_PATH=/home/user/build/llvm-15.0.4-ark99-beta9-debug-aarch64` * `-DLLVM_HOST_PATH=/home/user/build/llvm-15.0.4-ark99-beta9-debug-x86_64` ## Example with packaging all necessary versions ```bash INSTALL_DIR="/mnt/scratch/install" \ BUILD_DIR="/mnt/scratch/build" \ LLVM_SOURCES="/mnt/scratch/src/llvm-for-ark/llvm" \ VERSION="15.0.4-ark99-beta9" \ PACKAGE_VERSION="15.0.4-ark99" \ BUILD_X86_DEBUG=true \ BUILD_X86_RELEASE=true \ BUILD_AARCH64_DEBUG=true \ BUILD_AARCH64_RELEASE=true \ bash -x ./build_llvm.sh ```