|
| 1 | +#!/bin/bash |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | + |
| 19 | +set -e |
| 20 | +set -u |
| 21 | +set -o pipefail |
| 22 | + |
| 23 | +architecture_type=$(uname -i) |
| 24 | +# Cross-build LLVM for aarch64 when not building natively. |
| 25 | +if [ "$architecture_type" != "aarch64" ]; then |
| 26 | + git clone --depth 1 --branch release/11.x https://github.com/llvm/llvm-project.git |
| 27 | + pushd llvm-project |
| 28 | + |
| 29 | + # First build clang-tblgen and llvm-tblgen |
| 30 | + mkdir build-host |
| 31 | + pushd build-host |
| 32 | + cmake \ |
| 33 | + -G Ninja \ |
| 34 | + -DCMAKE_BUILD_TYPE=Release \ |
| 35 | + -DLLVM_ENABLE_ASSERTIONS=ON \ |
| 36 | + -DLLVM_ENABLE_PROJECTS="llvm;clang;clang-tools-extra" \ |
| 37 | + ../llvm |
| 38 | + ninja clang-tblgen llvm-tblgen |
| 39 | + popd |
| 40 | + |
| 41 | + # Then cross-compile LLVM for Aarch64 |
| 42 | + mkdir build |
| 43 | + pushd build |
| 44 | + CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ cmake \ |
| 45 | + -G Ninja \ |
| 46 | + -DCMAKE_BUILD_TYPE=Release \ |
| 47 | + -DCMAKE_INSTALL_PREFIX=/usr/llvm-aarch64 \ |
| 48 | + -DLLVM_ENABLE_ASSERTIONS=ON \ |
| 49 | + -DLLVM_ENABLE_PROJECTS="llvm;clang" \ |
| 50 | + -DCMAKE_SYSTEM_NAME=Linux \ |
| 51 | + -DLLVM_TABLEGEN=/llvm-project/build-host/bin/llvm-tblgen \ |
| 52 | + -DCLANG_TABLEGEN=/llvm-project/build-host/bin/clang-tblgen \ |
| 53 | + -DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-linux-gnu \ |
| 54 | + -DLLVM_TARGET_ARCH=AArch64 \ |
| 55 | + -DCMAKE_CXX_FLAGS='-march=armv8-a -mtune=cortex-a72' \ |
| 56 | + ../llvm |
| 57 | + ninja install |
| 58 | + popd |
| 59 | + popd |
| 60 | + rm -rf llvm-project |
| 61 | + |
| 62 | + # This is a hack. Cross-compiling LLVM with gcc will cause the llvm-config to be an Aarch64 executable. |
| 63 | + # We need it to be x86 to be able to call it when building TVM. We just copy and use the x86 one instead. |
| 64 | + cp /usr/bin/llvm-config /usr/llvm-aarch64/bin/llvm-config |
| 65 | +fi |
0 commit comments