Skip to content

Commit 10bbd4c

Browse files
author
Nicholas Rodrigues Lordello
committed
Update instructions for building LLVM intrinsics
1 parent 211f35a commit 10bbd4c

3 files changed

Lines changed: 27 additions & 12 deletions

File tree

.github/workflows/rust.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
cargo test --release
2626
- name: Test LLVM Intrinsics
2727
run: |
28+
sudo apt update && sudo apt install clang-16
2829
cargo clippy --features llvm-intrinsics --all-targets -- -D warnings
2930
cargo test --features llvm-intrinsics
3031
cargo test --features llvm-intrinsics --release

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,24 @@ in order to actually take advantage of the the optimized assembly:
9999
RUSTFLAGS="-Clinker-plugin-lto -Clinker=clang -Clink-arg=-fuse-ld=lld" cargo build
100100
```
101101

102+
Note that **the `clang` version must match the `rustc` LLVM version**. If not,
103+
it is possible to encounter errors when running the `ethnum-intrinsics` build
104+
script. You can verify the LLVM version used by `rustc` with:
105+
106+
```sh
107+
rustc --version --verbose | grep LLVM
108+
```
109+
110+
In particular, this affects macOS which ships its own `clang` binary. The
111+
`ethnum-intrinsics` build script accepts a `CLANG` environment variable to
112+
specity a specific `clang` executable path to use. Using the major LLVM
113+
version from the command above:
114+
115+
```
116+
brew install llvm@${LLVM_VERSION}
117+
CLANG=/opt/homebrew/opt/llvm@${LLVM_VERSION}/bin/clang cargo build
118+
```
119+
102120
### API Stability
103121

104122
The instinsics are exported under `ethnum::intrinsics`. That being said, be

intrinsics/build/main.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ use cc::Build;
1515
use std::{env, error::Error, fs, path::PathBuf, process::Command};
1616

1717
fn main() -> Result<(), Box<dyn Error>> {
18+
println!("cargo:rerun-if-env-changed=CLANG");
19+
let clang = env::var("CLANG")
20+
.map(PathBuf::from)
21+
.unwrap_or_else(|_| "clang".into());
22+
1823
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
1924

2025
let template = {
@@ -35,24 +40,15 @@ fn main() -> Result<(), Box<dyn Error>> {
3540
let source = template
3641
.replace("i128", "i256")
3742
.replace(" 127", " 255")
38-
.replace("dereferenceable(16)", "dereferenceable(32)")
39-
// TODO(nlordell): Figure out why Clang doesn't like these
40-
.replace("mustprogress ", "")
41-
.replace("noundef ", "")
42-
.replace("memory(argmem: readwrite) ", "")
43-
.replace("memory(argmem: read) ", "")
44-
.replace("memory(none) ", "")
45-
.replace(", !!1", "");
43+
.replace("dereferenceable(16)", "dereferenceable(32)");
44+
4645
let path = out_dir.join("intrinsics.ll");
4746
fs::write(&path, source)?;
4847
path
4948
};
5049

5150
let mut build = Build::new();
52-
build
53-
.compiler("clang")
54-
.file(intrinsics_ir_path)
55-
.opt_level(3);
51+
build.compiler(&clang).file(intrinsics_ir_path).opt_level(3);
5652

5753
let linker_plugin_lto =
5854
matches!(env::var("RUSTFLAGS"), Ok(flags) if flags.contains("-Clinker-plugin-lto"));

0 commit comments

Comments
 (0)