Skip to content

Commit 3c3b4c6

Browse files
committed
Configure LLVM
1 parent 1019dc9 commit 3c3b4c6

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

.github/workflows/test.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,34 @@ on:
88

99
env:
1010
CARGO_TERM_COLOR: always
11+
LLVM_VERSION: 21
1112

1213
jobs:
1314
build:
14-
1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- uses: actions/checkout@v4
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Install LLVM
22+
run: |-
23+
LLVM_MAJOR_VERSION=21
24+
25+
sudo apt-cache update
26+
27+
wget https://apt.llvm.org/llvm.sh
28+
chmod +x llvm.sh
29+
sudo ./llvm.sh "${LLVM_VERSION}"
30+
rm llvm.sh
31+
32+
# Point llvm-config to llvm-config-$LLVM_VERSION so Rust doesn't whinge about it
33+
sudo ln -sf "$(command -v "llvm-config-${LLVM_VERSION}")" /usr/bin/llvm-config
34+
35+
llvm-config --version
36+
1937
- name: Build
2038
run: cargo build --verbose
39+
2140
- name: Run tests
2241
run: cargo test --verbose

haikulang_llvm/build.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Attempt to avoid pain with LLVM, probably.
2+
fn main() {
3+
let output = std::process::Command::new("llvm-config")
4+
.arg("--prefix")
5+
.output()
6+
.expect(r#"
7+
Failed to run llvm-config. Is llvm-devel installed?
8+
9+
Try one of the following:
10+
11+
# Fedora
12+
- sudo dnf install llvm-devel clang-devel libffi-devel
13+
14+
# Ubuntu
15+
- wget https://apt.llvm.org/llvm.sh
16+
chmod +x llvm.sh
17+
sudo ./llvm.sh 21
18+
rm llvm.sh
19+
"#);
20+
21+
let prefix = std::str::from_utf8(&output.stdout).unwrap().trim();
22+
23+
let version_output = std::process::Command::new("llvm-config")
24+
.arg("--version")
25+
.output()
26+
.unwrap();
27+
28+
let version = std::str::from_utf8(&version_output.stdout).unwrap();
29+
let major_version = version.split('.').next().unwrap();
30+
31+
// This turns "21.x.x" into "LLVM_SYS_211_PREFIX"
32+
println!("cargo:rustc-env=LLVM_SYS_{}1_PREFIX={}", major_version, prefix);
33+
34+
println!("cargo:rustc-link-search=native={}/lib", prefix);
35+
}

0 commit comments

Comments
 (0)