Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions Formula/w/wasi-runtimes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class WasiRuntimes < Formula
end

depends_on "cmake" => :build
depends_on "lld" => [:build, :test]
depends_on "wasi-libc" => [:build, :test]
depends_on "lld" => :test
depends_on "wasmtime" => :test
depends_on "llvm"

Expand Down Expand Up @@ -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
Expand All @@ -75,7 +78,9 @@ 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?
Expand All @@ -84,9 +89,17 @@ def install
target = pkgshare/relative_path
next if target.exist?

target.parent.install_symlink pn
target.parent.mkpath
ln_s pn, target
end

# We set `-DLIBCXX_ENABLE_EXCEPTIONS=OFF` and `-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF`, but the
# the check for support for the `-fno-exceptions` flag erroneously fails because we don't
# have a WASM linker in our build environment. Pass the flag anyway because we know it works.
# See:
# - https://github.com/llvm/llvm-project/blob/62ff85f0799560b42754ef77b5f64ca2c7feeff7/libcxx/CMakeLists.txt#L551-L560
# - https://github.com/llvm/llvm-project/blob/62ff85f0799560b42754ef77b5f64ca2c7feeff7/runtimes/cmake/Modules/HandleFlags.cmake#L37-L40
ENV.append_to_cflags "-fno-exceptions"
target_configuration = Hash.new { |h, k| h[k] = {} }

targets.each do |target|
Expand Down Expand Up @@ -130,7 +143,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
Expand Down