-
-
Notifications
You must be signed in to change notification settings - Fork 12.7k
/
Copy pathwazero.rb
83 lines (68 loc) · 3.26 KB
/
wazero.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
class Wazero < Formula
desc "Zero dependency WebAssembly runtime"
homepage "https://wazero.io"
url "https://github.com/tetratelabs/wazero/archive/refs/tags/v1.9.0.tar.gz"
sha256 "b294ef32baf69cb7ef9be85ecdfa13b0e59a4bac2f1ad58ec21231e7e0d592e0"
license "Apache-2.0"
livecheck do
url :stable
regex(/^v?(\d+(?:\.\d+)+)$/i)
end
bottle do
sha256 cellar: :any_skip_relocation, arm64_sequoia: "c6c3e483291dbea6101c7498979e8f1186e5a3eeb71c594b4230d65a59599f27"
sha256 cellar: :any_skip_relocation, arm64_sonoma: "c6c3e483291dbea6101c7498979e8f1186e5a3eeb71c594b4230d65a59599f27"
sha256 cellar: :any_skip_relocation, arm64_ventura: "c6c3e483291dbea6101c7498979e8f1186e5a3eeb71c594b4230d65a59599f27"
sha256 cellar: :any_skip_relocation, sonoma: "0047c80bd8e21271e33bd11ccd8f245b5c5ea63aebf33cabcd32e1cc8757330b"
sha256 cellar: :any_skip_relocation, ventura: "0047c80bd8e21271e33bd11ccd8f245b5c5ea63aebf33cabcd32e1cc8757330b"
sha256 cellar: :any_skip_relocation, x86_64_linux: "ff1579937c7bc3110eb9c001456a6d16dce670eb805e1492546dfedf05127391"
end
depends_on "go" => :build
depends_on "wabt" => :test
def install
ldflags = %W[
-s -w
-X github.com/tetratelabs/wazero/internal/version.version=#{version}
]
system "go", "build", *std_go_args(ldflags:), "./cmd/wazero"
end
test do
assert_equal version.to_s, shell_output("#{bin}/wazero version").chomp
(testpath/"mount.wat").write <<~EOS
;; print the preopen directory path (guest side of the mount).
(module
(import "wasi_snapshot_preview1" "fd_prestat_get"
(func $wasi.fd_prestat_get (param i32 i32) (result i32)))
(import "wasi_snapshot_preview1" "fd_prestat_dir_name"
(func $wasi.fd_prestat_dir_name (param i32 i32 i32) (result i32)))
(import "wasi_snapshot_preview1" "fd_write"
(func $wasi.fd_write (param i32 i32 i32 i32) (result i32)))
(memory (export "memory") 1 1)
(func $main (export "_start")
;; First, we need to know the size of the prestat dir name.
(call $wasi.fd_prestat_get
(i32.const 3) ;; preopen FD
(i32.const 0)) ;; where to write prestat
(drop) ;; ignore the errno returned
;; Next, write the dir name to offset 8 (past the prestat).
(call $wasi.fd_prestat_dir_name
(i32.const 3) ;; preopen FD
(i32.const 8) ;; where to write dir_name
(i32.load (i32.const 4))) ;; length is the last part of the prestat
(drop) ;; ignore the errno returned
;; Now, convert the prestat to an iovec [offset, len] writing offset=8.
(i32.store (i32.const 0) (i32.const 8))
;; Finally, copy the dirname to stdout via its iovec [offset, len].
(call $wasi.fd_write
(i32.const 1) ;; stdout
(i32.const 0) ;; where's the iovec
(i32.const 1) ;; only one iovec
(i32.const 0)) ;; overwrite the iovec with the ignored result.
(drop) ;; ignore the errno returned
)
)
EOS
system "wat2wasm", testpath/"mount.wat", "-o", testpath/"mount.wasm"
assert_equal "/homebrew",
shell_output("#{bin}/wazero run -mount=/tmp:/homebrew #{testpath/"mount.wasm"}")
end
end