ruby_wasm 2.5.1-aarch64-linux-musl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.clang-format +8 -0
  3. data/CONTRIBUTING.md +128 -0
  4. data/Gemfile +17 -0
  5. data/LICENSE +21 -0
  6. data/NOTICE +1293 -0
  7. data/README.md +154 -0
  8. data/Rakefile +164 -0
  9. data/Steepfile +24 -0
  10. data/benchmarks/vm_deep_call.rb +55 -0
  11. data/docs/api.md +2 -0
  12. data/docs/cheat_sheet.md +195 -0
  13. data/docs/faq.md +25 -0
  14. data/exe/rbwasm +7 -0
  15. data/ext/.gitignore +2 -0
  16. data/ext/README.md +11 -0
  17. data/ext/extinit.c.erb +32 -0
  18. data/lib/ruby_wasm/3.1/ruby_wasm.so +0 -0
  19. data/lib/ruby_wasm/3.2/ruby_wasm.so +0 -0
  20. data/lib/ruby_wasm/3.3/ruby_wasm.so +0 -0
  21. data/lib/ruby_wasm/build/build_params.rb +3 -0
  22. data/lib/ruby_wasm/build/downloader.rb +18 -0
  23. data/lib/ruby_wasm/build/executor.rb +191 -0
  24. data/lib/ruby_wasm/build/product/baseruby.rb +37 -0
  25. data/lib/ruby_wasm/build/product/crossruby.rb +360 -0
  26. data/lib/ruby_wasm/build/product/libyaml.rb +70 -0
  27. data/lib/ruby_wasm/build/product/openssl.rb +93 -0
  28. data/lib/ruby_wasm/build/product/product.rb +39 -0
  29. data/lib/ruby_wasm/build/product/ruby_source.rb +103 -0
  30. data/lib/ruby_wasm/build/product/wasi_vfs.rb +45 -0
  31. data/lib/ruby_wasm/build/product/zlib.rb +70 -0
  32. data/lib/ruby_wasm/build/product.rb +8 -0
  33. data/lib/ruby_wasm/build/target.rb +24 -0
  34. data/lib/ruby_wasm/build/toolchain/wit_bindgen.rb +31 -0
  35. data/lib/ruby_wasm/build/toolchain.rb +193 -0
  36. data/lib/ruby_wasm/build.rb +92 -0
  37. data/lib/ruby_wasm/cli.rb +347 -0
  38. data/lib/ruby_wasm/packager/component_adapter/wasi_snapshot_preview1.command.wasm +0 -0
  39. data/lib/ruby_wasm/packager/component_adapter/wasi_snapshot_preview1.reactor.wasm +0 -0
  40. data/lib/ruby_wasm/packager/component_adapter.rb +14 -0
  41. data/lib/ruby_wasm/packager/core.rb +333 -0
  42. data/lib/ruby_wasm/packager/file_system.rb +160 -0
  43. data/lib/ruby_wasm/packager.rb +96 -0
  44. data/lib/ruby_wasm/rake_task.rb +60 -0
  45. data/lib/ruby_wasm/util.rb +15 -0
  46. data/lib/ruby_wasm/version.rb +3 -0
  47. data/lib/ruby_wasm.rb +34 -0
  48. data/package-lock.json +9777 -0
  49. data/package.json +12 -0
  50. data/rakelib/check.rake +37 -0
  51. data/rakelib/ci.rake +152 -0
  52. data/rakelib/doc.rake +29 -0
  53. data/rakelib/format.rake +35 -0
  54. data/rakelib/gem.rake +22 -0
  55. data/rakelib/packaging.rake +165 -0
  56. data/rakelib/version.rake +40 -0
  57. data/sig/open_uri.rbs +4 -0
  58. data/sig/ruby_wasm/build.rbs +327 -0
  59. data/sig/ruby_wasm/cli.rbs +51 -0
  60. data/sig/ruby_wasm/ext.rbs +26 -0
  61. data/sig/ruby_wasm/packager.rbs +122 -0
  62. data/sig/ruby_wasm/util.rbs +5 -0
  63. data/tools/clang-format-diff.sh +18 -0
  64. data/tools/exe/rbminify +12 -0
  65. data/tools/lib/syntax_tree/minify_ruby.rb +63 -0
  66. metadata +114 -0
@@ -0,0 +1,327 @@
1
+ module RubyWasm
2
+ VERSION: String
3
+
4
+ interface _Cacheable
5
+ def cache_key: (Digest::SHA256 digest) -> void
6
+ end
7
+
8
+ class Target
9
+ include _Cacheable
10
+
11
+ @triple: String
12
+ @pic: bool
13
+
14
+ attr_reader triple: String
15
+
16
+ def initialize: (String triple, ?pic: bool) -> void
17
+ def pic?: -> bool
18
+ end
19
+
20
+ class Build
21
+ include _Cacheable
22
+
23
+ @target: Target
24
+ @build_dir: String
25
+ @rubies_dir: String
26
+ @toolchain: Toolchain
27
+ @libyaml: LibYAMLProduct
28
+ @zlib: ZlibProduct
29
+ @openssl: OpenSSLProduct
30
+ @wasi_vfs: WasiVfsProduct?
31
+ @baseruby: BaseRubyProduct
32
+ @crossruby: CrossRubyProduct
33
+ @source: BuildSource
34
+
35
+ attr_reader toolchain: Toolchain
36
+
37
+ def initialize: (
38
+ string name,
39
+ target: Target,
40
+ src: Packager::build_source,
41
+ toolchain: Toolchain?,
42
+ build_dir: string,
43
+ rubies_dir: string,
44
+ ?wasi_vfs: :default | WasiVfsProduct?,
45
+ **untyped
46
+ ) -> void
47
+ def crossruby: () -> CrossRubyProduct
48
+ end
49
+
50
+ class BuildParams
51
+ attr_accessor name: String
52
+ attr_accessor target: Target
53
+ attr_accessor default_exts: String
54
+
55
+ def initialize: (name: string, target: Target, default_exts: string) -> void
56
+ end
57
+
58
+ class BuildProduct
59
+ def name: -> String
60
+ end
61
+
62
+ class AutoconfProduct < BuildProduct
63
+ @target: Target
64
+ @toolchain: Toolchain
65
+
66
+ def initialize: (Target target, Toolchain toolchain) -> void
67
+ def system_triplet_args: -> Array[String]
68
+ | -> Array[String]
69
+ def tools_args: -> Array[String]
70
+ | -> Array[String]
71
+ def configure_args: -> Array[String]
72
+ | -> Array[String]
73
+ end
74
+
75
+ class BuildSource < BuildProduct
76
+ @params: Hash[untyped, untyped]
77
+ @build_dir: String
78
+
79
+ def initialize: (untyped params, String build_dir) -> void
80
+ def name: -> String
81
+ def cache_key: (Digest::SHA256 digest) -> void
82
+ def src_dir: -> String
83
+ def configure_file: -> String
84
+ def fetch: (BuildExecutor executor) -> void
85
+ def build: (BuildExecutor executor) -> void
86
+ end
87
+
88
+ class BaseRubyProduct < BuildProduct
89
+ @build_dir: String
90
+ @source: BuildSource
91
+ @channel: String
92
+
93
+ def initialize: (String build_dir, BuildSource source) -> void
94
+ def product_build_dir: -> String
95
+ def install_dir: -> String
96
+ def name: -> String
97
+ def build: (BuildExecutor executor) -> void
98
+ end
99
+
100
+ class ZlibProduct < AutoconfProduct
101
+ ZLIB_VERSION: String
102
+ @build_dir: String
103
+
104
+ attr_reader target: Target
105
+ def initialize: (String build_dir, Target target, Toolchain toolchain) -> void
106
+ def product_build_dir: -> String
107
+ def destdir: -> String
108
+ def install_root: -> String
109
+ def name: -> String
110
+ def configure_args: -> Array[String]
111
+ def build: (BuildExecutor executor) -> void
112
+ end
113
+
114
+ class LibYAMLProduct < AutoconfProduct
115
+ LIBYAML_VERSION: String
116
+ @build_dir: String
117
+
118
+ attr_reader target: Target
119
+ def initialize: (String build_dir, Target target, Toolchain toolchain) -> void
120
+ def product_build_dir: -> String
121
+ def destdir: -> String
122
+ def install_root: -> String
123
+ def name: -> String
124
+ def build: (BuildExecutor executor) -> void
125
+ end
126
+
127
+ class OpenSSLProduct < AutoconfProduct
128
+ OPENSSL_VERSION: String
129
+ @build_dir: String
130
+
131
+ attr_reader target: Target
132
+ def initialize: (String build_dir, Target target, Toolchain toolchain) -> void
133
+ def product_build_dir: -> String
134
+ def destdir: -> String
135
+ def install_root: -> String
136
+ def name: -> String
137
+ def configure_args: -> Array[String]
138
+ def build: (BuildExecutor executor) -> void
139
+ end
140
+
141
+ class WasiVfsProduct < BuildProduct
142
+ WASI_VFS_VERSION: String
143
+ @build_dir: String
144
+ @need_fetch_lib: bool
145
+ @cli_path: String
146
+ @need_fetch_cli: bool
147
+
148
+ def initialize: (String build_dir) -> void
149
+ def lib_product_build_dir: -> String
150
+ def lib_wasi_vfs_a: -> String
151
+ def name: -> String
152
+ def build: (BuildExecutor executor) -> void
153
+ end
154
+
155
+ class CrossRubyExtProduct < BuildProduct
156
+ include RubyWasm::_Cacheable
157
+
158
+ @toolchain: Toolchain
159
+ @srcdir: String
160
+ @ext_relative_path: String
161
+
162
+ attr_reader name: String
163
+ def initialize: (String srcdir, Toolchain toolchain, ?ext_relative_path: String?) -> void
164
+ def product_build_dir: (CrossRubyProduct crossruby) -> String
165
+ def linklist: (CrossRubyProduct crossruby) -> String
166
+ def metadata_json: (CrossRubyProduct crossruby) -> String
167
+ def feature_name: (CrossRubyProduct crossruby) -> String
168
+
169
+ def make_args: (CrossRubyProduct crossruby) -> Array[String]
170
+ def build: (BuildExecutor executor, CrossRubyProduct crossruby) -> void
171
+ def do_extconf: (BuildExecutor executor, CrossRubyProduct crossruby) -> void
172
+ def do_install_rb: (BuildExecutor executor, CrossRubyProduct crossruby) -> void
173
+
174
+ private def do_legacy_extconf: (BuildExecutor executor, CrossRubyProduct crossruby) -> void
175
+ end
176
+
177
+ class CrossRubyProduct < AutoconfProduct
178
+ include RubyWasm::_Cacheable
179
+
180
+ @params: BuildParams
181
+ @rubies_dir: String
182
+ @build_dir: String
183
+ @baseruby: BaseRubyProduct
184
+ @libyaml: LibYAMLProduct
185
+ @zlib: ZlibProduct
186
+ @openssl: OpenSSLProduct
187
+ @wasi_vfs: WasiVfsProduct
188
+
189
+ attr_reader target: Target
190
+ attr_reader source: BuildSource
191
+ attr_reader toolchain: Toolchain
192
+ attr_accessor user_exts: Array[CrossRubyExtProduct]
193
+ attr_accessor wasmoptflags: Array[String]
194
+ attr_accessor cppflags: Array[String]
195
+ attr_accessor cflags: Array[String]
196
+ attr_accessor ldflags: Array[String]
197
+ attr_accessor debugflags: Array[String]
198
+ attr_accessor xcflags: Array[String]
199
+ attr_accessor xldflags: Array[String]
200
+ def initialize: (BuildParams params, String build_dir, String rubies_dir, BaseRubyProduct baseruby, BuildSource source, Toolchain toolchain) -> void
201
+ def configure: (BuildExecutor executor, ?reconfigure: bool) -> void
202
+ def need_exts_build?: -> bool
203
+ def need_extinit_obj?: -> bool
204
+ def build_exts: (BuildExecutor executor) -> void
205
+ def build: (BuildExecutor executor, ?remake: bool, ?reconfigure: bool) -> void
206
+ def clean: (BuildExecutor executor) -> void
207
+ def name: -> String
208
+ def build_dir: -> String
209
+ def ext_build_dir: -> String
210
+ def with_libyaml: (LibYAMLProduct libyaml) -> LibYAMLProduct
211
+ def with_zlib: (ZlibProduct zlib) -> ZlibProduct
212
+ def with_wasi_vfs: (WasiVfsProduct? wasi_vfs) -> WasiVfsProduct?
213
+ def with_openssl: (OpenSSLProduct openssl) -> OpenSSLProduct
214
+ def dest_dir: -> String
215
+ def artifact: -> String
216
+ def extinit_obj: -> String
217
+ def extinit_c_erb: -> String
218
+ def baseruby_path: -> String
219
+ def configure_args: (String build_triple, Toolchain toolchain) -> Array[String]
220
+ end
221
+
222
+ class WitBindgen
223
+ @build_dir: String
224
+ @tool_dir: String
225
+ @revision: String
226
+
227
+ attr_reader bin_path: String
228
+ def initialize: (build_dir: String, ?revision: String) -> void
229
+ def install: -> void
230
+ end
231
+
232
+ class Toolchain
233
+ @tools: Hash[untyped, untyped]
234
+ @tools_cache: Hash[untyped, untyped]
235
+
236
+ attr_reader name: String
237
+ def initialize: -> void
238
+ def find_tool: (Symbol name) -> String
239
+ def check_envvar: (untyped name) -> void
240
+ def self.get: (Target target, ?String? build_dir) -> (Toolchain)
241
+ def self.find_path: (String command) -> String?
242
+ def self.check_executable: (String command) -> String
243
+ def cc: -> String
244
+ def ranlib: -> String
245
+ def ld: -> String
246
+ def ar: -> String
247
+
248
+ def install: -> void
249
+ end
250
+
251
+ class WASISDK < Toolchain
252
+ @wasm_opt_path: String
253
+ @need_fetch_wasi_sdk: bool
254
+ @need_fetch_binaryen: bool
255
+ @tools: Hash[Symbol, String]
256
+ @wasi_sdk_path: String
257
+ @binaryen_version: Integer
258
+ @version_major: Integer
259
+ @version_minor: Integer
260
+ @binaryen_path: String
261
+
262
+ def initialize: (?String? wasi_sdk_path, ?build_dir: String?, ?version_major: Integer, ?version_minor: Integer, ?binaryen_version: Integer) -> void
263
+ def find_tool: (Symbol name) -> String
264
+ def wasm_opt: -> String
265
+ def wasi_sdk_path: -> String
266
+ def download_url: (Integer? version_major, Integer? version_minor) -> String
267
+ def binaryen_download_url: (Integer? version) -> String
268
+ def install_wasi_sdk: -> void
269
+ def install_binaryen: -> void
270
+ end
271
+
272
+ class Emscripten < Toolchain
273
+ @tools: Hash[Symbol, String]
274
+
275
+ def initialize: -> void
276
+ def find_tool: (Symbol name) -> String
277
+ end
278
+
279
+ class BuildExecutor
280
+ @verbose: bool
281
+ @github_actions_markup: bool
282
+ @process_count: Integer
283
+ @start_times: Hash[[Class, String], Time]
284
+
285
+ attr_reader process_count: Integer
286
+
287
+ def initialize: (?verbose: bool) -> void
288
+ def system: (*_ToS args, ?chdir: String?, ?env: Hash[String, String]?) -> void
289
+ def rm_rf: (FileUtils::pathlist list) -> void
290
+ def rm_f: (FileUtils::pathlist list) -> void
291
+ def cp_r: (FileUtils::pathlist src, path dest) -> void
292
+ def mv: (FileUtils::pathlist src, path dest) -> void
293
+ def mkdir_p: (FileUtils::pathlist list) -> void
294
+ def ln_s: (String src, String dest) -> void
295
+ def write: (String path, _ToS data) -> void
296
+
297
+ def begin_section: (Class klass, String name, String note) -> void
298
+ def end_section: (Class klass, String name) -> void
299
+
300
+ private def _print_command: (Array[_ToS] command, Hash[String, String]? env) -> void
301
+ end
302
+
303
+ class StatusPrinter
304
+ @mutex: Mutex
305
+ @counter: Integer
306
+ @indicators: String
307
+
308
+ def initialize: () -> void
309
+ def stdout: (String message) -> void
310
+ def stderr: (String message) -> void
311
+ def done: () -> void
312
+ end
313
+
314
+ class Downloader
315
+ def format_size: (Integer size) -> String
316
+
317
+ def download: (String url, String dest, String message) -> void
318
+ end
319
+
320
+ class BuildTask
321
+ @build: Build
322
+ attr_accessor name: String
323
+
324
+ def initialize: (String name, target: String, src: untyped, ?toolchain: Toolchain?, ?build_dir: String?, ?rubies_dir: String?, **untyped) -> void
325
+ def hexdigest: -> String
326
+ end
327
+ end
@@ -0,0 +1,51 @@
1
+ module RubyWasm
2
+ class CLI
3
+ type cli_options = {
4
+ print_ruby_cache_key: bool,
5
+ save_temps: bool,
6
+ output: String,
7
+
8
+ optimize: bool,
9
+ remake: bool,
10
+ reconfigure: bool,
11
+ clean: bool,
12
+
13
+ ruby_version: String,
14
+ target_triplet: String,
15
+ profile: String,
16
+ stdlib: bool,
17
+ disable_gems: bool,
18
+ gemfile: String?,
19
+ patches: Array[String],
20
+ format: String,
21
+ }
22
+
23
+ DEFAULT_RUBIES_DIR: string
24
+
25
+ @stdout: IO
26
+ @stderr: IO
27
+
28
+ def initialize: (stdout: IO, stderr: IO) -> void
29
+
30
+ def build: (Array[String] args) -> void
31
+ def pack: (Array[String] args) -> void
32
+
33
+ private
34
+
35
+ def build_config: (cli_options options) -> Packager::build_config
36
+ def compute_build_source: (cli_options options) -> Packager::build_source
37
+ def self.build_source_aliases: (string root) -> Hash[string, Packager::build_source]
38
+ def self.bundled_patches_path: () -> string
39
+ def root: () -> string
40
+
41
+ def derive_packager: (cli_options options) -> Packager
42
+ def do_print_ruby_cache_key: (Packager) -> void
43
+ def do_build: (BuildExecutor, string tmpdir, Packager, cli_options options) -> void
44
+
45
+ def require_extension: () -> void
46
+ end
47
+
48
+ self.@logger: Logger?
49
+ def self.logger: () -> Logger
50
+ attr_accessor self.log_level: Symbol
51
+ end
@@ -0,0 +1,26 @@
1
+ module RubyWasmExt
2
+ type bytes = String
3
+
4
+ def self.preinitialize: (bytes module_bytes) -> bytes
5
+
6
+ class WasiVfs
7
+ def initialize: () -> void
8
+
9
+ def self.run_cli: (Array[String] args) -> void
10
+
11
+ def map_dir: (String guest_path, String host_path) -> void
12
+
13
+ def pack: (bytes module_bytes) -> bytes
14
+ end
15
+
16
+ class ComponentLink
17
+ def initialize: () -> void
18
+ def library: (String name, bytes module, bool dl_openable) -> void
19
+ def adapter: (String name, bytes module) -> void
20
+ def validate: (bool) -> void
21
+ def stack_size: (Integer) -> void
22
+ def stub_missing_functions: (bool) -> void
23
+ def use_built_in_libdl: (bool) -> void
24
+ def encode: () -> bytes
25
+ end
26
+ end
@@ -0,0 +1,122 @@
1
+
2
+ class RubyWasm::Packager
3
+ type build_source_github = {
4
+ type: "github",
5
+ repo: String,
6
+ rev: String,
7
+ }
8
+ type build_source_tarball = {
9
+ type: "tarball",
10
+ url: String,
11
+ }
12
+ type build_source_local = {
13
+ type: "local",
14
+ path: String,
15
+ }
16
+ type build_source = (build_source_github | build_source_tarball | build_source_local) & {
17
+ name: string,
18
+ patches: Array[String],
19
+ }
20
+
21
+ type build_config = Hash[untyped, untyped]
22
+
23
+ type bytes = String
24
+
25
+ @definition: untyped
26
+ @config: build_config
27
+
28
+ def initialize: (string root, build_config?, untyped? definition) -> void
29
+
30
+ def package: (RubyWasm::BuildExecutor, string dest_dir, untyped options) -> bytes
31
+
32
+ @ruby_core_build: RubyWasm::Packager::Core?
33
+ def ruby_core_build: () -> RubyWasm::Packager::Core
34
+
35
+ EXCLUDED_GEMS: Array[string]
36
+
37
+ def specs: () -> Array[untyped]
38
+ def support_dynamic_linking?: () -> bool
39
+
40
+ def root: () -> string
41
+
42
+ ALL_DEFAULT_EXTS: string
43
+
44
+ def build_options: () -> Hash[Symbol, untyped]
45
+ def full_build_options: () -> Hash[Symbol, untyped]
46
+
47
+ class Core
48
+ include RubyWasm::_Cacheable
49
+
50
+ @packager: RubyWasm::Packager
51
+ def initialize: (RubyWasm::Packager) -> void
52
+ def build: (RubyWasm::BuildExecutor, untyped options) -> String
53
+ def build_and_link_exts: (RubyWasm::BuildExecutor) -> bytes
54
+
55
+ extend Forwardable
56
+
57
+ def artifact: () -> string
58
+
59
+ private
60
+
61
+ @build_strategy: BuildStrategy?
62
+ def build_strategy: () -> BuildStrategy
63
+
64
+ class BuildStrategy
65
+ @packager: RubyWasm::Packager
66
+ def initialize: (RubyWasm::Packager) -> void
67
+ def build: (RubyWasm::BuildExecutor, untyped options) -> String
68
+ def specs_with_extensions: () -> Array[[untyped, Array[string]]]
69
+ def build_and_link_exts: (RubyWasm::BuildExecutor) -> bytes
70
+ end
71
+
72
+ class DynamicLinking < RubyWasm::Packager::Core::BuildStrategy
73
+ @build: RubyWasm::Build
74
+ def derive_build: () -> RubyWasm::Build
75
+ def build_exts: (RubyWasm::BuildExecutor, RubyWasm::Build) -> void
76
+ def name: () -> string
77
+
78
+ private def link_exts: (RubyWasm::BuildExecutor, RubyWasm::Build) -> bytes
79
+ end
80
+
81
+ class StaticLinking < RubyWasm::Packager::Core::BuildStrategy
82
+ @build: RubyWasm::Build
83
+ def derive_build: () -> RubyWasm::Build
84
+ @user_exts: Array[RubyWasm::CrossRubyExtProduct]?
85
+ def user_exts: (RubyWasm::Build) -> Array[RubyWasm::CrossRubyExtProduct]
86
+
87
+ def name: () -> string
88
+ end
89
+ end
90
+
91
+ class FileSystem
92
+ @dest_dir: string
93
+ @packager: RubyWasm::Packager
94
+ @ruby_root: string
95
+
96
+ def initialize: (string dest_dir, RubyWasm::Packager) -> void
97
+ def package_ruby_root: (String tarball, RubyWasm::BuildExecutor) -> void
98
+ def remove_stdlib: (RubyWasm::BuildExecutor) -> void
99
+ def package_gems: () -> void
100
+
101
+ def setup_rb_content: () -> String
102
+
103
+ def remove_non_runtime_files: (RubyWasm::BuildExecutor) -> void
104
+
105
+ def bundle_dir: () -> String
106
+ def ruby_root: () -> string
107
+
108
+ private
109
+
110
+ def each_gem_content_path: () { (String, String) -> void } -> void
111
+ def each_gem_require_path: () { (String, String) -> void } -> void
112
+ def each_gem_extension_path: () { (String, String) -> void } -> void
113
+
114
+ def bundle_relative_path: () -> String
115
+ def ruby_version: () -> String
116
+ def rubyarchdir: () -> String
117
+ end
118
+
119
+ module ComponentAdapter
120
+ def self.wasi_snapshot_preview1: (String exec_model) -> String
121
+ end
122
+ end
@@ -0,0 +1,5 @@
1
+ module RubyWasm
2
+ module SizeFormatter
3
+ def self?.format: (Integer size) -> String
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ #!/bin/bash
2
+
3
+ set -eo pipefail
4
+
5
+ if [ -n "$1" ]; then
6
+ BASE_BRANCH="$1"
7
+ elif [ -n "$GITHUB_EVENT_BEFORE" ] && [ "push" = "$GITHUB_EVENT_NAME" ]; then
8
+ BASE_BRANCH="$GITHUB_EVENT_BEFORE"
9
+ elif [ -n "$GITHUB_BASE_REF" ]; then
10
+ BASE_BRANCH="origin/$GITHUB_BASE_REF"
11
+ else
12
+ BASE_BRANCH="@{upstream}"
13
+ fi
14
+
15
+ MERGE_BASE=$(git merge-base $BASE_BRANCH HEAD)
16
+
17
+ git diff -U0 --no-color $MERGE_BASE -- '*.c' '*.h' | clang-format-diff -i -p1
18
+ exit $?
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "../lib")
4
+
5
+ require "syntax_tree"
6
+ require "syntax_tree/cli"
7
+ require "syntax_tree/minify_ruby"
8
+
9
+ # Override the default formatter with our own.
10
+ SyntaxTree.register_handler(".rb", SyntaxTree::MinifyRuby)
11
+
12
+ exit(SyntaxTree::CLI.run(ARGV))
@@ -0,0 +1,63 @@
1
+ require "syntax_tree"
2
+
3
+ module SyntaxTree
4
+ module MinifyRuby
5
+
6
+ # This is a required API for syntax tree which just delegates to SyntaxTree.parse.
7
+ def self.parse(source)
8
+ ::SyntaxTree.parse(source)
9
+ end
10
+
11
+ # This is the main entrypoint for the formatter. It parses the source,
12
+ # builds a formatter, then prints the result.
13
+ def self.format(source, _maxwidth = nil)
14
+ formatter = Formatter.new(source)
15
+ program = parse(source)
16
+ CommentStrippingVisitor.new.visit(program)
17
+ program.format(formatter)
18
+
19
+ formatter.flush
20
+ formatter.output.join
21
+ end
22
+
23
+ # This is a required API for syntax tree which just delegates to SyntaxTree.read.
24
+ def self.read(filepath)
25
+ ::SyntaxTree.read(filepath)
26
+ end
27
+
28
+ class CommentStrippingVisitor < SyntaxTree::Visitor
29
+ def visit(node)
30
+ if node and node.comments.any?
31
+ node.comments.clear
32
+ end
33
+ super(node)
34
+ end
35
+
36
+ def visit_statements(node)
37
+ node.body.delete_if { _1.is_a?(SyntaxTree::Comment) }
38
+ super(node)
39
+ end
40
+ end
41
+
42
+ class Formatter < SyntaxTree::Formatter
43
+ def initialize(source)
44
+ super(source, [], Float::INFINITY) do |n|
45
+ # This block, called `genspace`, is used to generate indentation for `n` depth.
46
+ ""
47
+ end
48
+ end
49
+
50
+ def breakable(
51
+ separator = " ",
52
+ _width = separator.length,
53
+ indent: nil,
54
+ force: nil
55
+ )
56
+ # Don't break when already broken
57
+ return if target.last.is_a?(PrettierPrint::BreakParent)
58
+ return if not force and separator == ""
59
+ super(separator, _width, indent: indent, force: force)
60
+ end
61
+ end
62
+ end
63
+ end