Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llvm: add config file, update caveats #192709

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 46 additions & 7 deletions Formula/l/llvm.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
class Llvm < Formula
desc "Next-gen compiler infrastructure"
homepage "https://llvm.org/"
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.1/llvm-project-19.1.1.src.tar.xz"
sha256 "d40e933e2a208ee142898f85d886423a217e991abbcd42dd8211f507c93e1266"
# The LLVM Project is under the Apache License v2.0 with LLVM Exceptions
license "Apache-2.0" => { with: "LLVM-exception" }
head "https://github.com/llvm/llvm-project.git", branch: "main"

stable do
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.1/llvm-project-19.1.1.src.tar.xz"
sha256 "d40e933e2a208ee142898f85d886423a217e991abbcd42dd8211f507c93e1266"

# 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/1682c99a8877364f1d847395cef501e813804caa.patch?full_index=1"
sha256 "2d0a185e27ff2bc46531fc2c18c61ffab521ae8ece2db5b5bed498a15f3f3758"
end
end

livecheck do
url :stable
regex(/^llvmorg[._-]v?(\d+(?:\.\d+)+)$/i)
Expand All @@ -21,9 +32,6 @@ class Llvm < Formula
sha256 cellar: :any_skip_relocation, x86_64_linux: "fe6cd7c69619252eea13f0c5c590b2662541089d1a7e8bc606dbb07b1a769854"
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 @@ -53,6 +61,10 @@ def python3
"python3.12"
end

def clang_config_file_dir
etc/"clang"
end

def install
# The clang bindings need a little help finding our libclang.
inreplace "clang/bindings/python/clang/cindex.py",
Expand Down Expand Up @@ -116,6 +128,8 @@ def install
-DLLVM_ENABLE_Z3_SOLVER=#{versioned_formula? ? "OFF" : "ON"}
-DLLVM_OPTIMIZED_TABLEGEN=ON
-DLLVM_TARGETS_TO_BUILD=all
-DLLVM_USE_RELATIVE_PATHS_IN_FILES=ON
-DLLVM_SOURCE_PREFIX=.
-DLLDB_USE_SYSTEM_DEBUGSERVER=ON
-DLLDB_ENABLE_PYTHON=ON
-DLLDB_ENABLE_LUA=OFF
Expand All @@ -126,6 +140,8 @@ 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)}
-DCLANG_CONFIG_FILE_USER_DIR=~/.config/clang
]

if tap.present?
Expand Down Expand Up @@ -156,7 +172,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 @@ -412,6 +427,9 @@ def install
system "/usr/libexec/PlistBuddy", "-c", "Add:CompatibilityVersion integer 2", "Info.plist"
xctoolchain.install "Info.plist"
(xctoolchain/"usr").install_symlink [bin, include, lib, libexec, share]

# Install a major-versioned symlink that can be used across minor/patch version upgrades.
xctoolchain.parent.install_symlink xctoolchain.basename.to_s => "LLVM#{soversion}.xctoolchain"
end

# Install Vim plugins
Expand Down Expand Up @@ -445,10 +463,28 @@ def install
end
end

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

@Bo98 Bo98 Oct 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is best effort and might point to a newer SDK if CLT is not installed which wouldn't be great.

There's also the Xcode-beta.app -> Xcode.app case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, but note this is the path we set DEFAULT_SYSROOT to so this is strictly an improvement over existing builds (because users can now fix a broken --sysroot flag when previously they couldn't).

Copy link
Member

@Bo98 Bo98 Oct 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a relocatable bottle. Anybody building from source are long past the days of updating Xcode and are required by brew to have the CLT installed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should we just require the CLT regardless?

Copy link
Member

@Bo98 Bo98 Oct 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably. If we pursue a patch for target matching then we'll probably have to in the end anyway as we'll ship config files for all OS versions (pkg-config style except we don't need to bake in the OS version to clang).


clang_config_file_dir.mkpath
%w[clang.cfg clang++.cfg].each do |config_file|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does clang-cl, clang-cpp and flang work with this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to set --sysroot for clang-cl, do we? Need to check clang-cpp, but flang seems to work fine based on dependent testing.

Copy link
Member

@Bo98 Bo98 Oct 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No sorry, didn't mean to mention clang-cl. Not sure why I typed that.

clang-cpp is the main concern to check.

(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:
CLANG_CONFIG_FILE_SYSTEM_DIR: #{clang_config_file_dir}
CLANG_CONFIG_FILE_USER_DIR: ~/.config/clang

LLD is now provided in a separate formula:
brew install lld

We plan to build LLVM 20 with `LLVM_ENABLE_EH=OFF`. Please see:
https://github.com/orgs/Homebrew/discussions/5654
EOS

on_macos do
Expand All @@ -461,6 +497,9 @@ 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
EOS
end

Expand Down
Loading