Skip to content

Commit 7282b0a

Browse files
committed
llvm: fix targeting older macOS versions than the host
If you try to target a macOS version that is older than the host machine, our config files will point to an SDK that is likely not available on the host.[^1] We can fix this by defaulting to the unversioned SDK in these cases. [^1]: See, for example, Homebrew#196344 (comment)
1 parent 24a7941 commit 7282b0a

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

Formula/l/llvm.rb

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,10 @@ def write_config_files(macos_version, kernel_version, arch)
490490

491491
arches = Set.new([:arm64, :x86_64, :aarch64])
492492
arches << arch
493-
sysroot = if macos_version >= "10.14" || (macos_version.blank? && kernel_version.blank?)
493+
494+
sysroot = if macos_version.blank? || (MacOS.version > macos_version && MacOS::CLT.separate_header_package?)
495+
"#{MacOS::CLT::PKG_PATH}/SDKs/MacOSX.sdk"
496+
elsif macos_version >= "10.14"
494497
"#{MacOS::CLT::PKG_PATH}/SDKs/MacOSX#{macos_version}.sdk"
495498
else
496499
"/"
@@ -627,15 +630,27 @@ def caveats
627630
system bin/"clang", "-v", "test.c", "-o", "testCLT"
628631
assert_equal "Hello World!", shell_output("./testCLT").chomp
629632

630-
target = "#{Hardware::CPU.arch}-apple-macosx#{MacOS.full_version}"
631-
system bin/"clang-cpp", "-v", "--target=#{target}", "test.c"
632-
system bin/"clang-cpp", "-v", "--target=#{target}", "test.cpp"
633+
targets = ["#{Hardware::CPU.arch}-apple-macosx#{MacOS.full_version}"]
634+
635+
# The test tends to time out on Intel, so let's do these only for ARM macOS.
636+
if Hardware::CPU.arm?
637+
old_macos_version = HOMEBREW_MACOS_OLDEST_SUPPORTED.to_i - 1
638+
targets << "#{Hardware::CPU.arch}-apple-macosx#{old_macos_version}"
639+
640+
old_kernel_version = MacOSVersion.kernel_major_version(MacOSVersion.new(old_macos_version.to_s))
641+
targets << "#{Hardware::CPU.arch}-apple-darwin#{old_kernel_version}"
642+
end
643+
644+
targets.each do |target|
645+
system bin/"clang-cpp", "-v", "--target=#{target}", "test.c"
646+
system bin/"clang-cpp", "-v", "--target=#{target}", "test.cpp"
633647

634-
system bin/"clang", "-v", "--target=#{target}", "test.c", "-o", "test-macosx"
635-
assert_equal "Hello World!", shell_output("./test-macosx").chomp
648+
system bin/"clang", "-v", "--target=#{target}", "test.c", "-o", "test-macosx"
649+
assert_equal "Hello World!", shell_output("./test-macosx").chomp
636650

637-
system bin/"clang++", "-v", "--target=#{target}", "-std=c++11", "test.cpp", "-o", "test++-macosx"
638-
assert_equal "Hello World!", shell_output("./test++-macosx").chomp
651+
system bin/"clang++", "-v", "--target=#{target}", "-std=c++11", "test.cpp", "-o", "test++-macosx"
652+
assert_equal "Hello World!", shell_output("./test++-macosx").chomp
653+
end
639654
end
640655

641656
# Testing Xcode

0 commit comments

Comments
 (0)