Skip to content

Commit 6d03c97

Browse files
cmaginaclaude
andcommitted
feat: add LLVM setup script for modular installation
Add scripts/setup_llvm.sh to support LLVM installation and configuration within containers. This script: - Downloads LLVM source from GitHub when not mounted as a volume - Installs build dependencies for LLVM compilation - Provides a clean interface for LLVM integration The script supports the INSTALL_LLVM environment variable with 'source' or 'skip' options, enabling flexible LLVM setup for different container configurations. This is part of the modular script architecture introduced in PR #115. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 0a65511 commit 6d03c97

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

scripts/setup_llvm.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#! /bin/bash -e
2+
3+
trap "echo -e '\nScript interrupted. Exiting gracefully.'; exit 1" SIGINT
4+
5+
# Copyright (C) 2024-2025 Red Hat, Inc.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# SPDX-License-Identifier: Apache-2.0
20+
set -euo pipefail
21+
22+
WORKSPACE=${WORKSPACE:-${HOME}}
23+
24+
LLVM_DIR=${WORKSPACE}/llvm-project
25+
LLVM_REPO=https://github.com/llvm/llvm-project.git
26+
LLVM_BUILD_PATH=$LLVM_DIR/build
27+
28+
setup_src() {
29+
if [ ! -d "$LLVM_DIR" ]; then
30+
echo "Cloning the LLVM Project repo $LLVM_REPO to $LLVM_DIR ..."
31+
git clone "$LLVM_REPO" "$LLVM_DIR"
32+
if [ ! -d "$LLVM_DIR" ]; then
33+
echo "$LLVM_DIR not found. ERROR Cloning repository..."
34+
exit 1
35+
else
36+
pushd "$LLVM_DIR" 1>/dev/null || exit 1
37+
git fetch origin
38+
39+
[ -f "${HOME}"/.bashrc ] && source "${HOME}"/.bashrc
40+
41+
if [ -n "${LLVM_GITREF:-}" ]; then
42+
git checkout "$LLVM_GITREF"
43+
fi
44+
popd 1>/dev/null
45+
fi
46+
fi
47+
48+
echo "Adding LLVM_BUILD_PATH to ${HOME}/.bashrc ..."
49+
echo "export LLVM_BUILD_PATH=$LLVM_BUILD_PATH" >>"${HOME}/.bashrc"
50+
echo "Run 'source ${HOME}/.bashrc' to update the current shell"
51+
}
52+
53+
install_build_deps() {
54+
pushd "$LLVM_DIR" 1>/dev/null || exit 1
55+
if [ -f mlir/python/requirements.txt ]; then
56+
echo "Installing LLVM build dependencies ..."
57+
uv pip install -r mlir/python/requirements.txt
58+
fi
59+
popd 1>/dev/null
60+
}
61+
62+
usage() {
63+
cat >&2 <<EOF
64+
Usage: $(basename "$0") [COMMAND]
65+
source Download LLVM's source (if needed) and install the build deps
66+
EOF
67+
}
68+
69+
##
70+
## Main
71+
##
72+
73+
if [ $# -ne 1 ]; then
74+
usage
75+
exit 1
76+
fi
77+
78+
COMMAND=${1,,}
79+
80+
case $COMMAND in
81+
source)
82+
echo "Setting up the environment for building LLVM ..."
83+
setup_src
84+
install_build_deps
85+
;;
86+
*)
87+
usage
88+
exit 1
89+
;;
90+
esac

0 commit comments

Comments
 (0)