-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdevinstall_llvm.sh
More file actions
executable file
·111 lines (94 loc) · 2.68 KB
/
Copy pathdevinstall_llvm.sh
File metadata and controls
executable file
·111 lines (94 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#! /bin/bash -e
trap "echo -e '\nScript interrupted. Exiting gracefully.'; exit 1" SIGINT
# Copyright (C) 2024-2025 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
WORKSPACE=${WORKSPACE:-${HOME}}
LLVM_DIR=${WORKSPACE}/llvm-project
LLVM_BUILD_PATH=${LLVM_DIR}/build
LLVM_INSTALL_PATH=${LLVM_DIR}/install
LLVM_REPO=https://github.com/llvm/llvm-project.git
pip_install() {
if command -v uv &>/dev/null; then
uv pip install "$@"
else
pip install "$@"
fi
}
setup_src() {
echo "Downloading LLVM source code and setting up the environment for building from source..."
if [ ! -d "$LLVM_DIR" ]; then
echo "Cloning the LLVM Project repo $LLVM_REPO to $LLVM_DIR ..."
git clone "$LLVM_REPO" "$LLVM_DIR"
if [ ! -d "$LLVM_DIR" ]; then
echo "$LLVM_DIR not found. ERROR Cloning repository..."
exit 1
else
pushd "$LLVM_DIR" 1>/dev/null || exit 1
if [ -f "${HOME}"/.bashrc.d/00-triton_llvm_commit_hash.sh ]; then
LLVM_GITREF=$(grep LLVM_COMMIT_HASH "${HOME}/.bashrc.d/00-triton_llvm_commit_hash.sh" | cut -d'=' -f 2)
fi
if [ -n "${LLVM_GITREF:-}" ]; then
echo "Checking out LLVM_GITREF $LLVM_GITREF ..."
git checkout "$LLVM_GITREF"
fi
popd 1>/dev/null
fi
else
echo "LLVM repo already present, not cloning ..."
fi
echo "Setting LLVM local build variables in ${HOME}/.bashrc.d/00-llvm_project.sh ..."
tee "${HOME}/.bashrc.d/00-llvm_project.sh" <<EOF
# Using local LLVM build
export LLVM_BUILD_PATH="${LLVM_BUILD_PATH}"
export LLVM_INSTALL_PATH="${LLVM_INSTALL_PATH}"
EOF
if ((${USE_CCACHE:-0} != 0)); then
echo "export LLVM_CCACHE_BUILD=ON" >>"${HOME}/.bashrc.d/00-llvm_project.sh"
fi
}
install_build_deps() {
pushd "$LLVM_DIR" 1>/dev/null || exit 1
if [ -f mlir/python/requirements.txt ]; then
echo "Installing LLVM build dependencies ..."
pip_install -r mlir/python/requirements.txt
fi
popd 1>/dev/null
}
usage() {
cat >&2 <<EOF
Usage: $(basename "$0") [COMMAND]
source Download LLVM's source (if needed) and install the build deps
EOF
}
##
## Main
##
if [ $# -ne 1 ]; then
usage
exit 1
fi
COMMAND=${1,,}
case $COMMAND in
source)
setup_src
install_build_deps
;;
*)
usage
exit 1
;;
esac