Skip to content

Commit 81e813d

Browse files
authored
Leverage another LLVM binary to locate current clang binary (#23)
* Leverage another LLVM binary to locate current clang binary Different distros package LLVM / clang into different setups: * Fedora 41's clang package provides clang, clang-19 and llvm-ar * Ubuntu 24.04's clang package provides clang, clang-18 and llvm-ar-18 Previously, we rely on clang's binary name to infer names for other binaries. But given the above packaging reality, relying on binary clang introduces ambiguity. This commit changes the code so we now rely on another binary, such as llvm-strip or llvm-strip-18 to detect the suffix, and then piece together the binary names we will invoke. * Add sudo permission in CI * Eliminate rev command for windows usage
1 parent bda9341 commit 81e813d

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

.github/workflows/rust.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ jobs:
1616

1717
steps:
1818
- uses: actions/checkout@v3
19-
- name: Install llvm 18
20-
run: wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 18 && rm llvm.sh
19+
- name: Install llvm
20+
run: sudo apt update && sudo apt install -y clang # This requires Ubuntu 24.04 or later
2121
- name: Install cargo generate
2222
run: cargo install cargo-generate
2323
- name: Generate workspace
@@ -37,18 +37,16 @@ jobs:
3737
run: cd test-workspace && echo "1.75.0" > rust-toolchain
3838
- name: Install riscv64 target
3939
run: cd test-workspace && rustup target add riscv64imac-unknown-none-elf
40-
# TODO: Ubuntu 24.04 ships a clang package with clang, clang-18 and llvm-ar-18, while fedora ships a clang package with
41-
# clang, clang-19 and llvm-ar. We will need to deal with this quirk between different distros.
4240
- name: Run all checks
43-
run: cd test-workspace && CLANG=clang-18 make build test check clippy
41+
run: cd test-workspace && make build test check clippy
4442
- name: Reproducible build runs
4543
run: cd test-workspace && ./scripts/reproducible_build_docker --update && ./scripts/reproducible_build_docker --no-clean
4644
- name: Generate standalone contract
4745
run: cargo generate --path . standalone-contract --name test-contract
4846
- name: Lock Rust version
4947
run: cd test-contract && echo "1.75.0" > rust-toolchain
5048
- name: Run all checks
51-
run: cd test-contract && CLANG=clang-18 make build test check clippy
49+
run: cd test-contract && make build test check clippy
5250
- name: Reproducible build runs
5351
run: cd test-contract && ./scripts/reproducible_build_docker --update && ./scripts/reproducible_build_docker --no-clean
5452

standalone-contract/scripts/find_clang

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,29 @@ if [[ -n "${CLANG}" ]]; then
77
exit 0
88
fi
99

10-
CANDIDATES=("clang" "clang-16" "clang-17" "clang-18")
10+
# To cope with packaging messes from different distros, we would search
11+
# for a different binary other than clang, then convert it back to clang
12+
# at the end.
13+
SEARCH_TARGET="${SEARCH_TARGET:-llvm-strip}"
14+
15+
CANDIDATES=("${SEARCH_TARGET}" "${SEARCH_TARGET}-19" "${SEARCH_TARGET}-18" "${SEARCH_TARGET}-17" "${SEARCH_TARGET}-16")
1116

1217
BREW_PREFIX=$(brew --prefix 2> /dev/null)
1318
if [[ -n "${BREW_PREFIX}" ]]; then
1419
CANDIDATES+=(
15-
"${BREW_PREFIX}/opt/llvm/bin/clang"
16-
"${BREW_PREFIX}/opt/llvm@16/bin/clang"
17-
"${BREW_PREFIX}/opt/llvm@17/bin/clang"
18-
"${BREW_PREFIX}/opt/llvm@18/bin/clang"
20+
"${BREW_PREFIX}/opt/llvm/bin/${SEARCH_TARGET}"
21+
"${BREW_PREFIX}/opt/llvm@19/bin/${SEARCH_TARGET}"
22+
"${BREW_PREFIX}/opt/llvm@18/bin/${SEARCH_TARGET}"
23+
"${BREW_PREFIX}/opt/llvm@17/bin/${SEARCH_TARGET}"
24+
"${BREW_PREFIX}/opt/llvm@16/bin/${SEARCH_TARGET}"
1925
)
2026
fi
2127

2228
for candidate in ${CANDIDATES[@]}; do
23-
OUTPUT=$($candidate -dumpversion 2> /dev/null | cut -d'.' -f 1)
29+
OUTPUT=$($candidate --version 2> /dev/null | grep 'version [0-9]' | head -n 1 | cut -d'.' -f 1 | grep -o '[0-9][0-9]*')
2430

2531
if [[ $((OUTPUT)) -ge 16 ]]; then
26-
echo "$candidate"
32+
echo "${candidate/${SEARCH_TARGET}/clang}"
2733
exit 0
2834
fi
2935
done

workspace/scripts/find_clang

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,29 @@ if [[ -n "${CLANG}" ]]; then
77
exit 0
88
fi
99

10-
CANDIDATES=("clang" "clang-16" "clang-17" "clang-18")
10+
# To cope with packaging messes from different distros, we would search
11+
# for a different binary other than clang, then convert it back to clang
12+
# at the end.
13+
SEARCH_TARGET="${SEARCH_TARGET:-llvm-strip}"
14+
15+
CANDIDATES=("${SEARCH_TARGET}" "${SEARCH_TARGET}-19" "${SEARCH_TARGET}-18" "${SEARCH_TARGET}-17" "${SEARCH_TARGET}-16")
1116

1217
BREW_PREFIX=$(brew --prefix 2> /dev/null)
1318
if [[ -n "${BREW_PREFIX}" ]]; then
1419
CANDIDATES+=(
15-
"${BREW_PREFIX}/opt/llvm/bin/clang"
16-
"${BREW_PREFIX}/opt/llvm@16/bin/clang"
17-
"${BREW_PREFIX}/opt/llvm@17/bin/clang"
18-
"${BREW_PREFIX}/opt/llvm@18/bin/clang"
20+
"${BREW_PREFIX}/opt/llvm/bin/${SEARCH_TARGET}"
21+
"${BREW_PREFIX}/opt/llvm@19/bin/${SEARCH_TARGET}"
22+
"${BREW_PREFIX}/opt/llvm@18/bin/${SEARCH_TARGET}"
23+
"${BREW_PREFIX}/opt/llvm@17/bin/${SEARCH_TARGET}"
24+
"${BREW_PREFIX}/opt/llvm@16/bin/${SEARCH_TARGET}"
1925
)
2026
fi
2127

2228
for candidate in ${CANDIDATES[@]}; do
23-
OUTPUT=$($candidate -dumpversion 2> /dev/null | cut -d'.' -f 1)
29+
OUTPUT=$($candidate --version 2> /dev/null | grep 'version [0-9]' | head -n 1 | cut -d'.' -f 1 | grep -o '[0-9][0-9]*')
2430

2531
if [[ $((OUTPUT)) -ge 16 ]]; then
26-
echo "$candidate"
32+
echo "${candidate/${SEARCH_TARGET}/clang}"
2733
exit 0
2834
fi
2935
done

0 commit comments

Comments
 (0)