Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LLVM.version #15354

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions spec/std/llvm/llvm_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ require "spec"
require "llvm"

describe LLVM do
it ".version" do
LLVM.version.should eq LibLLVM::VERSION
end

describe ".normalize_triple" do
it "works" do
LLVM.normalize_triple("x86_64-apple-macos").should eq("x86_64-apple-macos")
Expand Down
11 changes: 1 addition & 10 deletions src/compiler/crystal/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ module Crystal
{{ read_file("#{__DIR__}/../../VERSION").chomp }}
end

def self.llvm_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
String.build do |io|
io << "Crystal " << version
Expand All @@ -27,7 +18,7 @@ module Crystal

io << "\n\nThe compiler was not built in release mode." unless release_mode?

io << "\n\nLLVM: " << llvm_version
io << "\n\nLLVM: " << LLVM.version
io << "\nDefault target: " << host_target
io << "\n"
end
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/program.cr
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ module Crystal
define_crystal_string_constant "VERSION", Crystal::Config.version, <<-MD
The version of the Crystal compiler.
MD
define_crystal_string_constant "LLVM_VERSION", Crystal::Config.llvm_version, <<-MD
define_crystal_string_constant "LLVM_VERSION", LLVM.version, <<-MD
The version of LLVM used by the Crystal compiler.
MD
define_crystal_string_constant "HOST_TRIPLE", Crystal::Config.host_target.to_s, <<-MD
Expand Down
16 changes: 16 additions & 0 deletions src/llvm.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ require "c/string"
module LLVM
@@initialized = false

# Returns the runtime version of LLVM.
#
# Starting with LLVM 16, this method returns the version as reported by
# `LLVMGetVersion` at runtime. Older versions of LLVM do not expose this
# information, so the value falls back to `LibLLVM::VERSION` which is
# determined at compile time and might slightly be out of sync to the
# dynamic library loaded at runtime.
def self.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.init_x86 : Nil
return if @@initialized_x86
@@initialized_x86 = true
Expand Down
Loading