Skip to content

Commit f347d81

Browse files
committed
wasi-runtimes 19.1.3
Also: - avoid referencing LLVM cellar paths in symlinks - fix some build flags - add config files to simplify usage with our clang
1 parent 7edc8ce commit f347d81

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

Formula/w/wasi-runtimes.rb

Lines changed: 30 additions & 12 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

@@ -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)