binaryen 1.1.6.2 → 1.1.6.4

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: 502cfbb2e9e33d3b32d5ab1881bf097fc7321bcb8746e2ae4b4142a6dbe3727a
4
- data.tar.gz: 20c543218c8b5c256012e3b386e4cf6ceda9461899f10d990edcba0b983dbc17
3
+ metadata.gz: e0f235a249bcf6c38016c2033776997d2d636126cea0b37d47c98dc2b932dd08
4
+ data.tar.gz: 3f123ebb5bdb0f24ebf004097e02ccab417d09838e9ec663a87e43ae472cb9a1
5
5
  SHA512:
6
- metadata.gz: 2a9d8542c524badbeb6721a9b6e9fc6cd9531e3a44134bce6206cba23c99c1d069850f85e0e222a0749de571d647e57a6f122dba6992661ef819f884581c7bcf
7
- data.tar.gz: e62fa41cc97a4d777e10872d4ec9df6690ca5a5c6d773d8e01de897b93e41880e6bd676a5756776bbdf91629977402c6dec8f7e269a2c32909f1b62143773ba5
6
+ metadata.gz: 8d58caa196cbc38e9178dba6fa0efdcdde270d298ef5c3f34e523f5281630ae18c32bac9bd6da379fb7b758a536b94afc2c3c3faddb68118c5ccb64255c256da
7
+ data.tar.gz: 85f826a48ba40d0e3d48e4806cc52faf265c058b53421af32efdc67eb811075f99c7e83488f6aab85b141478cac104c2d1031931374df75c650972107c8acd5a
@@ -3,6 +3,7 @@
3
3
  require "English"
4
4
  require "shellwords"
5
5
  require "timeout"
6
+ require "posix/spawn"
6
7
 
7
8
  module Binaryen
8
9
  # Wrapper around a binaryen executable command with a timeout and streaming IO.
@@ -14,6 +15,8 @@ module Binaryen
14
15
  # optimized_wasm = command.run("-O4", stdin: "(module)")
15
16
  # ```
16
17
  class Command
18
+ include POSIX::Spawn
19
+
17
20
  DEFAULT_ARGS_FOR_COMMAND = {
18
21
  "wasm-opt" => ["--output=-"],
19
22
  }.freeze
@@ -41,23 +44,26 @@ module Binaryen
41
44
  @default_args = DEFAULT_ARGS_FOR_COMMAND.fetch(cmd, [])
42
45
  end
43
46
 
44
- def run(*arguments, stdin: nil, stderr: File::NULL)
47
+ def run(*arguments, stdin: nil, stderr: nil)
45
48
  end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + @timeout
46
49
  command = build_command(*arguments)
47
- pipe = IO.popen(command, "rb+", err: stderr)
48
- pid = pipe.pid
50
+ pid, iwr, ord, erd = popen4(*command)
49
51
  timeout_checker = TimeoutChecker.new(end_time: end_time, pid: pid)
50
52
 
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)
53
+ write_to_pipe(iwr, stdin, timeout_checker) if stdin
54
+ if stderr
55
+ err_output = read_from_pipe(erd, timeout_checker)
56
+ write_to_pipe(stderr, err_output, timeout_checker, close_write: false)
57
+ end
58
+ output = read_from_pipe(ord, timeout_checker)
59
+ wait_or_kill(pid, timeout_checker, erd, stderr)
54
60
 
55
61
  output
56
62
  end
57
63
 
58
64
  private
59
65
 
60
- def write_to_pipe(pipe, stdin, timeout_checker)
66
+ def write_to_pipe(pipe, stdin, timeout_checker, close_write: true)
61
67
  offset = 0
62
68
  length = stdin.bytesize
63
69
 
@@ -72,7 +78,7 @@ module Binaryen
72
78
  end
73
79
  end
74
80
 
75
- pipe.close_write
81
+ pipe.close_write if close_write
76
82
  end
77
83
 
78
84
  def read_from_pipe(pipe, timeout_checker)
@@ -95,13 +101,15 @@ module Binaryen
95
101
  output
96
102
  end
97
103
 
98
- def wait_or_kill(pid, timeout_checker)
104
+ def wait_or_kill(pid, timeout_checker, err_read, err_write)
99
105
  loop do
100
106
  remaining_time = timeout_checker.check!
101
107
  raise Timeout::Error, "timed out waiting on process" if remaining_time <= 0
102
108
 
103
109
  if (_, status = Process.wait2(pid, Process::WNOHANG))
104
- raise Binaryen::NonZeroExitStatus, "command exited with status #{status.exitstatus}" if status.exitstatus != 0
110
+
111
+ raise Binaryen::NonZeroExitStatus,
112
+ "command exited with status #{status.exitstatus}" if status.exitstatus != 0
105
113
 
106
114
  return true
107
115
  else
@@ -111,7 +119,7 @@ module Binaryen
111
119
  end
112
120
 
113
121
  def build_command(*arguments)
114
- Shellwords.join([@cmd] + arguments + @default_args)
122
+ [@cmd] + arguments + @default_args
115
123
  end
116
124
 
117
125
  def command_path(cmd, ignore_missing)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Binaryen
4
- VERSION = "1.1.6.2"
4
+ VERSION = "1.1.6.4"
5
5
  BINARYEN_VERSION = "version_116"
6
6
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binaryen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6.2
4
+ version: 1.1.6.4
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-12-11 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2023-12-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: posix-spawn
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.15
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.15
13
27
  description:
14
28
  email:
15
29
  - gems@shopify.com