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

Refactor LLVM.default_target_triple to avoid regex #13659

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
25 changes: 25 additions & 0 deletions spec/std/llvm/llvm_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,29 @@ describe LLVM do
LLVM.normalize_triple("x86_64-linux-gnu").should eq("x86_64-unknown-linux-gnu")
end
end

it ".default_target_triple" do
triple = LLVM.default_target_triple
{% if flag?(:darwin) %}
triple.should match(/-apple-macosx$/)
{% elsif flag?(:android) %}
triple.should match(/-android$/)
{% elsif flag?(:linux) %}
straight-shoota marked this conversation as resolved.
Show resolved Hide resolved
triple.should match(/-linux/)
{% elsif flag?(:windows) %}
triple.should match(/-windows-/)
{% elsif flag?(:freebsd) %}
triple.should match(/-freebsd/)
{% elsif flag?(:openbsd) %}
triple.should match(/-openbsd/)
{% elsif flag?(:dragonfly) %}
triple.should match(/-dragonfly/)
{% elsif flag?(:netbsd) %}
triple.should match(/-netbsd/)
{% elsif flag?(:wasi) %}
triple.should match(/-wasi/)
{% else %}
pending! "Unknown operating system"
{% end %}
end
end
8 changes: 4 additions & 4 deletions src/llvm.cr
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ module LLVM

def self.default_target_triple : String
chars = LibLLVM.get_default_target_triple
triple = string_and_dispose(chars)
if triple =~ /x86_64-apple-macosx|x86_64-apple-darwin/
case triple = string_and_dispose(chars)
when .starts_with?("x86_64-apple-macosx"), .starts_with?("x86_64-apple-darwin")
# normalize on `macosx` and remove minimum deployment target version
"x86_64-apple-macosx"
elsif triple =~ /aarch64-apple-macosx|aarch64-apple-darwin/
when .starts_with?("aarch64-apple-macosx"), .starts_with?("aarch64-apple-darwin")
# normalize on `macosx` and remove minimum deployment target version
"aarch64-apple-macosx"
elsif triple =~ /aarch64-unknown-linux-android/
when .starts_with?("aarch64-unknown-linux-android")
# remove API version
"aarch64-unknown-linux-android"
else
Expand Down