11class Llvm < Formula
22 desc "Next-gen compiler infrastructure"
33 homepage "https://llvm.org/"
4- url "https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.2/llvm-project-19.1.2.src.tar.xz"
5- sha256 "3666f01fc52d8a0b0da83e107d74f208f001717824be0b80007f529453aa1e19"
64 # The LLVM Project is under the Apache License v2.0 with LLVM Exceptions
75 license "Apache-2.0" => { with : "LLVM-exception" }
86 head "https://github.com/llvm/llvm-project.git" , branch : "main"
97
8+ stable do
9+ url "https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.3/llvm-project-19.1.3.src.tar.xz"
10+ sha256 "324d483ff0b714c8ce7819a1b679dd9e4706cf91c6caf7336dc4ac0c1d3bf636"
11+
12+ # Backport relative `CLANG_CONFIG_FILE_SYSTEM_DIR` patch.
13+ # Remove in LLVM 20.
14+ # https://github.com/llvm/llvm-project/pull/110962
15+ patch do
16+ url "https://github.com/llvm/llvm-project/commit/1682c99a8877364f1d847395cef501e813804caa.patch?full_index=1"
17+ sha256 "2d0a185e27ff2bc46531fc2c18c61ffab521ae8ece2db5b5bed498a15f3f3758"
18+ end
19+ end
20+
1021 livecheck do
1122 url :stable
1223 regex ( /^llvmorg[._-]v?(\d +(?:\. \d +)+)$/i )
1324 end
1425
1526 bottle do
16- sha256 cellar : :any , arm64_sequoia : "d432f24a0f2d6d719f24181df8b27308d0923dea5acb51fb42d13c79cc20610b "
17- sha256 cellar : :any , arm64_sonoma : "25fb3ca0bca2324a9ba64d4d0776c04eac78dc24ad5645218e7dd9a5ac8fcb8b "
18- sha256 cellar : :any , arm64_ventura : "a6deb72445b89b4528f56fadb811332406f01d6c294a25cb9c9e9c417e35ab88 "
19- sha256 cellar : :any , sonoma : "3f4adf15aae3229808a4a351a33c93a0bda8548f75c3ffcf8b8fbd96a4f567fe "
20- sha256 cellar : :any , ventura : "5a218d82a37c5983a73fec61826278e49e7788e72131ca01b1808c0bcac4ba8f "
21- sha256 cellar : :any_skip_relocation , x86_64_linux : "bdbe203fbaa00f4d9b3ac5548a35c39da513f3cbe8a19f4068e0a7a58fac865e "
27+ sha256 cellar : :any , arm64_sequoia : "19873681a95ca87aa8a88ef5c5a548e437dbe4c74ad16f88c4c556a9beb87bc3 "
28+ sha256 cellar : :any , arm64_sonoma : "2f4bd09057f2badf19be728784804bd46c4dcfa94b42e56908a1879000baf6eb "
29+ sha256 cellar : :any , arm64_ventura : "fd9b1bd61321fd36b0618c9702e4ffa492ec2edcb66c859faf521a4607df6368 "
30+ sha256 cellar : :any , sonoma : "88c63f0c4c1a63b427dedc325cf26831f37604c749a2777a376bf6416c958f79 "
31+ sha256 cellar : :any , ventura : "d0f1a642be8a52e2dfb342b0405b8e584ff822ab4309bdf629efa1a6ed1ad196 "
32+ sha256 cellar : :any_skip_relocation , x86_64_linux : "479d06278bca8d5a7b8863f003ca127641ffef9c734976eee34fe8c0cc01d763 "
2233 end
2334
2435 # Clang cannot find system headers if Xcode CLT is not installed
@@ -49,10 +60,28 @@ class Llvm < Formula
4960 # Fails at building LLDB
5061 fails_with gcc : "5"
5162
63+ # Support simplified triples in version config files.
64+ # https://github.com/llvm/llvm-project/pull/111387
65+ patch do
66+ url "https://github.com/llvm/llvm-project/commit/88dd0d33147a7f46a3c9df4aed28ad4e47ef597c.patch?full_index=1"
67+ sha256 "0acaa80042055ad194306abb9843a94da24f53ee2bb819583d624391a6329b90"
68+ end
69+
70+ # Fix triple config loading for clang-cl
71+ # https://github.com/llvm/llvm-project/pull/111397
72+ patch do
73+ url "https://github.com/llvm/llvm-project/commit/a3e8b860788934d7cc1489f850f00dcfd9d8b595.patch?full_index=1"
74+ sha256 "6d8403fec7be55004e94de90b074c2c166811903ad4921fd76274498c5a60a23"
75+ end
76+
5277 def python3
5378 "python3.13"
5479 end
5580
81+ def clang_config_file_dir
82+ etc /"clang"
83+ end
84+
5685 def install
5786 # The clang bindings need a little help finding our libclang.
5887 inreplace "clang/bindings/python/clang/cindex.py" ,
@@ -116,6 +145,8 @@ def install
116145 -DLLVM_ENABLE_Z3_SOLVER=#{ versioned_formula? ? "OFF" : "ON" }
117146 -DLLVM_OPTIMIZED_TABLEGEN=ON
118147 -DLLVM_TARGETS_TO_BUILD=all
148+ -DLLVM_USE_RELATIVE_PATHS_IN_FILES=ON
149+ -DLLVM_SOURCE_PREFIX=.
119150 -DLLDB_USE_SYSTEM_DEBUGSERVER=ON
120151 -DLLDB_ENABLE_PYTHON=ON
121152 -DLLDB_ENABLE_LUA=OFF
@@ -126,6 +157,8 @@ def install
126157 -DCLANG_PYTHON_BINDINGS_VERSIONS=#{ python_versions . join ( ";" ) }
127158 -DLLVM_CREATE_XCODE_TOOLCHAIN=OFF
128159 -DCLANG_FORCE_MATCHING_LIBCLANG_SOVERSION=OFF
160+ -DCLANG_CONFIG_FILE_SYSTEM_DIR=#{ clang_config_file_dir . relative_path_from ( bin ) }
161+ -DCLANG_CONFIG_FILE_USER_DIR=~/.config/clang
129162 ]
130163
131164 if tap . present?
@@ -156,7 +189,6 @@ def install
156189 args << "-DLIBCXX_INSTALL_LIBRARY_DIR=#{ libcxx_install_libdir } "
157190 args << "-DLIBUNWIND_INSTALL_LIBRARY_DIR=#{ libunwind_install_libdir } "
158191 args << "-DLIBCXXABI_INSTALL_LIBRARY_DIR=#{ libcxx_install_libdir } "
159- args << "-DDEFAULT_SYSROOT=#{ macos_sdk } " if macos_sdk
160192 runtimes_cmake_args << "-DCMAKE_INSTALL_RPATH=#{ libcxx_rpaths . join ( "|" ) } "
161193
162194 # Disable builds for OSes not supported by the CLT SDK.
@@ -412,6 +444,25 @@ def install
412444 system "/usr/libexec/PlistBuddy" , "-c" , "Add:CompatibilityVersion integer 2" , "Info.plist"
413445 xctoolchain . install "Info.plist"
414446 ( xctoolchain /"usr" ) . install_symlink [ bin , include , lib , libexec , share ]
447+
448+ # Install a major-versioned symlink that can be used across minor/patch version upgrades.
449+ xctoolchain . parent . install_symlink xctoolchain . basename . to_s => "LLVM#{ soversion } .xctoolchain"
450+
451+ # 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 )
462+ end
463+
464+ # Also write an unversioned config file as fallback
465+ write_config_files ( "" , "" , Hardware ::CPU . arch )
415466 end
416467
417468 # Install Vim plugins
@@ -445,8 +496,34 @@ def install
445496 end
446497 end
447498
499+ # We use the extra layer of indirection in `arch` because the FormulaAudit/OnSystemConditionals
500+ # doesn't want to let us use `Hardware::CPU.arch` outside of `install` or `post_install` blocks.
501+ def write_config_files ( macos_version , kernel_version , arch )
502+ clang_config_file_dir . mkpath
503+
504+ arches = Set . new ( [ :arm64 , :x86_64 ] )
505+ arches << arch
506+
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
512+ end
513+ end
514+
515+ def post_install
516+ return unless OS . mac?
517+ return if ( clang_config_file_dir /"#{ Hardware ::CPU . arch } -apple-darwin#{ OS . kernel_version . major } .cfg" ) . exist?
518+
519+ write_config_files ( MacOS . version . major , OS . kernel_version . major , Hardware ::CPU . arch )
520+ end
521+
448522 def caveats
449523 s = <<~EOS
524+ CLANG_CONFIG_FILE_SYSTEM_DIR: #{ clang_config_file_dir }
525+ CLANG_CONFIG_FILE_USER_DIR: ~/.config/clang
526+
450527 LLD is now provided in a separate formula:
451528 brew install lld
452529
@@ -513,6 +590,9 @@ def caveats
513590 }
514591 CPP
515592
593+ system bin /"clang-cpp" , "-v" , "test.c"
594+ system bin /"clang-cpp" , "-v" , "test.cpp"
595+
516596 # Testing default toolchain and SDK location.
517597 system bin /"clang++" , "-v" ,
518598 "-std=c++11" , "test.cpp" , "-o" , "test++"
@@ -528,6 +608,7 @@ def caveats
528608 toolchain_path = "/Library/Developer/CommandLineTools"
529609 cpp_base = ( MacOS . version >= :big_sur ) ? MacOS ::CLT . sdk_path : toolchain_path
530610 system bin /"clang++" , "-v" ,
611+ "--no-default-config" ,
531612 "-isysroot" , MacOS ::CLT . sdk_path ,
532613 "-isystem" , "#{ cpp_base } /usr/include/c++/v1" ,
533614 "-isystem" , "#{ MacOS ::CLT . sdk_path } /usr/include" ,
@@ -543,6 +624,7 @@ def caveats
543624 if OS . mac? && MacOS ::Xcode . installed?
544625 cpp_base = ( MacOS ::Xcode . version >= "12.5" ) ? MacOS ::Xcode . sdk_path : MacOS ::Xcode . toolchain_path
545626 system bin /"clang++" , "-v" ,
627+ "--no-default-config" ,
546628 "-isysroot" , MacOS ::Xcode . sdk_path ,
547629 "-isystem" , "#{ cpp_base } /usr/include/c++/v1" ,
548630 "-isystem" , "#{ MacOS ::Xcode . sdk_path } /usr/include" ,
0 commit comments