Skip to content

Commit

Permalink
Refactor LLVM.default_target_triple to avoid regex
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Jul 12, 2023
1 parent 6f97ec7 commit 8dd544f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
23 changes: 23 additions & 0 deletions spec/std/llvm/llvm_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,27 @@ 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?(:linux) %}
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?(:was) %}
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

0 comments on commit 8dd544f

Please sign in to comment.