diff --git a/spec/std/llvm/llvm_spec.cr b/spec/std/llvm/llvm_spec.cr index 435be6c85d35..ea2df86f9413 100644 --- a/spec/std/llvm/llvm_spec.cr +++ b/spec/std/llvm/llvm_spec.cr @@ -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 diff --git a/src/llvm.cr b/src/llvm.cr index 5f44889aaf0a..a8d7a6b77818 100644 --- a/src/llvm.cr +++ b/src/llvm.cr @@ -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