Add shared library link mode for LLVM/MLIR#82
Merged
Conversation
Auto-detect whether LLVM is installed with static or shared libraries and link accordingly. This enables mlir-sys to work on systems where LLVM is built with shared libraries only (e.g. Gentoo, Fedora). Detection priority: 1. MLIR_SYS_LINK_SHARED env var (explicit override) 2. llvm-config --link-static --libnames (probe for static libs) 3. llvm-config --link-shared --libnames (fallback to shared) When shared, links MLIR, MLIR-C, and LLVM as shared libraries instead of scanning for individual static archives.
raviqqe
reviewed
Mar 14, 2026
Comment on lines
+80
to
83
| if flag.is_empty() { | ||
| continue; | ||
| } | ||
|
|
Member
Author
There was a problem hiding this comment.
llvm-config --system-libs
On my gentoo system its empty, (my gentoo ebuild builds mlir and llvm with shared linkage maybe thats why? i'm not sure)
without the is_empty() check you'd get cargo:rustc-link-lib= with no library name, which would break the build
28afc1c to
edd905d
Compare
Member
|
Thank you for the changes! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently
build.rshardcodes--link-staticand only scans for.aarchives. This breaks on distros like Gentoo and Fedora where LLVM is only packaged as shared libraries.Auto-detect link mode in
detect_link_mode()by probingllvm-configwith--link-staticfirst, then falling back to--link-shared. SetMLIR_SYS_LINK_SHARED=1(ortrue) to force shared mode.In shared mode, links
MLIRandMLIR-Cdirectly instead of enumerating.aarchives.parse_archive_nameis split intoparse_static_lib_nameandparse_shared_lib_name, with the latter handling.so, versioned.so.N, and.dylibsuffixes.--ignore-libllvmis only passed for static builds since it is not valid in shared mode.This probably prevents and fixes #64