Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 1 addition & 7 deletions Formula/w/wasi-runtimes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class WasiRuntimes < Formula
depends_on "cmake" => :build
depends_on "lld" => [:build, :test]
depends_on "wasi-libc" => [:build, :test]
depends_on "wasm-component-ld" => [:build, :test]
Comment thread
carlocab marked this conversation as resolved.
Outdated
depends_on "wasmtime" => :test
depends_on "llvm"

Expand Down Expand Up @@ -94,10 +95,6 @@ def install
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|
Expand Down Expand Up @@ -207,9 +204,6 @@ def install

clang = Formula["llvm"].opt_bin/"clang"
targets.each do |target|
# FIXME: Needs a working `wasm-component-ld`.
next if target.include?("wasip2")

system clang, "--target=#{target}", "-v", "test.c", "-o", "test-#{target}"
assert_equal "the answer is 42", shell_output("wasmtime #{testpath}/test-#{target}")

Expand Down
46 changes: 46 additions & 0 deletions Formula/w/wasm-component-ld.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class WasmComponentLd < Formula
desc "Linker for creating WebAssembly components"
homepage "https://wasi.dev"
url "https://github.com/bytecodealliance/wasm-component-ld/archive/refs/tags/v0.5.10.tar.gz"
sha256 "aa049a93da595e4dacf742865f13e7fb1cec1ab47de9258f0a11d81ad6c7a77b"
license "Apache-2.0"
head "https://github.com/bytecodealliance/wasm-component-ld.git", branch: "main"

depends_on "rust" => :build
depends_on "lld" => :test
depends_on "llvm" => :test
depends_on "wasi-libc" => :test
depends_on "wasmtime" => :test

def install
system "cargo", "install", *std_cargo_args
end

test do
resource "builtins" do
url "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-24/libclang_rt.builtins-wasm32-wasi-24.0.tar.gz"
sha256 "7e33c0df758b90469b1de3ca158e2d0a7f71934d5884525ba6a372de0b3b0ec7"
end

ENV.remove_macosxsdk if OS.mac?
ENV.remove_cc_etc

(testpath/"test.c").write <<~C
#include <stdio.h>
volatile int x = 42;
int main(void) {
printf("the answer is %d", x);
return 0;
}
C

clang = Formula["llvm"].opt_bin/"clang"
clang_resource_dir = Pathname.new(shell_output("#{clang} --print-resource-dir").chomp)
testpath.install_symlink clang_resource_dir/"include"
resource("builtins").stage testpath/"lib/wasm32-unknown-wasip2"
(testpath/"lib/wasm32-unknown-wasip2").install_symlink "libclang_rt.builtins-wasm32.a" => "libclang_rt.builtins.a"
wasm_args = %W[--target=wasm32-wasip2 --sysroot=#{Formula["wasi-libc"].opt_share}/wasi-sysroot]
system clang, *wasm_args, "-v", "test.c", "-o", "test", "-resource-dir=#{testpath}"
assert_equal "the answer is 42", shell_output("wasmtime #{testpath}/test")
end
end