binaryen 1.1.6 → 1.1.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -22
- data/lib/binaryen/command.rb +79 -15
- data/lib/binaryen/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 502cfbb2e9e33d3b32d5ab1881bf097fc7321bcb8746e2ae4b4142a6dbe3727a
|
4
|
+
data.tar.gz: 20c543218c8b5c256012e3b386e4cf6ceda9461899f10d990edcba0b983dbc17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a9d8542c524badbeb6721a9b6e9fc6cd9531e3a44134bce6206cba23c99c1d069850f85e0e222a0749de571d647e57a6f122dba6992661ef819f884581c7bcf
|
7
|
+
data.tar.gz: e62fa41cc97a4d777e10872d4ec9df6690ca5a5c6d773d8e01de897b93e41880e6bd676a5756776bbdf91629977402c6dec8f7e269a2c32909f1b62143773ba5
|
data/README.md
CHANGED
@@ -1,14 +1,29 @@
|
|
1
1
|
# `binaryen-rb`
|
2
2
|
|
3
|
-
[![
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/binaryen.svg)](https://badge.fury.io/rb/binaryen) | [![CI](https://github.com/Shopify/binaryen-rb/actions/workflows/test.yml/badge.svg)](https://github.com/Shopify/binaryen-rb/actions/workflows/test.yml)
|
4
|
+
|
5
|
+
A small gem which vendors [`binaryen` releases][binaryen] for easy use from Ruby. It includes the following executables:
|
6
|
+
|
7
|
+
Here's a version of the table with the descriptions shortened to a single sentence:
|
8
|
+
|
9
|
+
| exe | description |
|
10
|
+
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
11
|
+
| `wasm-split` | Splits a module into a primary and a secondary module, or instruments a module to gather a profile for future splitting. |
|
12
|
+
| `wasm-ctor-eval` | Executes code at compile time. |
|
13
|
+
| `wasm-merge` | Merges multiple wasm files into one. |
|
14
|
+
| `wasm-reduce` | Reduces a wasm file to a smaller one with the same behavior on a given command. |
|
15
|
+
| `wasm-metadce` | Performs dead code elimination (DCE) on a larger space that the wasm module is just a part of. |
|
16
|
+
| `wasm-shell` | Executes .wast files. |
|
17
|
+
| `wasm-fuzz-types` | Fuzzes type construction, canonicalization, and operations. |
|
18
|
+
| `wasm-fuzz-lattices` | Fuzzes lattices for reflexivity, transitivity, and anti-symmetry, and transfer functions for monotonicity. |
|
19
|
+
| `wasm-emscripten-finalize` | Performs Emscripten-specific transforms on .wasm files. |
|
20
|
+
| `wasm-as` | Assembles a .wat (WebAssembly text format) into a .wasm (WebAssembly binary format). |
|
21
|
+
| `wasm-opt` | Reads, writes, and optimizes files. |
|
22
|
+
| `wasm-dis` | Un-assembles a .wasm (WebAssembly binary format) into a .wat (WebAssembly text format). |
|
23
|
+
| `wasm2js` | Transforms .wasm/.wat files to asm.js. |
|
24
|
+
|
25
|
+
Please note that these are simplified descriptions and may not fully capture the functionality of each command. For a complete understanding, refer to the original descriptions or the respective command's documentation.
|
26
|
+
It also include `libinaryen` and it's corresponding header files, if you need them.
|
12
27
|
|
13
28
|
## Installation
|
14
29
|
|
@@ -22,16 +37,12 @@ Then run `bundle install`.
|
|
22
37
|
|
23
38
|
## Usage
|
24
39
|
|
25
|
-
This library only contains vendored
|
26
|
-
|
40
|
+
This library only contains vendored executables, and minimal Ruby code to invoke
|
41
|
+
them. You can see some examples of how to use this gem in the
|
42
|
+
[`./examples`](./examples) directory.
|
27
43
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
wasm_opt = Binaryen::Command.new("wasm-opt", timeout: 2)
|
32
|
-
result = wasm_opt.run("-O4", stdin: "(module)")
|
33
|
-
assert_equal("asm\x01", result.read.strip)
|
34
|
-
```
|
44
|
+
- [`./examples/wasm_opt.rb`](./examples/wasm_opt.rb) - Optimize a WebAssembly module
|
45
|
+
- [`./examples/wasm_split.rb`](./examples/wasm_split.rb) - Strip a WebAssembly module
|
35
46
|
|
36
47
|
## Contributing
|
37
48
|
|
@@ -39,11 +50,11 @@ Bug reports and pull requests are welcome on GitHub at
|
|
39
50
|
https://github.com/Shopify/binaryen-rb. Signing Shopify's CLA is a mandatory
|
40
51
|
when opening, you will be prompted to do so by a Github action.
|
41
52
|
|
42
|
-
Read and follow the guidelines in [CONTRIBUTING.md](
|
53
|
+
Read and follow the guidelines in [CONTRIBUTING.md](./CONTRIBUTING.md).
|
43
54
|
|
44
55
|
## Releases
|
45
56
|
|
46
|
-
This gem is published to [Rubygems]
|
57
|
+
This gem is published to [Rubygems][rubygems].
|
47
58
|
|
48
59
|
The procedure to publish a new release version is as follows:
|
49
60
|
|
@@ -51,8 +62,12 @@ The procedure to publish a new release version is as follows:
|
|
51
62
|
* Run bundle install to bump the version of the gem in `Gemfile.lock`
|
52
63
|
* Open a pull request, review, and merge
|
53
64
|
* Review commits since the last release to identify user-facing changes that should be included in the release notes
|
54
|
-
* [Create a
|
55
|
-
* [Deploy via Shipit]
|
65
|
+
* [Create a relase on GitHub][gh-release] with a version number that matches `lib/binaryen/version.rb`. Pick the `Create new tag` option. More on [creating releases][gh-release-notes]
|
66
|
+
* [Deploy via Shipit][shipit] and see your [latest version on Rubygems][rubygems]
|
56
67
|
|
57
68
|
|
58
69
|
[binaryen]: https://github.com/WebAssembly/binaryen/releases
|
70
|
+
[rubygems]: https://rubygems.org/gems/binaryen
|
71
|
+
[shipit]: https://shipit.shopify.io/shopify/binaryen-rb/release
|
72
|
+
[gh-release]: https://github.com/Shopify/binaryen-rb/releases/new
|
73
|
+
[gh-release-notes]: https://help.github.com/articles/creating-releases
|
data/lib/binaryen/command.rb
CHANGED
@@ -11,13 +11,30 @@ module Binaryen
|
|
11
11
|
#
|
12
12
|
# ```ruby
|
13
13
|
# command = Binaryen::Command.new("wasm-opt", timeout: 10)
|
14
|
-
# optimized_wasm = command.run("-O4", stdin: "(module)")
|
14
|
+
# optimized_wasm = command.run("-O4", stdin: "(module)")
|
15
15
|
# ```
|
16
16
|
class Command
|
17
17
|
DEFAULT_ARGS_FOR_COMMAND = {
|
18
18
|
"wasm-opt" => ["--output=-"],
|
19
19
|
}.freeze
|
20
20
|
|
21
|
+
class TimeoutChecker
|
22
|
+
def initialize(end_time:, pid:)
|
23
|
+
@end_time = end_time
|
24
|
+
@pid = pid
|
25
|
+
end
|
26
|
+
|
27
|
+
def check!
|
28
|
+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
29
|
+
if now >= @end_time
|
30
|
+
Process.kill("KILL", @pid)
|
31
|
+
raise Timeout::Error, "Command timed out"
|
32
|
+
end
|
33
|
+
remaining_time = @end_time - now
|
34
|
+
remaining_time
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
21
38
|
def initialize(cmd, timeout: 10, ignore_missing: false)
|
22
39
|
@cmd = command_path(cmd, ignore_missing) || raise(ArgumentError, "command not found: #{cmd}")
|
23
40
|
@timeout = timeout
|
@@ -25,26 +42,73 @@ module Binaryen
|
|
25
42
|
end
|
26
43
|
|
27
44
|
def run(*arguments, stdin: nil, stderr: File::NULL)
|
28
|
-
|
45
|
+
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + @timeout
|
29
46
|
command = build_command(*arguments)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
47
|
+
pipe = IO.popen(command, "rb+", err: stderr)
|
48
|
+
pid = pipe.pid
|
49
|
+
timeout_checker = TimeoutChecker.new(end_time: end_time, pid: pid)
|
50
|
+
|
51
|
+
write_to_pipe(pipe, stdin, timeout_checker) if stdin
|
52
|
+
output = read_from_pipe(pipe, timeout_checker)
|
53
|
+
wait_or_kill(pid, timeout_checker)
|
54
|
+
|
55
|
+
output
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def write_to_pipe(pipe, stdin, timeout_checker)
|
61
|
+
offset = 0
|
62
|
+
length = stdin.bytesize
|
63
|
+
|
64
|
+
while offset < length
|
65
|
+
remaining_time = timeout_checker.check!
|
66
|
+
|
67
|
+
if IO.select(nil, [pipe], nil, remaining_time)
|
68
|
+
written = pipe.write_nonblock(stdin.byteslice(offset, length), exception: false)
|
69
|
+
offset += written if written.is_a?(Integer)
|
70
|
+
else
|
71
|
+
raise Timeout::Error, "Command timed out"
|
41
72
|
end
|
73
|
+
end
|
74
|
+
|
75
|
+
pipe.close_write
|
76
|
+
end
|
77
|
+
|
78
|
+
def read_from_pipe(pipe, timeout_checker)
|
79
|
+
output = +""
|
42
80
|
|
43
|
-
|
81
|
+
while (result = pipe.read_nonblock(8192, exception: false))
|
82
|
+
remaining_time = timeout_checker.check!
|
83
|
+
raise Timeout::Error, "Command timed out" if remaining_time <= 0
|
84
|
+
|
85
|
+
case result
|
86
|
+
when :wait_readable
|
87
|
+
IO.select([pipe], nil, nil, remaining_time)
|
88
|
+
when nil
|
89
|
+
break
|
90
|
+
else
|
91
|
+
output << result
|
92
|
+
end
|
44
93
|
end
|
94
|
+
|
95
|
+
output
|
45
96
|
end
|
46
97
|
|
47
|
-
|
98
|
+
def wait_or_kill(pid, timeout_checker)
|
99
|
+
loop do
|
100
|
+
remaining_time = timeout_checker.check!
|
101
|
+
raise Timeout::Error, "timed out waiting on process" if remaining_time <= 0
|
102
|
+
|
103
|
+
if (_, status = Process.wait2(pid, Process::WNOHANG))
|
104
|
+
raise Binaryen::NonZeroExitStatus, "command exited with status #{status.exitstatus}" if status.exitstatus != 0
|
105
|
+
|
106
|
+
return true
|
107
|
+
else
|
108
|
+
sleep(0.1)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
48
112
|
|
49
113
|
def build_command(*arguments)
|
50
114
|
Shellwords.join([@cmd] + arguments + @default_args)
|
data/lib/binaryen/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: binaryen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.6
|
4
|
+
version: 1.1.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11
|
11
|
+
date: 2023-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
|
-
rubygems_version: 3.4.
|
95
|
+
rubygems_version: 3.4.22
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: Vendors binaryen libraries, headers, and executables for use in Ruby
|