binaryen 1.1.6 → 1.1.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79531a2c434673dc0e59cfbf5d1ff033267132198e0de1a0e24d0803d6c8f472
4
- data.tar.gz: d7fffe6247cb63d59058342f791e1e1847add67b9927495f2d4cf78e3c186ae5
3
+ metadata.gz: f28c12d0f3983f4a8856a70bd62767df1021eac072a97edea0174b59648519d1
4
+ data.tar.gz: 6973598a0a4d375e1445a6d463853b6a37a4343b735c191fa10b7457cdb4273e
5
5
  SHA512:
6
- metadata.gz: 04faf1e73bb50578cb015551e48bc1a7557e8a9861f5ad94fd9485aec4e0f966365a278784165154a72ab654ec256390bca29815d6dff42d9d31444bd64fd26e
7
- data.tar.gz: f6327a9e5afce78253840ee70299d3b481adf2365ef216386c0e93ab1325369051c5ad67aba738effd11703ac1b428186ef6adefb724b3c1737cd2599faafd21
6
+ metadata.gz: 31693bb150232527b2ebae35f6a44f72d3af7a02ec3d6370df366226eb7e4b718375db2c832f6fe169a843c1c4b4ced9116d0d4e247a4805d473c01f8d9677a9
7
+ data.tar.gz: feac4bb36b20f5b5e0d7907fb2cad013e2c90c23bb5cdb7b233ca0e74407ab558de9f765b2bd8adcbe9148976363b1dca9781b6dbf37dead3f0dac867c36eaad
data/README.md CHANGED
@@ -1,14 +1,29 @@
1
1
  # `binaryen-rb`
2
2
 
3
- [![Latest version of 'binaryen' @ Cloudsmith](https://api-prd.cloudsmith.io/v1/badges/version/shopify/gems/ruby/binaryen/latest/a=arm64-darwin;xp=arm64-darwin/?render=true&show_latest=true&badge_token=gAAAAABkK04DV1HW1IJsownx5q-cChJ6cFdRDg24g8RHpDMUkX3k_bPW1hcwcldoJ-m2uO3wwFPO7E9Z1D8xu1l-PHghoV7q8Pj0jYHuZ5ce3iHVMVgdMvE%3D)](https://cloudsmith.io/~shopify/repos/gems/packages/detail/ruby/binaryen/latest/a=arm64-darwin;xp=arm64-darwin/)
4
- [![Build status](https://badge.buildkite.com/add062a055afaa789b95b55688346674dfcaaea0c962470740.svg)](https://buildkite.com/shopify/binaryen-rb)
5
-
6
- A small gem which vendors [`binaryen` releases][binaryen] for common Ruby platforms.
7
-
8
- | | |
9
- | ----- | ------------------------------------------------------------------------- |
10
- | Owner | [@Shopify/liquid-perf](https://github.com/orgs/Shopify/teams/liquid-perf) |
11
- | Help | [#liquid-perf](https://shopify.slack.com/archives/C03AE40AL1W) |
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 binaries, and minimal Ruby code. It is
26
- intended to be used by other gems which depend on `binaryen`.
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
- ```ruby
29
- require "binaryen"
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](https://github.com/Shopify/binaryen-rb/blob/main/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](https://rubygems.org/gems/binaryen).
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 release on GitHub](https://github.com/Shopify/binaryen-rb/releases/new) with a version number that matches `lib/binaryen/version.rb`. More on [creating releases](https://help.github.com/articles/creating-releases).
55
- * [Deploy via Shipit](https://shipit.shopify.io/shopify/binaryen-rb/cloudsmith) and see your [latest version on Cloudsmith](https://cloudsmith.io/~shopify/repos/gems/packages/detail/ruby/binaryen-rb/latest)
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
@@ -11,7 +11,7 @@ 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)").read
14
+ # optimized_wasm = command.run("-O4", stdin: "(module)")
15
15
  # ```
16
16
  class Command
17
17
  DEFAULT_ARGS_FOR_COMMAND = {
@@ -25,27 +25,98 @@ module Binaryen
25
25
  end
26
26
 
27
27
  def run(*arguments, stdin: nil, stderr: File::NULL)
28
- pid = nil
29
28
  command = build_command(*arguments)
30
- Timeout.timeout(@timeout) do
31
- pipe = IO.popen(command, "rb+", err: stderr)
32
- pid = pipe.pid
33
- pipe.write(stdin) if stdin
34
- pipe.close_write
35
- output = pipe
36
- Process.wait(pid)
37
- pid = nil
38
-
39
- if $CHILD_STATUS.exitstatus != 0
40
- raise Binaryen::NonZeroExitStatus, "command exited with status #{$CHILD_STATUS.exitstatus}: #{command}"
41
- end
29
+ pipe = IO.popen(command, "rb+", err: stderr)
30
+ pid = pipe.pid
31
+ start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
32
+ remaining_timeout = @timeout
42
33
 
43
- output
34
+ if stdin
35
+ start_time, remaining_timeout = write_to_pipe(pipe, stdin, start_time, remaining_timeout)
44
36
  end
37
+
38
+ output, remaining_timeout = read_from_pipe(pipe, start_time, remaining_timeout)
39
+
40
+ wait_or_kill(pid, start_time, remaining_timeout)
41
+
42
+ output
45
43
  end
46
44
 
47
45
  private
48
46
 
47
+ def write_to_pipe(pipe, stdin, start_time, remaining_timeout)
48
+ offset = 0
49
+ length = stdin.bytesize
50
+
51
+ while offset < length
52
+ start_time, remaining_timeout = update_timeout(start_time, remaining_timeout)
53
+ if IO.select(nil, [pipe], nil, remaining_timeout)
54
+ written = pipe.write_nonblock(stdin.byteslice(offset, length), exception: false)
55
+ case written
56
+ when Integer
57
+ offset += written
58
+ when :wait_writable
59
+ puts "wait"
60
+ # If the pipe is not ready for writing, retry
61
+ end
62
+ else
63
+ raise Timeout::Error, "Command timed out"
64
+ end
65
+ end
66
+
67
+ pipe.close_write
68
+ [start_time, remaining_timeout]
69
+ end
70
+
71
+ def read_from_pipe(pipe, start_time, remaining_timeout)
72
+ output = +""
73
+
74
+ while (result = pipe.read_nonblock(8192, exception: false))
75
+ start_time, remaining_timeout = update_timeout(start_time, remaining_timeout)
76
+
77
+ case result
78
+ when :wait_readable
79
+ IO.select([pipe], nil, nil, remaining_timeout)
80
+ when nil
81
+ break
82
+ else
83
+ output << result
84
+ end
85
+ end
86
+
87
+ [output, remaining_timeout]
88
+ end
89
+
90
+ def update_timeout(start_time, remaining_timeout)
91
+ elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
92
+ remaining_timeout -= elapsed_time
93
+
94
+ raise Timeout::Error, "command timed out" if remaining_timeout <= 0
95
+
96
+ start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
97
+
98
+ [start_time, remaining_timeout]
99
+ end
100
+
101
+ def wait_or_kill(pid, start_time, remaining_timeout)
102
+ while remaining_timeout > 0
103
+ start_time, remaining_timeout = update_timeout(start_time, remaining_timeout)
104
+
105
+ if (_, status = Process.wait2(pid, Process::WNOHANG))
106
+ if status.exitstatus != 0
107
+ raise Binaryen::NonZeroExitStatus, "command exited with status #{status.exitstatus}"
108
+ end
109
+
110
+ return true
111
+ else
112
+ sleep(0.1)
113
+ end
114
+ end
115
+
116
+ Process.kill("KILL", pid)
117
+ raise Timeout::Error, "timed out waiting on process"
118
+ end
119
+
49
120
  def build_command(*arguments)
50
121
  Shellwords.join([@cmd] + arguments + @default_args)
51
122
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Binaryen
4
- VERSION = "1.1.6"
4
+ VERSION = "1.1.6.1"
5
5
  BINARYEN_VERSION = "version_116"
6
6
  end
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.1
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-30 00:00:00.000000000 Z
11
+ date: 2023-12-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: