Skip to content

Commit

Permalink
llvm: add config file, update caveats
Browse files Browse the repository at this point in the history
Adding a system config file will allow us to stop baking in the
`DEFAULT_SYSROOT` and allow users on Xcode-only installations to use the
bottles. It will also make it easier to update this value when users
upgrade the major version of their macOS. Before this change, this
required a full reinstall. After, users will simply have to
`brew postinstall llvm`.

The config file change requires an upstream patch. We'll probably have
to wait a little bit for it to merge, and then wait another few days to
make sure it doesn't get reverted.

Following discussion at #192505, let's also update the caveats to notify
users of potential changes regarding `LLVM_ENABLE_EH` in LLVM 20.
  • Loading branch information
carlocab committed Oct 3, 2024
1 parent 22c68a0 commit 3da97da
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions Formula/l/llvm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class Llvm < Formula
sha256 cellar: :any_skip_relocation, x86_64_linux: "4066cc4bba868660b63f4130073b19d551b82d2cbeb9fe6d96e5a68d864ee305"
end

# Clang cannot find system headers if Xcode CLT is not installed
pour_bottle? only_if: :clt_installed

keg_only :provided_by_macos

# https://llvm.org/docs/GettingStarted.html#requirement
Expand Down Expand Up @@ -54,6 +51,18 @@ def python3
"python3.12"
end

def clang_config_file_dir
etc/"clang"
end

# Backport relative `CLANG_CONFIG_FILE_SYSTEM_DIR` patch.
# Remove in LLVM 20.
# https://github.com/llvm/llvm-project/pull/110962
patch do
url "https://github.com/llvm/llvm-project/commit/e31545f666eb4ca32030956a38dbc4078a64068c.patch?full_index=1"
sha256 "53c2af0027e06ec0268ddda205c28aecf065ea08374dba0d8be573aa0d1b5aa7"
end

def install
# The clang bindings need a little help finding our libclang.
inreplace "clang/bindings/python/clang/cindex.py",
Expand Down Expand Up @@ -127,6 +136,7 @@ def install
-DCLANG_PYTHON_BINDINGS_VERSIONS=#{python_versions.join(";")}
-DLLVM_CREATE_XCODE_TOOLCHAIN=OFF
-DCLANG_FORCE_MATCHING_LIBCLANG_SOVERSION=OFF
-DCLANG_CONFIG_FILE_SYSTEM_DIR=#{clang_config_file_dir.relative_path_from(bin)}
]

if tap.present?
Expand Down Expand Up @@ -157,7 +167,6 @@ def install
args << "-DLIBCXX_INSTALL_LIBRARY_DIR=#{libcxx_install_libdir}"
args << "-DLIBUNWIND_INSTALL_LIBRARY_DIR=#{libunwind_install_libdir}"
args << "-DLIBCXXABI_INSTALL_LIBRARY_DIR=#{libcxx_install_libdir}"
args << "-DDEFAULT_SYSROOT=#{macos_sdk}" if macos_sdk
runtimes_cmake_args << "-DCMAKE_INSTALL_RPATH=#{libcxx_rpaths.join("|")}"

# Disable builds for OSes not supported by the CLT SDK.
Expand Down Expand Up @@ -446,6 +455,18 @@ def install
end
end

def post_install
return unless OS.mac?
return unless (macos_sdk = MacOS.sdk_path_if_needed)

clang_config_file_dir.mkpath
%w[clang.cfg clang++.cfg].each do |config_file|
(clang_config_file_dir/config_file).atomic_write <<~CONFIG
--sysroot=#{macos_sdk}
CONFIG
end
end

def caveats
s = <<~EOS
`lld` is now provided in a separate formula:
Expand All @@ -462,6 +483,12 @@ def caveats
LDFLAGS="-L#{opt_lib}/c++ -L#{opt_lib}/unwind -lunwind"
NOTE: You probably want to use the libunwind and libc++ provided by macOS unless you know what you're doing.
When upgrading to a new major version of macOS (e.g. 15 to 16), please run:
brew postinstall llvm
We plan to build LLVM 20 with `LLVM_ENABLE_EH=OFF`. Please see:
<link to issue or discussion>
EOS
end

Expand Down

0 comments on commit 3da97da

Please sign in to comment.