diff --git a/Formula/f/flang.rb b/Formula/f/flang.rb index 2a30299d9837..52df711a7b7f 100644 --- a/Formula/f/flang.rb +++ b/Formula/f/flang.rb @@ -1,8 +1,8 @@ class Flang < Formula desc "LLVM Fortran Frontend" homepage "https://flang.llvm.org/" - url "https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.2/llvm-project-19.1.2.src.tar.xz" - sha256 "3666f01fc52d8a0b0da83e107d74f208f001717824be0b80007f529453aa1e19" + url "https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.3/llvm-project-19.1.3.src.tar.xz" + sha256 "324d483ff0b714c8ce7819a1b679dd9e4706cf91c6caf7336dc4ac0c1d3bf636" # 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" @@ -12,12 +12,12 @@ class Flang < Formula end bottle do - sha256 cellar: :any, arm64_sequoia: "27ac24add409b9d5625b9b76be498d28e9679f5b623e7bba4bdce7ab5e0f8fd4" - sha256 cellar: :any, arm64_sonoma: "ccb62aacc3bf88d1d90cd54c0a9a46853e81db56da569f2c06447e347e9171c7" - sha256 cellar: :any, arm64_ventura: "af6152f4c4bfa44381dcf315e4fe410c42049564b644985ea956ae77ead11a4d" - sha256 cellar: :any, sonoma: "d20e249d059695374646c2630c062de6ce1104033ab5b582121639053ec0a610" - sha256 cellar: :any, ventura: "663de6e3ba2a070367cb0c8fd4c7eb42182d844342835f1ed18c80f4c10bcd07" - sha256 cellar: :any_skip_relocation, x86_64_linux: "5708a60af8feca789467e0e03ceddd2f3e38532b082ed0e238487e18c7675c53" + sha256 cellar: :any, arm64_sequoia: "fdd2c87834a1ec92f4d87d8c0703c2e7bdfd15cadc72174fd768962f174588f1" + sha256 cellar: :any, arm64_sonoma: "ecf637bff4bd02c2c4c77344603a065f6b61310eb1243869c9e0e17002f1d06c" + sha256 cellar: :any, arm64_ventura: "2683519b08dd29be67ac74e10dce1bff82133c25ab3a8f3ea83a0ce32628b4bf" + sha256 cellar: :any, sonoma: "48b935fdba8b67b0efa4f2a292d9dc0ebf0d60b45972f25f476e51f2e98612df" + sha256 cellar: :any, ventura: "9cc0bd144901f4261199a629a5adc712204cac15241e0ddb1bcf517cad896ace" + sha256 cellar: :any_skip_relocation, x86_64_linux: "9157954980e2051622073b1252c7db1ca504764fc351ae2e17b6f582305f68f6" end depends_on "cmake" => :build diff --git a/Formula/l/lld.rb b/Formula/l/lld.rb index 778dbf1ce29b..10007e4322f6 100644 --- a/Formula/l/lld.rb +++ b/Formula/l/lld.rb @@ -1,8 +1,8 @@ class Lld < Formula desc "LLVM Project Linker" homepage "https://lld.llvm.org/" - url "https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.2/llvm-project-19.1.2.src.tar.xz" - sha256 "3666f01fc52d8a0b0da83e107d74f208f001717824be0b80007f529453aa1e19" + url "https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.3/llvm-project-19.1.3.src.tar.xz" + sha256 "324d483ff0b714c8ce7819a1b679dd9e4706cf91c6caf7336dc4ac0c1d3bf636" # 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" @@ -12,12 +12,12 @@ class Lld < Formula end bottle do - sha256 cellar: :any, arm64_sequoia: "5468a8e6c10d3b82434abe5e4c362342805ac42edbc077fbd5399258f2db72fa" - sha256 cellar: :any, arm64_sonoma: "5d2d703d5590adbd8996d61d2d3da0b51872c3827415ef88aa3df02ab321946d" - sha256 cellar: :any, arm64_ventura: "65d1eba15e7038789763660cee27705c0d35c283f7c427138f667b4b0a251a7f" - sha256 cellar: :any, sonoma: "b3034a2cc91ab370aff823bba99ff4b23ea4d50727a6cb0d3f97bea590ade8cb" - sha256 cellar: :any, ventura: "89c04a9ebe385817266fe287f346a84c5dd257c7cee49a228fcf043965f2ec3f" - sha256 cellar: :any_skip_relocation, x86_64_linux: "bb0f1641bd8dc7d05a3d265f86364c70ea0dba5cf4b27bc8924016fec0fe38b4" + sha256 cellar: :any, arm64_sequoia: "3faff17efc1a535986c58c3a955f91e89e9ba9bce32f9889e3bf696281380a79" + sha256 cellar: :any, arm64_sonoma: "5fd7b600bdba8c1d306419ccbadadfea013182bb34de2ecb014e4e127ce1fb6c" + sha256 cellar: :any, arm64_ventura: "a674c53a55bb4f369366b0334a04c6ced6378db8d45ca24d025a1ba5d4aaee30" + sha256 cellar: :any, sonoma: "1078eb6095f92efd8662797477cd70b0e759d7831240285731928323738248ef" + sha256 cellar: :any, ventura: "b3884e1f07369239fce22e22351d3346fce69a14dd75f2e2b4cfa852fe7ab41d" + sha256 cellar: :any_skip_relocation, x86_64_linux: "82ea1ac2d00d05656288f04be8a2796bbec7af630ee43fcdcd8d2b4eea7606e4" end depends_on "cmake" => :build diff --git a/Formula/l/llvm.rb b/Formula/l/llvm.rb index 4bb7008663f5..d21f311c7011 100644 --- a/Formula/l/llvm.rb +++ b/Formula/l/llvm.rb @@ -1,24 +1,35 @@ class Llvm < Formula desc "Next-gen compiler infrastructure" homepage "https://llvm.org/" - url "https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.2/llvm-project-19.1.2.src.tar.xz" - sha256 "3666f01fc52d8a0b0da83e107d74f208f001717824be0b80007f529453aa1e19" # 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.3/llvm-project-19.1.3.src.tar.xz" + sha256 "324d483ff0b714c8ce7819a1b679dd9e4706cf91c6caf7336dc4ac0c1d3bf636" + + # 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) end bottle do - sha256 cellar: :any, arm64_sequoia: "d432f24a0f2d6d719f24181df8b27308d0923dea5acb51fb42d13c79cc20610b" - sha256 cellar: :any, arm64_sonoma: "25fb3ca0bca2324a9ba64d4d0776c04eac78dc24ad5645218e7dd9a5ac8fcb8b" - sha256 cellar: :any, arm64_ventura: "a6deb72445b89b4528f56fadb811332406f01d6c294a25cb9c9e9c417e35ab88" - sha256 cellar: :any, sonoma: "3f4adf15aae3229808a4a351a33c93a0bda8548f75c3ffcf8b8fbd96a4f567fe" - sha256 cellar: :any, ventura: "5a218d82a37c5983a73fec61826278e49e7788e72131ca01b1808c0bcac4ba8f" - sha256 cellar: :any_skip_relocation, x86_64_linux: "bdbe203fbaa00f4d9b3ac5548a35c39da513f3cbe8a19f4068e0a7a58fac865e" + sha256 cellar: :any, arm64_sequoia: "19873681a95ca87aa8a88ef5c5a548e437dbe4c74ad16f88c4c556a9beb87bc3" + sha256 cellar: :any, arm64_sonoma: "2f4bd09057f2badf19be728784804bd46c4dcfa94b42e56908a1879000baf6eb" + sha256 cellar: :any, arm64_ventura: "fd9b1bd61321fd36b0618c9702e4ffa492ec2edcb66c859faf521a4607df6368" + sha256 cellar: :any, sonoma: "88c63f0c4c1a63b427dedc325cf26831f37604c749a2777a376bf6416c958f79" + sha256 cellar: :any, ventura: "d0f1a642be8a52e2dfb342b0405b8e584ff822ab4309bdf629efa1a6ed1ad196" + sha256 cellar: :any_skip_relocation, x86_64_linux: "479d06278bca8d5a7b8863f003ca127641ffef9c734976eee34fe8c0cc01d763" end # Clang cannot find system headers if Xcode CLT is not installed @@ -49,10 +60,28 @@ class Llvm < Formula # Fails at building LLDB fails_with gcc: "5" + # Support simplified triples in version config files. + # https://github.com/llvm/llvm-project/pull/111387 + patch do + url "https://github.com/llvm/llvm-project/commit/88dd0d33147a7f46a3c9df4aed28ad4e47ef597c.patch?full_index=1" + sha256 "0acaa80042055ad194306abb9843a94da24f53ee2bb819583d624391a6329b90" + end + + # Fix triple config loading for clang-cl + # https://github.com/llvm/llvm-project/pull/111397 + patch do + url "https://github.com/llvm/llvm-project/commit/a3e8b860788934d7cc1489f850f00dcfd9d8b595.patch?full_index=1" + sha256 "6d8403fec7be55004e94de90b074c2c166811903ad4921fd76274498c5a60a23" + end + def python3 "python3.13" 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", @@ -116,6 +145,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 @@ -126,6 +157,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? @@ -156,7 +189,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. @@ -412,6 +444,25 @@ 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" + + # Write config files for each macOS major version so that this works across OS upgrades. + # TODO: replace this with a call to `MacOSVersion.kernel_major_version` once this is in a release tag: + # https://github.com/Homebrew/brew/pull/18674 + { + 11 => 20, + 12 => 21, + 13 => 22, + 14 => 23, + 15 => 24, + }.each do |macos_version, kernel_version| + write_config_files(macos_version, kernel_version, Hardware::CPU.arch) + end + + # Also write an unversioned config file as fallback + write_config_files("", "", Hardware::CPU.arch) end # Install Vim plugins @@ -445,8 +496,34 @@ def install end end + # We use the extra layer of indirection in `arch` because the FormulaAudit/OnSystemConditionals + # doesn't want to let us use `Hardware::CPU.arch` outside of `install` or `post_install` blocks. + def write_config_files(macos_version, kernel_version, arch) + clang_config_file_dir.mkpath + + arches = Set.new([:arm64, :x86_64]) + arches << arch + + arches.each do |target_arch| + target_triple = "#{target_arch}-apple-darwin#{kernel_version}" + (clang_config_file_dir/"#{target_triple}.cfg").atomic_write <<~CONFIG + --sysroot=#{MacOS::CLT::PKG_PATH}/SDKs/MacOSX#{macos_version}.sdk + CONFIG + end + end + + def post_install + return unless OS.mac? + return if (clang_config_file_dir/"#{Hardware::CPU.arch}-apple-darwin#{OS.kernel_version.major}.cfg").exist? + + write_config_files(MacOS.version.major, OS.kernel_version.major, Hardware::CPU.arch) + end + def caveats s = <<~EOS + 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 @@ -513,6 +590,9 @@ def caveats } CPP + system bin/"clang-cpp", "-v", "test.c" + system bin/"clang-cpp", "-v", "test.cpp" + # Testing default toolchain and SDK location. system bin/"clang++", "-v", "-std=c++11", "test.cpp", "-o", "test++" @@ -528,6 +608,7 @@ def caveats toolchain_path = "/Library/Developer/CommandLineTools" cpp_base = (MacOS.version >= :big_sur) ? MacOS::CLT.sdk_path : toolchain_path system bin/"clang++", "-v", + "--no-default-config", "-isysroot", MacOS::CLT.sdk_path, "-isystem", "#{cpp_base}/usr/include/c++/v1", "-isystem", "#{MacOS::CLT.sdk_path}/usr/include", @@ -543,6 +624,7 @@ def caveats if OS.mac? && MacOS::Xcode.installed? cpp_base = (MacOS::Xcode.version >= "12.5") ? MacOS::Xcode.sdk_path : MacOS::Xcode.toolchain_path system bin/"clang++", "-v", + "--no-default-config", "-isysroot", MacOS::Xcode.sdk_path, "-isystem", "#{cpp_base}/usr/include/c++/v1", "-isystem", "#{MacOS::Xcode.sdk_path}/usr/include", diff --git a/Formula/w/wasi-runtimes.rb b/Formula/w/wasi-runtimes.rb index 069778258ef3..f30c702b7fb2 100644 --- a/Formula/w/wasi-runtimes.rb +++ b/Formula/w/wasi-runtimes.rb @@ -1,8 +1,8 @@ class WasiRuntimes < Formula desc "Compiler-RT and libc++ runtimes for WASI" homepage "https://wasi.dev" - url "https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.2/llvm-project-19.1.2.src.tar.xz" - sha256 "3666f01fc52d8a0b0da83e107d74f208f001717824be0b80007f529453aa1e19" + url "https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.3/llvm-project-19.1.3.src.tar.xz" + sha256 "324d483ff0b714c8ce7819a1b679dd9e4706cf91c6caf7336dc4ac0c1d3bf636" license "Apache-2.0" => { with: "LLVM-exception" } head "https://github.com/llvm/llvm-project.git", branch: "main" @@ -11,12 +11,12 @@ class WasiRuntimes < Formula end bottle do - sha256 cellar: :any_skip_relocation, arm64_sequoia: "3c15d547e848cda42bffcb56e8d797f81482495ff45207c808e214274617a8e8" - sha256 cellar: :any_skip_relocation, arm64_sonoma: "0effbd63bd850eef30b7d75d73b8b863b91a9dc74d532e6ca762ad11d49b9ec4" - sha256 cellar: :any_skip_relocation, arm64_ventura: "b9918fe74820758f11a0a6412e957764c155886d6c999fba9a9e822f2d7b75d2" - sha256 cellar: :any_skip_relocation, sonoma: "c1840dfe57ce81fdeb13e63f89aa90569e572935db233f6a34597dae63fd1e12" - sha256 cellar: :any_skip_relocation, ventura: "a077d43170858dc3121b56320315028cb625447e888b2d6265c98b6c24b4d164" - sha256 cellar: :any_skip_relocation, x86_64_linux: "13c5e9e2ee72e70baeee0882d2b35a5b75137e4628ca839462d8df932585184e" + sha256 cellar: :any_skip_relocation, arm64_sequoia: "0f2634f91560a0537344f4c84466e06fad5061c6eaf943136ffc82f2c8e8fa58" + sha256 cellar: :any_skip_relocation, arm64_sonoma: "3903b29603e9926d540312e302a5f9c1e0338587c2d9ab71b40a00a00e3c22ce" + sha256 cellar: :any_skip_relocation, arm64_ventura: "27e597c06a4606f5e189a8aafe97a67d1af2b1efde5a8919a380b8a4423df319" + sha256 cellar: :any_skip_relocation, sonoma: "bedd743473f5afa26709ef42f2c729f9dd7c350930fb5d47b24c2ab575cb95bf" + sha256 cellar: :any_skip_relocation, ventura: "72fb97b1e58463cfa0e40625ce6028be7f4f41c19ad0455af1ad0c31521cf70b" + sha256 cellar: :any_skip_relocation, x86_64_linux: "926a42b854953ac8613d97785241bbc78a2ef4190b0c6680ddcf496a9e4d0d65" end depends_on "cmake" => :build @@ -53,6 +53,9 @@ def install -DCMAKE_C_COMPILER_WORKS=ON -DCMAKE_CXX_COMPILER_WORKS=ON -DCMAKE_SYSROOT=#{wasi_libc.opt_share}/wasi-sysroot + -DCMAKE_FIND_FRAMEWORK=NEVER + -DCMAKE_VERBOSE_MAKEFILE=ON + -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=#{HOMEBREW_LIBRARY_PATH}/cmake/trap_fetchcontent_provider.cmake ] # Compiler flags taken from: # https://github.com/WebAssembly/wasi-sdk/blob/5e04cd81eb749edb5642537d150ab1ab7aedabe9/cmake/wasi-sdk-sysroot.cmake#L65-L75 @@ -75,7 +78,10 @@ def install (pkgshare/"lib").install_symlink "wasi" => "wasip1" (pkgshare/"lib").install_symlink "wasi" => "wasip2" - clang_resource_dir = Pathname.new(Utils.safe_popen_read(llvm.opt_bin/"clang", "-print-resource-dir").chomp) + clang_resource_dir = Utils.safe_popen_read(llvm.opt_bin/"clang", "-print-resource-dir").chomp + clang_resource_dir.sub! llvm.prefix.realpath, llvm.opt_prefix + clang_resource_dir = Pathname.new(clang_resource_dir) + clang_resource_include_dir = clang_resource_dir/"include" clang_resource_include_dir.find do |pn| next unless pn.file? @@ -84,16 +90,22 @@ def install target = pkgshare/relative_path next if target.exist? - target.parent.install_symlink pn + target.parent.mkpath + ln_s pn, target end + # FIXME: the build mistakenly concludes our toolchain doesn't support `-fno-exceptions` + # because we have no `wasm-component-ld`. Remove the line below when + # `wasm-component-ld` is merged. + ENV.append_to_cflags "-fno-exceptions" target_configuration = Hash.new { |h, k| h[k] = {} } targets.each do |target| # Configuration taken from: # https://github.com/WebAssembly/wasi-sdk/blob/5e04cd81eb749edb5642537d150ab1ab7aedabe9/cmake/wasi-sdk-sysroot.cmake#L227-L271 configuration = target_configuration[target] - configuration[:threads] = configuration[:pic] = target.end_with?("-threads") ? "ON" : "OFF" + configuration[:threads] = target.end_with?("-threads") ? "ON" : "OFF" + configuration[:pic] = target.end_with?("-threads") ? "OFF" : "ON" configuration[:flags] = target.end_with?("-threads") ? ["-pthread"] : [] cflags = ENV.cflags&.split || [] @@ -130,7 +142,7 @@ def install -DLIBCXX_ENABLE_FILESYSTEM:BOOL=ON -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT:BOOL=OFF -DLIBCXX_CXX_ABI=libcxxabi - -DLIBCXX_CXX_ABI_INCLUDE_PATHS=#{testpath}/libcxxabi/include + -DLIBCXX_CXX_ABI_INCLUDE_PATHS=#{buildpath}/libcxxabi/include -DLIBCXX_HAS_MUSL_LIBC:BOOL=ON -DLIBCXX_ABI_VERSION=2 -DLIBCXXABI_ENABLE_EXCEPTIONS:BOOL=OFF @@ -157,6 +169,16 @@ def install system "cmake", "-S", "runtimes", "-B", "runtimes-#{target}", *target_cmake_args, *common_cmake_args system "cmake", "--build", "runtimes-#{target}" system "cmake", "--install", "runtimes-#{target}" + + triple = Utils.safe_popen_read(llvm.opt_bin/"clang", "--target=#{target}", "--print-target-triple").chomp + config_file = "#{triple}.cfg" + + (buildpath/config_file).write <<~CONFIG + --sysroot=#{HOMEBREW_PREFIX}/share/wasi-sysroot + -resource-dir=#{HOMEBREW_PREFIX}/share/wasi-runtimes + CONFIG + + (etc/"clang").install config_file end (share/"wasi-sysroot/include/c++/v1").mkpath touch share/"wasi-sysroot/include/c++/v1/.keepme" @@ -184,18 +206,14 @@ def install CPP clang = Formula["llvm"].opt_bin/"clang" - wasm_args = %W[ - --sysroot=#{HOMEBREW_PREFIX}/share/wasi-sysroot - -resource-dir=#{HOMEBREW_PREFIX}/share/wasi-runtimes - ] targets.each do |target| # FIXME: Needs a working `wasm-component-ld`. next if target.include?("wasip2") - system clang, "--target=#{target}", *wasm_args, "-v", "test.c", "-o", "test-#{target}" + system clang, "--target=#{target}", "-v", "test.c", "-o", "test-#{target}" assert_equal "the answer is 42", shell_output("wasmtime #{testpath}/test-#{target}") - system "#{clang}++", "--target=#{target}", *wasm_args, "-v", "test.cc", "-o", "test-cxx-#{target}" + system "#{clang}++", "--target=#{target}", "-v", "test.cc", "-o", "test-cxx-#{target}" assert_equal "hello from C++ main with cout!", shell_output("wasmtime #{testpath}/test-cxx-#{target}").chomp end end