Skip to content

Commit 78b4cd5

Browse files
authored
Merge pull request #196094 from Homebrew/llvm-lld-flang-wasi-runtimes
llvm lld flang wasi-runtimes 19.1.3
2 parents 545c09b + 471f141 commit 78b4cd5

File tree

4 files changed

+143
-43
lines changed

4 files changed

+143
-43
lines changed

Formula/f/flang.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
class Flang < Formula
22
desc "LLVM Fortran Frontend"
33
homepage "https://flang.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"
4+
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.3/llvm-project-19.1.3.src.tar.xz"
5+
sha256 "324d483ff0b714c8ce7819a1b679dd9e4706cf91c6caf7336dc4ac0c1d3bf636"
66
# The LLVM Project is under the Apache License v2.0 with LLVM Exceptions
77
license "Apache-2.0" => { with: "LLVM-exception" }
88
head "https://github.com/llvm/llvm-project.git", branch: "main"
@@ -12,12 +12,12 @@ class Flang < Formula
1212
end
1313

1414
bottle do
15-
sha256 cellar: :any, arm64_sequoia: "27ac24add409b9d5625b9b76be498d28e9679f5b623e7bba4bdce7ab5e0f8fd4"
16-
sha256 cellar: :any, arm64_sonoma: "ccb62aacc3bf88d1d90cd54c0a9a46853e81db56da569f2c06447e347e9171c7"
17-
sha256 cellar: :any, arm64_ventura: "af6152f4c4bfa44381dcf315e4fe410c42049564b644985ea956ae77ead11a4d"
18-
sha256 cellar: :any, sonoma: "d20e249d059695374646c2630c062de6ce1104033ab5b582121639053ec0a610"
19-
sha256 cellar: :any, ventura: "663de6e3ba2a070367cb0c8fd4c7eb42182d844342835f1ed18c80f4c10bcd07"
20-
sha256 cellar: :any_skip_relocation, x86_64_linux: "5708a60af8feca789467e0e03ceddd2f3e38532b082ed0e238487e18c7675c53"
15+
sha256 cellar: :any, arm64_sequoia: "fdd2c87834a1ec92f4d87d8c0703c2e7bdfd15cadc72174fd768962f174588f1"
16+
sha256 cellar: :any, arm64_sonoma: "ecf637bff4bd02c2c4c77344603a065f6b61310eb1243869c9e0e17002f1d06c"
17+
sha256 cellar: :any, arm64_ventura: "2683519b08dd29be67ac74e10dce1bff82133c25ab3a8f3ea83a0ce32628b4bf"
18+
sha256 cellar: :any, sonoma: "48b935fdba8b67b0efa4f2a292d9dc0ebf0d60b45972f25f476e51f2e98612df"
19+
sha256 cellar: :any, ventura: "9cc0bd144901f4261199a629a5adc712204cac15241e0ddb1bcf517cad896ace"
20+
sha256 cellar: :any_skip_relocation, x86_64_linux: "9157954980e2051622073b1252c7db1ca504764fc351ae2e17b6f582305f68f6"
2121
end
2222

2323
depends_on "cmake" => :build

Formula/l/lld.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
class Lld < Formula
22
desc "LLVM Project Linker"
33
homepage "https://lld.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"
4+
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.3/llvm-project-19.1.3.src.tar.xz"
5+
sha256 "324d483ff0b714c8ce7819a1b679dd9e4706cf91c6caf7336dc4ac0c1d3bf636"
66
# The LLVM Project is under the Apache License v2.0 with LLVM Exceptions
77
license "Apache-2.0" => { with: "LLVM-exception" }
88
head "https://github.com/llvm/llvm-project.git", branch: "main"
@@ -12,12 +12,12 @@ class Lld < Formula
1212
end
1313

1414
bottle do
15-
sha256 cellar: :any, arm64_sequoia: "5468a8e6c10d3b82434abe5e4c362342805ac42edbc077fbd5399258f2db72fa"
16-
sha256 cellar: :any, arm64_sonoma: "5d2d703d5590adbd8996d61d2d3da0b51872c3827415ef88aa3df02ab321946d"
17-
sha256 cellar: :any, arm64_ventura: "65d1eba15e7038789763660cee27705c0d35c283f7c427138f667b4b0a251a7f"
18-
sha256 cellar: :any, sonoma: "b3034a2cc91ab370aff823bba99ff4b23ea4d50727a6cb0d3f97bea590ade8cb"
19-
sha256 cellar: :any, ventura: "89c04a9ebe385817266fe287f346a84c5dd257c7cee49a228fcf043965f2ec3f"
20-
sha256 cellar: :any_skip_relocation, x86_64_linux: "bb0f1641bd8dc7d05a3d265f86364c70ea0dba5cf4b27bc8924016fec0fe38b4"
15+
sha256 cellar: :any, arm64_sequoia: "3faff17efc1a535986c58c3a955f91e89e9ba9bce32f9889e3bf696281380a79"
16+
sha256 cellar: :any, arm64_sonoma: "5fd7b600bdba8c1d306419ccbadadfea013182bb34de2ecb014e4e127ce1fb6c"
17+
sha256 cellar: :any, arm64_ventura: "a674c53a55bb4f369366b0334a04c6ced6378db8d45ca24d025a1ba5d4aaee30"
18+
sha256 cellar: :any, sonoma: "1078eb6095f92efd8662797477cd70b0e759d7831240285731928323738248ef"
19+
sha256 cellar: :any, ventura: "b3884e1f07369239fce22e22351d3346fce69a14dd75f2e2b4cfa852fe7ab41d"
20+
sha256 cellar: :any_skip_relocation, x86_64_linux: "82ea1ac2d00d05656288f04be8a2796bbec7af630ee43fcdcd8d2b4eea7606e4"
2121
end
2222

2323
depends_on "cmake" => :build

Formula/l/llvm.rb

Lines changed: 91 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
11
class 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",

Formula/w/wasi-runtimes.rb

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
class WasiRuntimes < Formula
22
desc "Compiler-RT and libc++ runtimes for WASI"
33
homepage "https://wasi.dev"
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"
4+
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.3/llvm-project-19.1.3.src.tar.xz"
5+
sha256 "324d483ff0b714c8ce7819a1b679dd9e4706cf91c6caf7336dc4ac0c1d3bf636"
66
license "Apache-2.0" => { with: "LLVM-exception" }
77
head "https://github.com/llvm/llvm-project.git", branch: "main"
88

@@ -11,12 +11,12 @@ class WasiRuntimes < Formula
1111
end
1212

1313
bottle do
14-
sha256 cellar: :any_skip_relocation, arm64_sequoia: "3c15d547e848cda42bffcb56e8d797f81482495ff45207c808e214274617a8e8"
15-
sha256 cellar: :any_skip_relocation, arm64_sonoma: "0effbd63bd850eef30b7d75d73b8b863b91a9dc74d532e6ca762ad11d49b9ec4"
16-
sha256 cellar: :any_skip_relocation, arm64_ventura: "b9918fe74820758f11a0a6412e957764c155886d6c999fba9a9e822f2d7b75d2"
17-
sha256 cellar: :any_skip_relocation, sonoma: "c1840dfe57ce81fdeb13e63f89aa90569e572935db233f6a34597dae63fd1e12"
18-
sha256 cellar: :any_skip_relocation, ventura: "a077d43170858dc3121b56320315028cb625447e888b2d6265c98b6c24b4d164"
19-
sha256 cellar: :any_skip_relocation, x86_64_linux: "13c5e9e2ee72e70baeee0882d2b35a5b75137e4628ca839462d8df932585184e"
14+
sha256 cellar: :any_skip_relocation, arm64_sequoia: "0f2634f91560a0537344f4c84466e06fad5061c6eaf943136ffc82f2c8e8fa58"
15+
sha256 cellar: :any_skip_relocation, arm64_sonoma: "3903b29603e9926d540312e302a5f9c1e0338587c2d9ab71b40a00a00e3c22ce"
16+
sha256 cellar: :any_skip_relocation, arm64_ventura: "27e597c06a4606f5e189a8aafe97a67d1af2b1efde5a8919a380b8a4423df319"
17+
sha256 cellar: :any_skip_relocation, sonoma: "bedd743473f5afa26709ef42f2c729f9dd7c350930fb5d47b24c2ab575cb95bf"
18+
sha256 cellar: :any_skip_relocation, ventura: "72fb97b1e58463cfa0e40625ce6028be7f4f41c19ad0455af1ad0c31521cf70b"
19+
sha256 cellar: :any_skip_relocation, x86_64_linux: "926a42b854953ac8613d97785241bbc78a2ef4190b0c6680ddcf496a9e4d0d65"
2020
end
2121

2222
depends_on "cmake" => :build
@@ -53,6 +53,9 @@ def install
5353
-DCMAKE_C_COMPILER_WORKS=ON
5454
-DCMAKE_CXX_COMPILER_WORKS=ON
5555
-DCMAKE_SYSROOT=#{wasi_libc.opt_share}/wasi-sysroot
56+
-DCMAKE_FIND_FRAMEWORK=NEVER
57+
-DCMAKE_VERBOSE_MAKEFILE=ON
58+
-DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=#{HOMEBREW_LIBRARY_PATH}/cmake/trap_fetchcontent_provider.cmake
5659
]
5760
# Compiler flags taken from:
5861
# https://github.com/WebAssembly/wasi-sdk/blob/5e04cd81eb749edb5642537d150ab1ab7aedabe9/cmake/wasi-sdk-sysroot.cmake#L65-L75
@@ -75,7 +78,10 @@ def install
7578
(pkgshare/"lib").install_symlink "wasi" => "wasip1"
7679
(pkgshare/"lib").install_symlink "wasi" => "wasip2"
7780

78-
clang_resource_dir = Pathname.new(Utils.safe_popen_read(llvm.opt_bin/"clang", "-print-resource-dir").chomp)
81+
clang_resource_dir = Utils.safe_popen_read(llvm.opt_bin/"clang", "-print-resource-dir").chomp
82+
clang_resource_dir.sub! llvm.prefix.realpath, llvm.opt_prefix
83+
clang_resource_dir = Pathname.new(clang_resource_dir)
84+
7985
clang_resource_include_dir = clang_resource_dir/"include"
8086
clang_resource_include_dir.find do |pn|
8187
next unless pn.file?
@@ -84,16 +90,22 @@ def install
8490
target = pkgshare/relative_path
8591
next if target.exist?
8692

87-
target.parent.install_symlink pn
93+
target.parent.mkpath
94+
ln_s pn, target
8895
end
8996

97+
# FIXME: the build mistakenly concludes our toolchain doesn't support `-fno-exceptions`
98+
# because we have no `wasm-component-ld`. Remove the line below when
99+
# `wasm-component-ld` is merged.
100+
ENV.append_to_cflags "-fno-exceptions"
90101
target_configuration = Hash.new { |h, k| h[k] = {} }
91102

92103
targets.each do |target|
93104
# Configuration taken from:
94105
# https://github.com/WebAssembly/wasi-sdk/blob/5e04cd81eb749edb5642537d150ab1ab7aedabe9/cmake/wasi-sdk-sysroot.cmake#L227-L271
95106
configuration = target_configuration[target]
96-
configuration[:threads] = configuration[:pic] = target.end_with?("-threads") ? "ON" : "OFF"
107+
configuration[:threads] = target.end_with?("-threads") ? "ON" : "OFF"
108+
configuration[:pic] = target.end_with?("-threads") ? "OFF" : "ON"
97109
configuration[:flags] = target.end_with?("-threads") ? ["-pthread"] : []
98110

99111
cflags = ENV.cflags&.split || []
@@ -130,7 +142,7 @@ def install
130142
-DLIBCXX_ENABLE_FILESYSTEM:BOOL=ON
131143
-DLIBCXX_ENABLE_ABI_LINKER_SCRIPT:BOOL=OFF
132144
-DLIBCXX_CXX_ABI=libcxxabi
133-
-DLIBCXX_CXX_ABI_INCLUDE_PATHS=#{testpath}/libcxxabi/include
145+
-DLIBCXX_CXX_ABI_INCLUDE_PATHS=#{buildpath}/libcxxabi/include
134146
-DLIBCXX_HAS_MUSL_LIBC:BOOL=ON
135147
-DLIBCXX_ABI_VERSION=2
136148
-DLIBCXXABI_ENABLE_EXCEPTIONS:BOOL=OFF
@@ -157,6 +169,16 @@ def install
157169
system "cmake", "-S", "runtimes", "-B", "runtimes-#{target}", *target_cmake_args, *common_cmake_args
158170
system "cmake", "--build", "runtimes-#{target}"
159171
system "cmake", "--install", "runtimes-#{target}"
172+
173+
triple = Utils.safe_popen_read(llvm.opt_bin/"clang", "--target=#{target}", "--print-target-triple").chomp
174+
config_file = "#{triple}.cfg"
175+
176+
(buildpath/config_file).write <<~CONFIG
177+
--sysroot=#{HOMEBREW_PREFIX}/share/wasi-sysroot
178+
-resource-dir=#{HOMEBREW_PREFIX}/share/wasi-runtimes
179+
CONFIG
180+
181+
(etc/"clang").install config_file
160182
end
161183
(share/"wasi-sysroot/include/c++/v1").mkpath
162184
touch share/"wasi-sysroot/include/c++/v1/.keepme"
@@ -184,18 +206,14 @@ def install
184206
CPP
185207

186208
clang = Formula["llvm"].opt_bin/"clang"
187-
wasm_args = %W[
188-
--sysroot=#{HOMEBREW_PREFIX}/share/wasi-sysroot
189-
-resource-dir=#{HOMEBREW_PREFIX}/share/wasi-runtimes
190-
]
191209
targets.each do |target|
192210
# FIXME: Needs a working `wasm-component-ld`.
193211
next if target.include?("wasip2")
194212

195-
system clang, "--target=#{target}", *wasm_args, "-v", "test.c", "-o", "test-#{target}"
213+
system clang, "--target=#{target}", "-v", "test.c", "-o", "test-#{target}"
196214
assert_equal "the answer is 42", shell_output("wasmtime #{testpath}/test-#{target}")
197215

198-
system "#{clang}++", "--target=#{target}", *wasm_args, "-v", "test.cc", "-o", "test-cxx-#{target}"
216+
system "#{clang}++", "--target=#{target}", "-v", "test.cc", "-o", "test-cxx-#{target}"
199217
assert_equal "hello from C++ main with cout!", shell_output("wasmtime #{testpath}/test-cxx-#{target}").chomp
200218
end
201219
end

0 commit comments

Comments
 (0)