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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79531a2c434673dc0e59cfbf5d1ff033267132198e0de1a0e24d0803d6c8f472
4
- data.tar.gz: d7fffe6247cb63d59058342f791e1e1847add67b9927495f2d4cf78e3c186ae5
3
+ metadata.gz: 502cfbb2e9e33d3b32d5ab1881bf097fc7321bcb8746e2ae4b4142a6dbe3727a
4
+ data.tar.gz: 20c543218c8b5c256012e3b386e4cf6ceda9461899f10d990edcba0b983dbc17
5
5
  SHA512:
6
- metadata.gz: 04faf1e73bb50578cb015551e48bc1a7557e8a9861f5ad94fd9485aec4e0f966365a278784165154a72ab654ec256390bca29815d6dff42d9d31444bd64fd26e
7
- data.tar.gz: f6327a9e5afce78253840ee70299d3b481adf2365ef216386c0e93ab1325369051c5ad67aba738effd11703ac1b428186ef6adefb724b3c1737cd2599faafd21
6
+ metadata.gz: 2a9d8542c524badbeb6721a9b6e9fc6cd9531e3a44134bce6206cba23c99c1d069850f85e0e222a0749de571d647e57a6f122dba6992661ef819f884581c7bcf
7
+ data.tar.gz: e62fa41cc97a4d777e10872d4ec9df6690ca5a5c6d773d8e01de897b93e41880e6bd676a5756776bbdf91629977402c6dec8f7e269a2c32909f1b62143773ba5
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,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)").read
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
- pid = nil
45
+ end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + @timeout
29
46
  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}"
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
- output
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
- private
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)
@@ -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.2"
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.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-30 00:00:00.000000000 Z
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.21
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