Skip to content

Commit

Permalink
Merge branch 'femtomc:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe authored Sep 23, 2022
2 parents 5e5f395 + 2d4e0da commit 21c7940
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "mlir-sys"
version = "0.1.2"
authors = ["McCoy R. Becker"]
version = "0.1.3"
authors = ["McCoy R. Becker, Yota Toyama"]
edition = "2021"
description = "Rust bindings to the MLIR C API."
repository = "https://github.com/femtomc/mlir-sys"
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

Rust bindings to [the MLIR C API](https://mlir.llvm.org/docs/CAPI/).

## Install

```sh
cargo add mlir-sys
```

This crate searches an `llvm-config` command on build and uses it to determine build configurations related to LLVM and MLIR. You can also use a `MLIR_SYS_150_PREFIX` environment variable to specify a custom directory of LLVM installation.

## License

[MIT](LICENSE)
27 changes: 25 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,30 @@ use std::error::Error;
use std::fs;
use std::io;
use std::path::Path;
use std::process::exit;
use std::process::Command;
use std::str;

const LLVM_MAJOR_VERSION: usize = 15;

fn main() {
run().unwrap()
if let Err(error) = run() {
eprintln!("{}", error);
exit(1);
}
}

fn run() -> Result<(), Box<dyn Error>> {
let version = llvm_config("--version")?;

if !version.starts_with(&format!("{}.", LLVM_MAJOR_VERSION)) {
return Err(format!(
"failed to find correct version ({}.x.x) of llvm-config (found {})",
LLVM_MAJOR_VERSION, version
)
.into());
}

println!("cargo:rerun-if-changed=wrapper.h");
println!("cargo:rustc-link-search={}", llvm_config("--libdir")?);

Expand Down Expand Up @@ -77,7 +93,14 @@ fn get_system_libcpp() -> Option<&'static str> {
}

fn llvm_config(argument: &str) -> Result<String, Box<dyn Error>> {
let call = format!("llvm-config --link-static {}", argument);
let prefix = env::var("MLIR_SYS_150_PREFIX")
.map(|path| Path::new(&path).join("bin"))
.unwrap_or_default();
let call = format!(
"{} --link-static {}",
prefix.join("llvm-config").display(),
argument
);

Ok(str::from_utf8(
&if cfg!(target_os = "windows") {
Expand Down

0 comments on commit 21c7940

Please sign in to comment.