-
-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Expand file tree
/
Copy pathwazero.rb
More file actions
83 lines (68 loc) · 3.26 KB
/
Copy pathwazero.rb
File metadata and controls
83 lines (68 loc) · 3.26 KB
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.12.0.tar.gz"
sha256 "81afcc5576db589dda5403f71aa5ae2593222a7ba9671007484bf0ce6e21e7ba"
license "Apache-2.0"
livecheck do
url :stable
regex(/^v?(\d+(?:\.\d+)+)$/i)
end
bottle do
sha256 cellar: :any_skip_relocation, arm64_tahoe: "2b48c99c3b9ee63f59d9ed32d7f5ae4c40551248686bd4cd2434044d16c59b03"
sha256 cellar: :any_skip_relocation, arm64_sequoia: "2b48c99c3b9ee63f59d9ed32d7f5ae4c40551248686bd4cd2434044d16c59b03"
sha256 cellar: :any_skip_relocation, arm64_sonoma: "2b48c99c3b9ee63f59d9ed32d7f5ae4c40551248686bd4cd2434044d16c59b03"
sha256 cellar: :any_skip_relocation, sonoma: "820d56ab8fdc93c8305eb50378f794c2aff267ce59efc008cace240fd0674332"
sha256 cellar: :any_skip_relocation, arm64_linux: "112def4207427435ec33263a919ba870e0e75332ae0e8113a92bfb1ca6f9f70f"
sha256 cellar: :any, x86_64_linux: "3100242d33d61d5d21e3c19b9962e392cc5c4a5077725005a12f3d20bc9ca553"
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