Skip to content

Commit 75b439d

Browse files
committed
wasi-runtimes: various fixes
- avoid references LLVM Cellar paths in symlinks, as these will break on version updates to LLVM - make `lld` a test-only dependency, since it's not required at build-time
1 parent ca2eeea commit 75b439d

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

Formula/w/wasi-runtimes.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class WasiRuntimes < Formula
2222
depends_on "cmake" => :build
2323
depends_on "lld" => [:build, :test]
2424
depends_on "wasi-libc" => [:build, :test]
25+
depends_on "wasm-component-ld" => [:build, :test]
2526
depends_on "wasmtime" => :test
2627
depends_on "llvm"
2728

@@ -53,6 +54,9 @@ def install
5354
-DCMAKE_C_COMPILER_WORKS=ON
5455
-DCMAKE_CXX_COMPILER_WORKS=ON
5556
-DCMAKE_SYSROOT=#{wasi_libc.opt_share}/wasi-sysroot
57+
-DCMAKE_FIND_FRAMEWORK=NEVER
58+
-DCMAKE_VERBOSE_MAKEFILE=ON
59+
-DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=#{HOMEBREW_LIBRARY_PATH}/cmake/trap_fetchcontent_provider.cmake
5660
]
5761
# Compiler flags taken from:
5862
# https://github.com/WebAssembly/wasi-sdk/blob/5e04cd81eb749edb5642537d150ab1ab7aedabe9/cmake/wasi-sdk-sysroot.cmake#L65-L75
@@ -75,7 +79,9 @@ def install
7579
(pkgshare/"lib").install_symlink "wasi" => "wasip1"
7680
(pkgshare/"lib").install_symlink "wasi" => "wasip2"
7781

78-
clang_resource_dir = Pathname.new(Utils.safe_popen_read(llvm.opt_bin/"clang", "-print-resource-dir").chomp)
82+
clang_resource_dir = Utils.safe_popen_read(llvm.opt_bin/"clang", "-print-resource-dir").chomp
83+
clang_resource_dir.sub! llvm.prefix.realpath, llvm.opt_prefix
84+
clang_resource_dir = Pathname.new(clang_resource_dir)
7985
clang_resource_include_dir = clang_resource_dir/"include"
8086
clang_resource_include_dir.find do |pn|
8187
next unless pn.file?
@@ -84,7 +90,8 @@ 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

9097
target_configuration = Hash.new { |h, k| h[k] = {} }
@@ -93,7 +100,8 @@ def install
93100
# Configuration taken from:
94101
# https://github.com/WebAssembly/wasi-sdk/blob/5e04cd81eb749edb5642537d150ab1ab7aedabe9/cmake/wasi-sdk-sysroot.cmake#L227-L271
95102
configuration = target_configuration[target]
96-
configuration[:threads] = configuration[:pic] = target.end_with?("-threads") ? "ON" : "OFF"
103+
configuration[:threads] = target.end_with?("-threads") ? "ON" : "OFF"
104+
configuration[:pic] = target.end_with?("-threads") ? "OFF" : "ON"
97105
configuration[:flags] = target.end_with?("-threads") ? ["-pthread"] : []
98106

99107
cflags = ENV.cflags&.split || []
@@ -130,7 +138,7 @@ def install
130138
-DLIBCXX_ENABLE_FILESYSTEM:BOOL=ON
131139
-DLIBCXX_ENABLE_ABI_LINKER_SCRIPT:BOOL=OFF
132140
-DLIBCXX_CXX_ABI=libcxxabi
133-
-DLIBCXX_CXX_ABI_INCLUDE_PATHS=#{testpath}/libcxxabi/include
141+
-DLIBCXX_CXX_ABI_INCLUDE_PATHS=#{buildpath}/libcxxabi/include
134142
-DLIBCXX_HAS_MUSL_LIBC:BOOL=ON
135143
-DLIBCXX_ABI_VERSION=2
136144
-DLIBCXXABI_ENABLE_EXCEPTIONS:BOOL=OFF
@@ -189,9 +197,6 @@ def install
189197
-resource-dir=#{HOMEBREW_PREFIX}/share/wasi-runtimes
190198
]
191199
targets.each do |target|
192-
# FIXME: Needs a working `wasm-component-ld`.
193-
next if target.include?("wasip2")
194-
195200
system clang, "--target=#{target}", *wasm_args, "-v", "test.c", "-o", "test-#{target}"
196201
assert_equal "the answer is 42", shell_output("wasmtime #{testpath}/test-#{target}")
197202

0 commit comments

Comments
 (0)