binaryen 1.1.6.pre.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +58 -0
  3. data/extconf.rb +75 -0
  4. data/lib/binaryen/command.rb +57 -0
  5. data/lib/binaryen/error.rb +6 -0
  6. data/lib/binaryen/version.rb +6 -0
  7. data/lib/binaryen.rb +38 -0
  8. data/vendor/arm64-darwin/bin/wasm-as +0 -0
  9. data/vendor/arm64-darwin/bin/wasm-ctor-eval +0 -0
  10. data/vendor/arm64-darwin/bin/wasm-dis +0 -0
  11. data/vendor/arm64-darwin/bin/wasm-emscripten-finalize +0 -0
  12. data/vendor/arm64-darwin/bin/wasm-fuzz-lattices +0 -0
  13. data/vendor/arm64-darwin/bin/wasm-fuzz-types +0 -0
  14. data/vendor/arm64-darwin/bin/wasm-merge +0 -0
  15. data/vendor/arm64-darwin/bin/wasm-metadce +0 -0
  16. data/vendor/arm64-darwin/bin/wasm-opt +0 -0
  17. data/vendor/arm64-darwin/bin/wasm-reduce +0 -0
  18. data/vendor/arm64-darwin/bin/wasm-shell +0 -0
  19. data/vendor/arm64-darwin/bin/wasm-split +0 -0
  20. data/vendor/arm64-darwin/bin/wasm2js +0 -0
  21. data/vendor/arm64-darwin/include/binaryen-c.h +3615 -0
  22. data/vendor/arm64-darwin/include/wasm-delegations.def +105 -0
  23. data/vendor/arm64-darwin/lib/libbinaryen.dylib +0 -0
  24. data/vendor/x86_64-darwin/bin/wasm-as +0 -0
  25. data/vendor/x86_64-darwin/bin/wasm-ctor-eval +0 -0
  26. data/vendor/x86_64-darwin/bin/wasm-dis +0 -0
  27. data/vendor/x86_64-darwin/bin/wasm-emscripten-finalize +0 -0
  28. data/vendor/x86_64-darwin/bin/wasm-fuzz-lattices +0 -0
  29. data/vendor/x86_64-darwin/bin/wasm-fuzz-types +0 -0
  30. data/vendor/x86_64-darwin/bin/wasm-merge +0 -0
  31. data/vendor/x86_64-darwin/bin/wasm-metadce +0 -0
  32. data/vendor/x86_64-darwin/bin/wasm-opt +0 -0
  33. data/vendor/x86_64-darwin/bin/wasm-reduce +0 -0
  34. data/vendor/x86_64-darwin/bin/wasm-shell +0 -0
  35. data/vendor/x86_64-darwin/bin/wasm-split +0 -0
  36. data/vendor/x86_64-darwin/bin/wasm2js +0 -0
  37. data/vendor/x86_64-darwin/include/binaryen-c.h +3615 -0
  38. data/vendor/x86_64-darwin/include/wasm-delegations.def +105 -0
  39. data/vendor/x86_64-darwin/lib/libbinaryen.dylib +0 -0
  40. data/vendor/x86_64-linux/bin/wasm-as +0 -0
  41. data/vendor/x86_64-linux/bin/wasm-ctor-eval +0 -0
  42. data/vendor/x86_64-linux/bin/wasm-dis +0 -0
  43. data/vendor/x86_64-linux/bin/wasm-emscripten-finalize +0 -0
  44. data/vendor/x86_64-linux/bin/wasm-fuzz-lattices +0 -0
  45. data/vendor/x86_64-linux/bin/wasm-fuzz-types +0 -0
  46. data/vendor/x86_64-linux/bin/wasm-merge +0 -0
  47. data/vendor/x86_64-linux/bin/wasm-metadce +0 -0
  48. data/vendor/x86_64-linux/bin/wasm-opt +0 -0
  49. data/vendor/x86_64-linux/bin/wasm-reduce +0 -0
  50. data/vendor/x86_64-linux/bin/wasm-shell +0 -0
  51. data/vendor/x86_64-linux/bin/wasm-split +0 -0
  52. data/vendor/x86_64-linux/bin/wasm2js +0 -0
  53. data/vendor/x86_64-linux/include/binaryen-c.h +3615 -0
  54. data/vendor/x86_64-linux/include/wasm-delegations.def +105 -0
  55. data/vendor/x86_64-linux/lib/libbinaryen.a +0 -0
  56. metadata +99 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 773664dfc73f0168da19636afb23f35106e2b0426f7f6ff22c15e790e4fba882
4
+ data.tar.gz: af7edac7322317bd39100d7e65d0cfc43f48a8aa9f63ac3ca2c5564dff775a62
5
+ SHA512:
6
+ metadata.gz: 2af49d37b27f4dafd1abb76139b103bacd95cae2434c2913ed0f45d04b121c5a3cdf2fe110b3662cfc14b574416dade62e433c6ec0a49d981cd1075c0e4417d7
7
+ data.tar.gz: 39195bc078126fabdab98f97eb3a8d6cbb9ce1b06211af6c96078ec888dddadefe00de8344ed6dc282855cffffa11f7343a35ec15f3218e2eddab879a400ef61
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # `binaryen-rb`
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) |
12
+
13
+ ## Installation
14
+
15
+ Add the following to your Gemfile:
16
+
17
+ ```ruby
18
+ gem "binaryen"
19
+ ```
20
+
21
+ Then run `bundle install`.
22
+
23
+ ## Usage
24
+
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`.
27
+
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
+ ```
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at
39
+ https://github.com/Shopify/binaryen-rb. Signing Shopify's CLA is a mandatory
40
+ when opening, you will be prompted to do so by a Github action.
41
+
42
+ Read and follow the guidelines in [CONTRIBUTING.md](https://github.com/Shopify/binaryen-rb/blob/main/CONTRIBUTING.md).
43
+
44
+ ## Releases
45
+
46
+ This gem is published to [Rubygems](https://rubygems.org/gems/binaryen).
47
+
48
+ The procedure to publish a new release version is as follows:
49
+
50
+ * Update `lib/binaryen/version.rb` to a valid [`binaryen` release version][binaryen]
51
+ * Run bundle install to bump the version of the gem in `Gemfile.lock`
52
+ * Open a pull request, review, and merge
53
+ * 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)
56
+
57
+
58
+ [binaryen]: https://github.com/WebAssembly/binaryen/releases
data/extconf.rb ADDED
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "fileutils"
5
+
6
+ def log(msg)
7
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
8
+ $stderr.write("[#{timestamp}] [binaryen-rb] " + msg + "\n")
9
+ end
10
+
11
+ def to_mib(bytes)
12
+ (bytes.to_f / 1024.to_f / 1024.to_f).round(2)
13
+ end
14
+
15
+ total_saved = 0
16
+
17
+ if enable_config("prune", true)
18
+ begin
19
+ log("[info] removing unnecessary vendor directories")
20
+
21
+ cpu = RbConfig::CONFIG["host_cpu"]
22
+ os = RbConfig::CONFIG["host_os"]
23
+ if os.include?("darwin")
24
+ os = "darwin"
25
+ end
26
+ ruby_platform = "#{cpu}-#{os}"
27
+
28
+ Dir["#{__dir__}/vendor/*"].each do |dir|
29
+ next if dir.end_with?(ruby_platform)
30
+
31
+ space_saved = Dir["#{dir}/**/*"].sum { |f| File.file?(f) ? File.size(f) : 0 }
32
+ total_saved += space_saved
33
+ log("[info] removing #{dir} (#{to_mib(space_saved)} MiB saved)")
34
+ FileUtils.rm_rf(dir)
35
+ end
36
+ rescue => e
37
+ log("[warn] failed to remove unnecessary vendor directories: #{e}")
38
+ end
39
+ end
40
+
41
+ unless File.exist?("#{__dir__}/vendor/#{ruby_platform}")
42
+ log("[fatal] no vendor directory found for #{ruby_platform}, cannot use binaryen-rb on this platform yet")
43
+ exit 1
44
+ end
45
+
46
+ if enable_config("strip", true)
47
+ begin
48
+ strip_command = RbConfig::MAKEFILE_CONFIG["STRIP"]
49
+
50
+ if strip_command.nil?
51
+ log("[warn] no strip command found, skipping")
52
+ else
53
+ Dir["#{__dir__}/vendor/#{ruby_platform}/{lib,bin}/*"].each do |lib|
54
+ start_size = File.size(lib)
55
+ if system("#{strip_command} #{lib}")
56
+ end_size = File.size(lib)
57
+ size_diff = (start_size - end_size)
58
+ total_saved += size_diff
59
+ log("[info] stripped #{lib.sub(__dir__, ".")} (#{size_diff} bytes saved)")
60
+ else
61
+ log("[warn] failed to strip #{lib}")
62
+ end
63
+ end
64
+ end
65
+ rescue => e
66
+ log("[warn] failed to strip binaries: #{e}")
67
+ end
68
+ end
69
+
70
+ File.write("Makefile", <<~MAKEFILE)
71
+ install:
72
+ \t@echo "binaryen-rb does not need to be installed"
73
+ MAKEFILE
74
+
75
+ log("[info] done (#{to_mib(total_saved)} MiB saved)")
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "English"
4
+ require "shellwords"
5
+ require "timeout"
6
+
7
+ module Binaryen
8
+ # Wrapper around a binaryen executable command with a timeout and streaming IO.
9
+ #
10
+ # @example Running wasm-opt
11
+ #
12
+ # ```ruby
13
+ # command = Binaryen::Command.new("wasm-opt", timeout: 10)
14
+ # optimized_wasm = command.run("-O4", stdin: "(module)").read
15
+ # ```
16
+ class Command
17
+ DEFAULT_ARGS_FOR_COMMAND = {
18
+ "wasm-opt" => ["--output=-"],
19
+ }.freeze
20
+
21
+ def initialize(cmd, timeout: 10, ignore_missing: false)
22
+ @cmd = command_path(cmd, ignore_missing) || raise(ArgumentError, "command not found: #{cmd}")
23
+ @timeout = timeout
24
+ @default_args = DEFAULT_ARGS_FOR_COMMAND.fetch(cmd, [])
25
+ end
26
+
27
+ def run(*arguments, stdin: nil, stderr: File::NULL)
28
+ pid = nil
29
+ 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
42
+
43
+ output
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def build_command(*arguments)
50
+ Shellwords.join([@cmd] + arguments + @default_args)
51
+ end
52
+
53
+ def command_path(cmd, ignore_missing)
54
+ Dir[File.join(Binaryen.bindir, cmd)].first || (ignore_missing && cmd)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Binaryen
4
+ class Error < StandardError; end
5
+ class NonZeroExitStatus < Error; end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Binaryen
4
+ VERSION = "1.1.6.pre.3"
5
+ BINARYEN_VERSION = "version_116"
6
+ end
data/lib/binaryen.rb ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "binaryen/version"
4
+ require "binaryen/error"
5
+ require "binaryen/command"
6
+
7
+ module Binaryen
8
+ class Error < StandardError; end
9
+
10
+ class << self
11
+ # Path to the vendored binaryen files
12
+ def vendordir
13
+ @vendordir ||= begin
14
+ cpu = RbConfig::CONFIG["host_cpu"]
15
+ os = RbConfig::CONFIG["host_os"]
16
+ if os.include?("darwin")
17
+ os = "darwin"
18
+ end
19
+ File.expand_path(File.join(File.dirname(__FILE__), "..", "vendor", "#{cpu}-#{os}"))
20
+ end
21
+ end
22
+
23
+ # Path to the vendored binaryen binary executables
24
+ def bindir
25
+ @bindir ||= File.join(vendordir, "bin")
26
+ end
27
+
28
+ # Path to the vendored binaryen libraries
29
+ def libdir
30
+ @libdir ||= File.join(vendordir, "lib")
31
+ end
32
+
33
+ # Path to the vendored binaryen headers and definitions
34
+ def includedir
35
+ @includedir ||= File.join(vendordir, "include")
36
+ end
37
+ end
38
+ end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file