binaryen 1.1.6.pre.3 → 1.1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 773664dfc73f0168da19636afb23f35106e2b0426f7f6ff22c15e790e4fba882
4
- data.tar.gz: af7edac7322317bd39100d7e65d0cfc43f48a8aa9f63ac3ca2c5564dff775a62
3
+ metadata.gz: f28c12d0f3983f4a8856a70bd62767df1021eac072a97edea0174b59648519d1
4
+ data.tar.gz: 6973598a0a4d375e1445a6d463853b6a37a4343b735c191fa10b7457cdb4273e
5
5
  SHA512:
6
- metadata.gz: 2af49d37b27f4dafd1abb76139b103bacd95cae2434c2913ed0f45d04b121c5a3cdf2fe110b3662cfc14b574416dade62e433c6ec0a49d981cd1075c0e4417d7
7
- data.tar.gz: 39195bc078126fabdab98f97eb3a8d6cbb9ce1b06211af6c96078ec888dddadefe00de8344ed6dc282855cffffa11f7343a35ec15f3218e2eddab879a400ef61
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.pre.3"
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.pre.3
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:
@@ -88,9 +88,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  requirements:
91
- - - ">"
91
+ - - ">="
92
92
  - !ruby/object:Gem::Version
93
- version: 1.3.1
93
+ version: '0'
94
94
  requirements: []
95
95
  rubygems_version: 3.4.21
96
96
  signing_key: