Skip to content

Commit

Permalink
Query runtime version of LLVM (#15355)
Browse files Browse the repository at this point in the history
Use the runtime version of libllvm (via `LLVMGetVersion`, if available) for `crystal --version` and `Crystal::LLVM_VERSION` constant. The version of a dynamically loaded library might differ from `LibLLVM::VERSION` which is the version at build time.
  • Loading branch information
straight-shoota authored Jan 20, 2025
1 parent c4682db commit 39aaae5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/compiler/crystal/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ module Crystal
end

def self.llvm_version
LibLLVM::VERSION
{% if LibLLVM.has_method?(:get_version) %}
LibLLVM.get_version(out major, out minor, out patch)
"#{major}.#{minor}.#{patch}"
{% else %}
LibLLVM::VERSION
{% end %}
end

def self.description
Expand Down
4 changes: 4 additions & 0 deletions src/llvm/lib_llvm/core.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ lib LibLLVM

fun dispose_message = LLVMDisposeMessage(message : Char*)

{% unless LibLLVM::IS_LT_160 %}
fun get_version = LLVMGetVersion(major : UInt*, minor : UInt*, patch : UInt*) : Void
{% end %}

fun create_context = LLVMContextCreate : ContextRef
fun dispose_context = LLVMContextDispose(c : ContextRef)

Expand Down

0 comments on commit 39aaae5

Please sign in to comment.