-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall_aocc
More file actions
executable file
·129 lines (109 loc) · 5.03 KB
/
install_aocc
File metadata and controls
executable file
·129 lines (109 loc) · 5.03 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env bash
# Script to install the AMD AOCC for Ubuntu (amd64/x86_64)
# Usage: bash install_aocc [RETRY_MAX] [RETRY_DELAY_SECONDS]
#
# N.B.: The most technical part is to download the correct .deb package from GitHub releases.
# After that, installation is done via a simple invocation of apt.
set -uo pipefail
# Download URL for AOCC 5.1.0. Updated on 20260214. See
# https://www.amd.com/fr/developer/aocc.html
# https://github.com/fortran-lang/setup-fortran/issues/188
DOWNLOAD_URL="https://download.amd.com/developer/eula/aocc/aocc-5-1/aocc-compiler-5.1.0_1_amd64.deb"
SHA256SUM="42f9ed0713a8fe269d5a5b40b1992a5380ff59b4441e58d38eb9f27df5bfe6df"
# Default directory where AOCC is installed. Modify if needed.
AOCC_DIR="/opt/AMD"
echo -e "\n---------------------------------------------------------------------------------------------------"
echo -e "N.B.: We suppose that the default installation directory for AOCC is\n\n\t${AOCC_DIR}\n"
echo -e "After installation, please verify that AOCC is installed there by checking for the flang binary:\n"
echo -e "\tls ${AOCC_DIR}/aocc-compiler-VERSION/bin/flang\n"
echo -e "If it is not found there, please modify the AOCC_DIR variable in the script and re-run it."
echo -e "---------------------------------------------------------------------------------------------------\n"
# The installation may fail due to network issues, so we retry until it works. We retry for at most
# $RETRY_MAX times with a delay of $RETRY_DELAY_SECONDS seconds between attempts.
if [[ "$#" -ge 1 ]]; then
RETRY_MAX="$1"
else
RETRY_MAX=5
fi
if [[ "$#" -ge 2 ]]; then
RETRY_DELAY_SECONDS="$2"
else
RETRY_DELAY_SECONDS=10
fi
# Allow update to fail (|| true) but proceed to install
sudo apt update || true
sudo apt install -y curl
# Make a temp directory and move into it
TMP_DIR="$(mktemp -d)"
cleanup() {
# Only remove if it still exists
[[ -n "${TMP_DIR:-}" && -d "${TMP_DIR}" ]] && rm -rf -- "${TMP_DIR}"
TMP_DIR="" # Prevent double cleanup
}
trap cleanup EXIT
echo "--> Created temporary directory: ${TMP_DIR}"
cd "${TMP_DIR}" || exit 1
echo "--> Changed to ${TMP_DIR}"
FILENAME="${TMP_DIR}/aocc.deb"
# Create a custom curl wrapper to enforce HTTP/1.1 and IPv4, with retries and timeouts.
# Useful in CI environments with occasional network issues.
cat >"$TMP_DIR/curl" <<'EOF'
#!/usr/bin/env bash
exec /usr/bin/curl --http1.1 -4 -L -C - --retry 5 --retry-connrefused --retry-delay 5 --no-keepalive --limit-rate 50M --connect-timeout 30 --max-time 1800 "$@"
EOF
chmod +x "$TMP_DIR/curl"
export PATH="$TMP_DIR:$PATH"
type curl
# Install AOCC
# See https://www.amd.com/fr/developer/aocc.html
# We retry for at most $RETRY_MAX times with a delay of $RETRY_DELAY_SECONDS seconds between attempts.
RETRY_TIMES=0
while true; do
# Download the package
curl -fL -o "${FILENAME}" "${DOWNLOAD_URL}"
echo "--> Downloaded: ${FILENAME}"
# Verify it's a valid .deb file
if ! echo "${SHA256SUM} ${FILENAME}" | sha256sum -c || ! dpkg-deb -I "${FILENAME}" ; then
echo "Warning: Downloaded file does not match the sha256sum or is not a valid .deb package." >&2
else
# Install the package (apt resolves dependencies; dpkg alone does not)
echo "--> Installing the package..."
sudo apt install -y "${FILENAME}"
# Verify installation
ADIR="$(find "${AOCC_DIR}" -maxdepth 1 -name "aocc-compiler*" -type d -print | sort -V | tail -n 1)"
if [[ -z "$ADIR" ]]; then
echo "Warning: AOCC directory not found after the installation, which probably failed." >&2
# continue to retry...
else
AFLANG=$(find -L "${ADIR}" -type f -name flang -exec test -x {} \; -print 2>/dev/null | sort | tail -n 1)
[[ -n "$AFLANG" && -x "$AFLANG" ]] && break || echo "Warning: AOCC flang not found or not executable after the installation, which probably failed." >&2
fi
fi
RETRY_TIMES=$((RETRY_TIMES + 1))
if [ $RETRY_TIMES -ge "$RETRY_MAX" ]; then
echo "Error: Installation failed after $RETRY_TIMES attempts." >&2
exit 1
else
echo "Retrying in $RETRY_DELAY_SECONDS seconds ... (Attempt: $RETRY_TIMES)"
rm -f -- "${FILENAME}"
sleep "$RETRY_DELAY_SECONDS"
fi
done
# Final messages
echo "--> AOCC installation completed."
echo -e "\nThe AOCC flang version is:\n"
$AFLANG --version
echo -e "\nThe path to AOCC flang is:\n"
echo "$AFLANG"
echo -e "\nTo use AOCC, you may need to add to your PATH:"
echo -e "\n\texport PATH=\$PATH:$(dirname "$AFLANG")\n"
echo "Maybe also set LD_LIBRARY_PATH:"
echo -e "\n\texport LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$(dirname "$(dirname "$AFLANG")")/lib\n"
echo -e "Add these lines to your ~/.bashrc or ~/.profile for persistence.\n"
# Set environment variable for subsequent steps if running in GitHub Actions
if [[ -n "${GITHUB_ENV:-}" ]]; then
echo "PATH=$PATH:$ADIR/bin" >> "$GITHUB_ENV"
# The following line makes AOCC Flang available as 'aoccflang' in the subsequent steps.
sudo ln -s "$ADIR"/bin/flang "$ADIR"/bin/aoccflang
fi
# Cleanup is handled by trap on EXIT