Skip to content

Add a bundled mode to download LLVM automatically in the build.rs#68

Open
marcantoinem wants to merge 14 commits into
mlir-rs:mainfrom
marcantoinem:bundled
Open

Add a bundled mode to download LLVM automatically in the build.rs#68
marcantoinem wants to merge 14 commits into
mlir-rs:mainfrom
marcantoinem:bundled

Conversation

@marcantoinem

@marcantoinem marcantoinem commented Jun 11, 2025

Copy link
Copy Markdown

I'm writing a CPU backend in https://github.com/tracel-ai/cubecl and I needed to make mlir-sys a bit more portable and add a way to not depend on the system installation of llvm which could not be the good version. I wrote a crate to add this capability to tblgen-rs also. https://github.com/marcantoinem/llvm-bundler-rs The crates use a github action to get a specific version llvm compile it and compress it into a Github release that is then downloaded during compilation. I would love to merge it upstream. It also contains fixes to allow static linking for MLIR by reading the mlir dependency cmake and doing a topological sort. I would like to move this crate in the mlir-rs organisation to make it more trustworthy.

It also support only linux for the moment, but I will add MacOs and Windows support soon.

@femtomc

femtomc commented Sep 16, 2025

Copy link
Copy Markdown
Collaborator

Thanks for this! Sorry for delay in looking at this.

Comment thread build.rs
bindgen::builder()
.header("wrapper.h")
.clang_arg(format!("-I{}", llvm_config("--includedir")?))
.clang_arg("-I/usr/include")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wont work on nixos

better something like

// In build.rs
let mut builder = bindgen::Builder::default()
    .header("wrapper.h")
    .clang_arg(format!("-I{}", llvm_config("--includedir")?));

// Only add system paths if explicitly provided via env var, 
// otherwise let the compiler/bindgen find them itself.
if let Ok(extra_include) = std::env::var("BINDGEN_EXTRA_CLANG_ARGS") {
    builder = builder.clang_arg(extra_include);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants