@@ -32,9 +32,6 @@ class Llvm < Formula
32
32
sha256 cellar : :any_skip_relocation , x86_64_linux : "479d06278bca8d5a7b8863f003ca127641ffef9c734976eee34fe8c0cc01d763"
33
33
end
34
34
35
- # Clang cannot find system headers if Xcode CLT is not installed
36
- pour_bottle? only_if : :clt_installed
37
-
38
35
keg_only :provided_by_macos
39
36
40
37
# https://llvm.org/docs/GettingStarted.html#requirement
@@ -449,16 +446,9 @@ def install
449
446
xctoolchain . parent . install_symlink xctoolchain . basename . to_s => "LLVM#{ soversion } .xctoolchain"
450
447
451
448
# Write config files for each macOS major version so that this works across OS upgrades.
452
- # TODO: replace this with a call to `MacOSVersion.kernel_major_version` once this is in a release tag:
453
- # https://github.com/Homebrew/brew/pull/18674
454
- {
455
- 11 => 20 ,
456
- 12 => 21 ,
457
- 13 => 22 ,
458
- 14 => 23 ,
459
- 15 => 24 ,
460
- } . each do |macos_version , kernel_version |
461
- write_config_files ( macos_version , kernel_version , Hardware ::CPU . arch )
449
+ MacOSVersion ::SYMBOLS . each_value do |v |
450
+ macos_version = MacOSVersion . new ( v )
451
+ write_config_files ( macos_version , MacOSVersion . kernel_major_version ( macos_version ) , Hardware ::CPU . arch )
462
452
end
463
453
464
454
# Also write an unversioned config file as fallback
@@ -503,20 +493,37 @@ def write_config_files(macos_version, kernel_version, arch)
503
493
504
494
arches = Set . new ( [ :arm64 , :x86_64 ] )
505
495
arches << arch
496
+ sysroot = if macos_version >= "10.14" || ( macos_version . blank? && kernel_version . blank? )
497
+ "#{ MacOS ::CLT ::PKG_PATH } /SDKs/MacOSX#{ macos_version } .sdk"
498
+ else
499
+ "/"
500
+ end
506
501
507
- arches . each do |target_arch |
508
- target_triple = "#{ target_arch } -apple-darwin#{ kernel_version } "
509
- ( clang_config_file_dir /"#{ target_triple } .cfg" ) . atomic_write <<~CONFIG
510
- --sysroot=#{ MacOS ::CLT ::PKG_PATH } /SDKs/MacOSX#{ macos_version } .sdk
511
- CONFIG
502
+ {
503
+ darwin : kernel_version ,
504
+ macosx : macos_version ,
505
+ } . each do |system , version |
506
+ arches . each do |target_arch |
507
+ config_file = "#{ target_arch } -apple-#{ system } #{ version } .cfg"
508
+ ( clang_config_file_dir /config_file ) . atomic_write <<~CONFIG
509
+ --sysroot=#{ sysroot }
510
+ CONFIG
511
+ end
512
512
end
513
513
end
514
514
515
515
def post_install
516
516
return unless OS . mac?
517
- return if ( clang_config_file_dir /"#{ Hardware ::CPU . arch } -apple-darwin#{ OS . kernel_version . major } .cfg" ) . exist?
518
517
519
- write_config_files ( MacOS . version . major , OS . kernel_version . major , Hardware ::CPU . arch )
518
+ config_files = {
519
+ darwin : OS . kernel_version . major ,
520
+ macosx : MacOS . version ,
521
+ } . map do |system , version |
522
+ clang_config_file_dir /"#{ Hardware ::CPU . arch } -apple-#{ system } #{ version } .cfg"
523
+ end
524
+ return if config_files . all? ( &:exist? )
525
+
526
+ write_config_files ( MacOS . version , OS . kernel_version . major , Hardware ::CPU . arch )
520
527
end
521
528
522
529
def caveats
@@ -534,6 +541,10 @@ def caveats
534
541
on_macos do
535
542
s += <<~EOS
536
543
544
+ Using `clang`, `clang++`, etc., requires a CLT installation at `/Library/Developer/CommandLineTools`.
545
+ If you don't want to install the CLT, you can write appropriate configuration files pointing to your
546
+ SDK at ~/.config/clang.
547
+
537
548
To use the bundled libunwind please use the following LDFLAGS:
538
549
LDFLAGS="-L#{ opt_lib } /unwind -lunwind"
539
550
@@ -618,6 +629,16 @@ def caveats
618
629
assert_equal "Hello World!" , shell_output ( "./testCLT++" ) . chomp
619
630
system bin /"clang" , "-v" , "test.c" , "-o" , "testCLT"
620
631
assert_equal "Hello World!" , shell_output ( "./testCLT" ) . chomp
632
+
633
+ target = "#{ Hardware ::CPU . arch } -apple-macosx#{ MacOS . full_version } "
634
+ system bin /"clang-cpp" , "-v" , "--target=#{ target } " , "test.c"
635
+ system bin /"clang-cpp" , "-v" , "--target=#{ target } " , "test.cpp"
636
+
637
+ system bin /"clang" , "-v" , "--target=#{ target } " , "test.c" , "-o" , "test-macosx"
638
+ assert_equal "Hello World!" , shell_output ( "./test-macosx" ) . chomp
639
+
640
+ system bin /"clang++" , "-v" , "--target=#{ target } " , "-std=c++11" , "test.cpp" , "-o" , "test++-macosx"
641
+ assert_equal "Hello World!" , shell_output ( "./test++-macosx" ) . chomp
621
642
end
622
643
623
644
# Testing Xcode
0 commit comments