-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall_flang
More file actions
executable file
·67 lines (58 loc) · 2.53 KB
/
install_flang
File metadata and controls
executable file
·67 lines (58 loc) · 2.53 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
#!/usr/bin/env bash
# Usage: bash install_flang
#
echo "Deprecated. See install_llvm instead."
exit 1
REPO_NAME="flang"
GIT_ADDR="https://github.com/zaikunzhang/$REPO_NAME.git"
TMP_DIR="$(mktemp -d)"
# If this is not a GitHub-hosted runner, we first check whether flang is already installed in the
# default directory $FLANG_DFT. If it is, we skip the installation. Otherwise, we install flang to
# the temporary directory $FLANG_DIR defined below. Why not install flang to $FLANG_DFT? Because we
# prefer to install it in a temporary directory to avoid polluting the default directory.
FLANG_DFT="$HOME/local/flang"
if [[ "$GITHUB_ACTIONS" != "true" || "$RUNNER_ENVIRONMENT" != "github-hosted" ]]; then
# We assume that ncurses are already installed on self-hosted runners.
printf "\nThe runner is not hosted by GitHub. Skip installation of ncurses.\n"
if [[ -d $FLANG_DFT && -f $FLANG_DFT/bin/flang && -f $FLANG_DFT/bin/flang ]] ;then
echo "PATH=$PATH:$FLANG_DFT/bin" >> "$GITHUB_ENV"
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$FLANG_DFT/lib" >> "$GITHUB_ENV"
printf "\nflang is already installed. Skip installation.\n"
exit 0
fi
else
if [[ "$(uname -s)" == Darwin ]] ; then # macOS
brew update || true
brew install ncurses git
else # Assume Linux
sudo apt update || true
sudo apt install -y libncurses* git # libncurses* needed for libtinfo.so
fi
fi
if [[ "$(uname -s)" == Darwin ]] ; then # macOS
ARCH=macos_arm # LLVM does not provide macos_x86 flang binaries as of February 2026
else # Assume Linux
ARCH=$(uname -m)
fi
# Clone the flang repository to the temporary directory
git clone "$GIT_ADDR" "$TMP_DIR/$REPO_NAME"
FLANG_ARCHIVE="$TMP_DIR/$REPO_NAME/$ARCH/flang.tar.xz"
# Decompress the flang archive
mkdir -p "$HOME"/tmp
FLANG_DIR=$(mktemp -d -p "$HOME"/tmp/)
cat "${FLANG_ARCHIVE}".* | tar -xJ --directory "$FLANG_DIR"
FLANG_DIR="$FLANG_DIR/flang"
# Remove the temporary directory
rm -rf "$TMP_DIR"
# Set environment variable for subsequent steps
# N.B.: The following lines will not work if this script is invoked with sudo.
# Put flang/bin to the beginning of PATH, in case there is another flang in PATH, e.g., from AOCC.
echo "PATH=$FLANG_DIR/bin:$PATH" >> "$GITHUB_ENV"
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$FLANG_DIR/lib" >> "$GITHUB_ENV"
# Show the result of the installation.
export PATH=$FLANG_DIR/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$FLANG_DIR/lib
echo "The flang installed is:"
flang --version
echo "The path to flang is:"
command -v flang