Skip to content

Commit

Permalink
llvm: fix targeting older macOS versions than the host
Browse files Browse the repository at this point in the history
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, #196344 (comment)
  • Loading branch information
carlocab committed Dec 8, 2024
1 parent 8dd1e7e commit a91ed2c
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions Formula/l/llvm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,10 @@ def write_config_files(macos_version, kernel_version, arch)

arches = Set.new([:arm64, :x86_64, :aarch64])
arches << arch
sysroot = if macos_version >= "10.14" || (macos_version.blank? && kernel_version.blank?)

sysroot = if macos_version.blank? || (MacOS.version >= macos_version && MacOS::CLT.separate_header_package?)
"#{MacOS::CLT::PKG_PATH}/SDKs/MacOSX.sdk"
elsif macos_version >= "10.14"
"#{MacOS::CLT::PKG_PATH}/SDKs/MacOSX#{macos_version}.sdk"
else
"/"
Expand Down Expand Up @@ -627,15 +630,22 @@ def caveats
system bin/"clang", "-v", "test.c", "-o", "testCLT"
assert_equal "Hello World!", shell_output("./testCLT").chomp

target = "#{Hardware::CPU.arch}-apple-macosx#{MacOS.full_version}"
system bin/"clang-cpp", "-v", "--target=#{target}", "test.c"
system bin/"clang-cpp", "-v", "--target=#{target}", "test.cpp"

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

system bin/"clang++", "-v", "--target=#{target}", "-std=c++11", "test.cpp", "-o", "test++-macosx"
assert_equal "Hello World!", shell_output("./test++-macosx").chomp
[
"#{Hardware::CPU.arch}-apple-macosx#{MacOS.full_version}",
"#{Hardware::CPU.arch}-apple-macosx#{HOMEBREW_MACOS_OLDEST_SUPPORTED.to_i - 1}",
"#{Hardware::CPU.arch}-apple-macosx",
"#{Hardware::CPU.arch}-apple-macosx",
"#{Hardware::CPU.arch}-apple-darwin",
].each do |target|
system bin/"clang-cpp", "-v", "--target=#{target}", "test.c"
system bin/"clang-cpp", "-v", "--target=#{target}", "test.cpp"

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

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

# Testing Xcode
Expand Down

0 comments on commit a91ed2c

Please sign in to comment.