Skip to content

Commit ca2eeea

Browse files
committed
wasm-component-ld 0.5.10 (new formula)
This is needed to enable the `rust` formula to target WASI, and will enable us to remove existing uses of `rustup` at build-time.
1 parent 75c0a69 commit ca2eeea

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

Formula/w/wasm-component-ld.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
class WasmComponentLd < Formula
2+
desc "Linker for creating WebAssembly components"
3+
homepage "https://wasi.dev"
4+
url "https://github.com/bytecodealliance/wasm-component-ld/archive/refs/tags/v0.5.10.tar.gz"
5+
sha256 "aa049a93da595e4dacf742865f13e7fb1cec1ab47de9258f0a11d81ad6c7a77b"
6+
license "Apache-2.0"
7+
head "https://github.com/bytecodealliance/wasm-component-ld.git", branch: "main"
8+
9+
depends_on "rust" => :build
10+
depends_on "lld" => :test
11+
depends_on "llvm" => :test
12+
depends_on "wasi-libc" => :test
13+
depends_on "wasmtime" => :test
14+
15+
def install
16+
system "cargo", "install", *std_cargo_args
17+
end
18+
19+
test do
20+
resource "builtins" do
21+
url "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-24/libclang_rt.builtins-wasm32-wasi-24.0.tar.gz"
22+
sha256 "7e33c0df758b90469b1de3ca158e2d0a7f71934d5884525ba6a372de0b3b0ec7"
23+
end
24+
25+
ENV.remove_macosxsdk if OS.mac?
26+
ENV.remove_cc_etc
27+
28+
(testpath/"test.c").write <<~C
29+
#include <stdio.h>
30+
volatile int x = 42;
31+
int main(void) {
32+
printf("the answer is %d", x);
33+
return 0;
34+
}
35+
C
36+
37+
clang = Formula["llvm"].opt_bin/"clang"
38+
clang_resource_dir = Pathname.new(shell_output("#{clang} --print-resource-dir").chomp)
39+
testpath.install_symlink clang_resource_dir/"include"
40+
resource("builtins").stage testpath/"lib/wasm32-unknown-wasip2"
41+
(testpath/"lib/wasm32-unknown-wasip2").install_symlink "libclang_rt.builtins-wasm32.a" => "libclang_rt.builtins.a"
42+
wasm_args = %W[--target=wasm32-wasip2 --sysroot=#{Formula["wasi-libc"].opt_share}/wasi-sysroot]
43+
system clang, *wasm_args, "-v", "test.c", "-o", "test", "-resource-dir=#{testpath}"
44+
assert_equal "the answer is 42", shell_output("wasmtime #{testpath}/test")
45+
end
46+
end

0 commit comments

Comments
 (0)