rbs 4.1.0.pre.1 → 4.1.0
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 +4 -4
- data/.dockerignore +37 -0
- data/.github/workflows/bundle-update.yml +1 -1
- data/.github/workflows/c-check.yml +14 -6
- data/.github/workflows/comments.yml +2 -2
- data/.github/workflows/dependabot.yml +2 -2
- data/.github/workflows/jruby.yml +79 -0
- data/.github/workflows/milestone.yml +13 -2
- data/.github/workflows/ruby.yml +16 -4
- data/.github/workflows/rust.yml +13 -8
- data/.github/workflows/truffleruby.yml +54 -0
- data/.github/workflows/typecheck.yml +5 -2
- data/.github/workflows/wasm.yml +55 -0
- data/.github/workflows/windows.yml +8 -2
- data/.gitignore +8 -0
- data/CHANGELOG.md +88 -0
- data/Dockerfile.jruby +53 -0
- data/README.md +3 -3
- data/Rakefile +103 -1
- data/Steepfile +9 -0
- data/core/array.rbs +243 -180
- data/core/builtin.rbs +6 -6
- data/core/enumerable.rbs +109 -109
- data/core/enumerator/product.rbs +5 -5
- data/core/enumerator.rbs +28 -28
- data/core/file.rbs +24 -1018
- data/core/file_constants.rbs +463 -0
- data/core/file_stat.rbs +534 -0
- data/core/float.rbs +0 -24
- data/core/hash.rbs +117 -101
- data/core/integer.rbs +21 -58
- data/core/io.rbs +25 -7
- data/core/match_data.rbs +1 -1
- data/core/module.rbs +88 -74
- data/core/numeric.rbs +3 -0
- data/core/object_space/weak_key_map.rbs +7 -7
- data/core/pathname.rbs +0 -10
- data/core/ractor.rbs +0 -10
- data/core/range.rbs +23 -23
- data/core/rbs/ops.rbs +154 -0
- data/core/rbs/unnamed/argf.rbs +3 -3
- data/core/rubygems/errors.rbs +4 -1
- data/core/rubygems/requirement.rbs +0 -10
- data/core/rubygems/rubygems.rbs +4 -1
- data/core/rubygems/specification.rbs +8 -0
- data/core/rubygems/version.rbs +0 -160
- data/core/set.rbs +3 -3
- data/core/struct.rbs +16 -16
- data/core/thread.rbs +9 -14
- data/docs/CONTRIBUTING.md +2 -1
- data/docs/inline.md +36 -6
- data/docs/rbs_by_example.md +20 -20
- data/docs/release.md +69 -0
- data/docs/syntax.md +2 -2
- data/docs/wasm_serialization.md +80 -0
- data/ext/rbs_extension/ast_translation.c +1294 -973
- data/ext/rbs_extension/ast_translation.h +4 -0
- data/ext/rbs_extension/legacy_location.c +11 -6
- data/ext/rbs_extension/main.c +139 -4
- data/include/rbs/ast.h +9 -1
- data/include/rbs/serialize.h +39 -0
- data/lib/rbs/ast/ruby/comment_block.rb +6 -4
- data/lib/rbs/ast/ruby/helpers/location_helper.rb +1 -1
- data/lib/rbs/ast/ruby/members.rb +12 -1
- data/lib/rbs/buffer.rb +48 -11
- data/lib/rbs/collection/sources/git.rb +6 -0
- data/lib/rbs/definition_builder/method_builder.rb +12 -6
- data/lib/rbs/environment.rb +4 -3
- data/lib/rbs/inline_parser.rb +5 -3
- data/lib/rbs/namespace.rb +47 -11
- data/lib/rbs/parser_aux.rb +4 -2
- data/lib/rbs/prototype/rbi.rb +193 -25
- data/lib/rbs/prototype/runtime.rb +2 -0
- data/lib/rbs/resolver/type_name_resolver.rb +12 -14
- data/lib/rbs/type_name.rb +33 -13
- data/lib/rbs/unit_test/type_assertions.rb +9 -0
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/wasm/deserializer.rb +213 -0
- data/lib/rbs/wasm/location.rb +61 -0
- data/lib/rbs/wasm/parser.rb +137 -0
- data/lib/rbs/wasm/runtime.rb +196 -0
- data/lib/rbs/wasm/serialization_schema.rb +110 -0
- data/lib/rbs.rb +13 -2
- data/lib/rbs_jars.rb +39 -0
- data/lib/rdoc_plugin/parser.rb +5 -0
- data/rbs.gemspec +32 -2
- data/sig/ast/ruby/members.rbs +6 -1
- data/sig/buffer.rbs +19 -1
- data/sig/namespace.rbs +20 -0
- data/sig/parser.rbs +10 -0
- data/sig/prototype/rbi.rbs +33 -4
- data/sig/resolver/type_name_resolver.rbs +2 -4
- data/sig/typename.rbs +15 -0
- data/sig/unit_test/type_assertions.rbs +4 -0
- data/sig/wasm/deserializer.rbs +66 -0
- data/sig/wasm/serialization_schema.rbs +13 -0
- data/src/ast.c +78 -78
- data/src/lexer.c +97 -93
- data/src/lexer.re +1 -1
- data/src/lexstate.c +9 -1
- data/src/serialize.c +958 -0
- data/src/util/rbs_allocator.c +14 -8
- data/stdlib/abbrev/0/array.rbs +1 -1
- data/stdlib/csv/0/csv.rbs +5 -5
- data/stdlib/delegate/0/delegator.rbs +2 -1
- data/stdlib/digest/0/digest.rbs +11 -5
- data/stdlib/erb/0/erb.rbs +1 -1
- data/stdlib/etc/0/etc.rbs +18 -4
- data/stdlib/fileutils/0/fileutils.rbs +21 -21
- data/stdlib/ipaddr/0/ipaddr.rbs +0 -5
- data/stdlib/json/0/json.rbs +6 -6
- data/stdlib/monitor/0/monitor.rbs +2 -2
- data/stdlib/openssl/0/openssl.rbs +44 -38
- data/stdlib/resolv/0/resolv.rbs +1 -1
- data/stdlib/shellwords/0/shellwords.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +32 -10
- data/stdlib/strscan/0/string_scanner.rbs +74 -55
- data/stdlib/tempfile/0/manifest.yaml +3 -0
- data/stdlib/timeout/0/timeout.rbs +0 -5
- data/stdlib/tsort/0/cyclic.rbs +1 -1
- data/stdlib/tsort/0/interfaces.rbs +8 -8
- data/stdlib/tsort/0/tsort.rbs +9 -9
- data/stdlib/uri/0/generic.rbs +0 -5
- data/stdlib/zlib/0/gzip_reader.rbs +2 -2
- data/stdlib/zlib/0/zstream.rbs +0 -1
- data/wasm/README.md +60 -0
- data/wasm/rbs_wasm.c +423 -0
- metadata +26 -5
- data/.vscode/extensions.json +0 -5
- data/.vscode/settings.json +0 -19
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,93 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 4.1.0 (2026-07-27)
|
|
4
|
+
|
|
5
|
+
RBS 4.1 ships with JRuby support. The RBS parser is written in plain C without depending on the Ruby C API, so it is compiled to WebAssembly and runs on a Wasm runtime, with the parsed AST serialized in a binary format and decoded into RBS objects. The full test suite runs on JRuby in CI.
|
|
6
|
+
|
|
7
|
+
The inline RBS syntax gets three new features: singleton method definitions (`def self.`), the `module-self` constraint, and instance variable annotations in `module` declarations. Note that RBS inline is still experimental and may change in future releases.
|
|
8
|
+
|
|
9
|
+
This release also introduces `RBS::Rewriter`, an API to edit RBS source text while preserving the surrounding content, which `rbs annotate` is now built on. Parsing performance is improved by interning type names in a shared trie and reducing allocations per node.
|
|
10
|
+
|
|
11
|
+
`RBS::Prototype::Runtime`, the RDoc plugin parser, and the top-level `float` type alias are deprecated in this release.
|
|
12
|
+
|
|
13
|
+
### Signature updates
|
|
14
|
+
|
|
15
|
+
**Updated classes/modules/methods:** `ARGF`, `Array`, `CSV`, `Class`, `Delegator`, `Digest`, `ERB`, `Enumerable`, `Enumerator`, `Enumerator::Product`, `Etc`, `File`, `File::Constants`, `File::Stat`, `FileUtils`, `Float`, `Gem`, `Hash`, `IO`, `IPAddr`, `Integer`, `JSON`, `Kernel`, `MatchData`, `Module`, `Monitor`, `Numeric`, `ObjectSpace::WeakKeyMap`, `OpenSSL`, `Pathname`, `RBS::Ops`, `Ractor`, `Range`, `Resolv`, `RubyVM::InstructionSequence`, `Set`, `Shellwords`, `String`, `StringIO`, `StringScanner`, `Struct`, `Tempfile`, `Thread`, `Timeout`, `TSort`, `URI::Generic`, `Zlib::GzipReader`, `Zlib::ZStream`
|
|
16
|
+
|
|
17
|
+
* Remove stale Float constants and add a constant drift test ([#2994](https://github.com/ruby/rbs/pull/2994))
|
|
18
|
+
* Update RDoc comments with Ruby 4.0.6 ([#3035](https://github.com/ruby/rbs/pull/3035))
|
|
19
|
+
* Add a dependency on tempfile. ([#3025](https://github.com/ruby/rbs/pull/3025))
|
|
20
|
+
* Support `%a{implicitly-returns-nil}` on `MatchData#[]` ([#2990](https://github.com/ruby/rbs/pull/2990))
|
|
21
|
+
* Update `Array` ([#2987](https://github.com/ruby/rbs/pull/2987))
|
|
22
|
+
* Allow nil output buffers for reader methods ([#3002](https://github.com/ruby/rbs/pull/3002))
|
|
23
|
+
* Add stdlib signature tests for #2967 ([#2989](https://github.com/ruby/rbs/pull/2989))
|
|
24
|
+
* Update `Integer`, phase 1 ([#2995](https://github.com/ruby/rbs/pull/2995))
|
|
25
|
+
* Add RBS::Ops ([#2934](https://github.com/ruby/rbs/pull/2934))
|
|
26
|
+
* Update Module ([#2933](https://github.com/ruby/rbs/pull/2933))
|
|
27
|
+
* Correct core/stdlib signatures to match Ruby 4.0 ([#2967](https://github.com/ruby/rbs/pull/2967))
|
|
28
|
+
* Revert Digest::Class method changes ([#2980](https://github.com/ruby/rbs/pull/2980))
|
|
29
|
+
* Add stdlib tests for updated StringScanner signatures ([#2968](https://github.com/ruby/rbs/pull/2968))
|
|
30
|
+
* Update `StringScanner` signatures to match strscan 3.1.6 ([#2959](https://github.com/ruby/rbs/pull/2959))
|
|
31
|
+
* Remove StringScanner methods absent from the latest Ruby release ([#2961](https://github.com/ruby/rbs/pull/2961))
|
|
32
|
+
* Fix `Resolv#initialize` signature: array of resolvers + `use_ipv6:` ([#2960](https://github.com/ruby/rbs/pull/2960))
|
|
33
|
+
* [Hash] Update Hash's signatures and tests to be correct ([#2694](https://github.com/ruby/rbs/pull/2694))
|
|
34
|
+
* update rbs signatures to be more consistent with generics ([#2867](https://github.com/ruby/rbs/pull/2867))
|
|
35
|
+
* Use top-level `path` in fileutils.rbs to suppress deprecation warning ([#2949](https://github.com/ruby/rbs/pull/2949))
|
|
36
|
+
* Update File::Constants and File::Stat ([#2942](https://github.com/ruby/rbs/pull/2942))
|
|
37
|
+
* Add signature for `RubyVM::InstructionSequence.of` ([#2916](https://github.com/ruby/rbs/pull/2916))
|
|
38
|
+
* fix OpenSSL#session_new_cb signature ([#2924](https://github.com/ruby/rbs/pull/2924))
|
|
39
|
+
* [Class] update class.rbs ([#2898](https://github.com/ruby/rbs/pull/2898))
|
|
40
|
+
* Deprecate top-level float ([#2695](https://github.com/ruby/rbs/pull/2695))
|
|
41
|
+
* [Kernel] Updated querying methods ([#2685](https://github.com/ruby/rbs/pull/2685))
|
|
42
|
+
|
|
43
|
+
### Library changes
|
|
44
|
+
|
|
45
|
+
* Convert character offset to byte offset in parse_inline_*_annotation ([#2945](https://github.com/ruby/rbs/pull/2945))
|
|
46
|
+
* Guard against underflow when sysconf(_SC_PAGESIZE) returns 0 ([#3031](https://github.com/ruby/rbs/pull/3031))
|
|
47
|
+
* Report invalid UTF-8 byte in a comment as a parsing error ([#2983](https://github.com/ruby/rbs/pull/2983))
|
|
48
|
+
* Fetch Chicory/ASM jars from Maven instead of bundling in gem ([#3019](https://github.com/ruby/rbs/pull/3019))
|
|
49
|
+
* Add write barrier protection to RBS Location objects ([#3022](https://github.com/ruby/rbs/pull/3022))
|
|
50
|
+
* Rename parameter in rbs_intern_type_name for clarity ([#3023](https://github.com/ruby/rbs/pull/3023))
|
|
51
|
+
* Deprecate RDoc plugin parser ([#3016](https://github.com/ruby/rbs/pull/3016))
|
|
52
|
+
* Run the test suite on JRuby (JRuby support, step 4) ([#3008](https://github.com/ruby/rbs/pull/3008))
|
|
53
|
+
* Run the RBS parser on JRuby via WebAssembly (JRuby support, step 3) ([#3000](https://github.com/ruby/rbs/pull/3000))
|
|
54
|
+
* Add binary serialization of the parsed AST (JRuby support, step 2) ([#2999](https://github.com/ruby/rbs/pull/2999))
|
|
55
|
+
* Build the RBS parser as a WebAssembly module (JRuby support, step 1) ([#2998](https://github.com/ruby/rbs/pull/2998))
|
|
56
|
+
* Reject reversed position ranges in parser/lexer entrypoints ([#2974](https://github.com/ruby/rbs/pull/2974))
|
|
57
|
+
* Fix lexer infinite loop / abort on invalid UTF-8 byte ([#2973](https://github.com/ruby/rbs/pull/2973))
|
|
58
|
+
* Flyweight TypeName / Namespace cached in a shared trie ([#2957](https://github.com/ruby/rbs/pull/2957))
|
|
59
|
+
* Reduce Hash allocation per `Node` creation ([#2946](https://github.com/ruby/rbs/pull/2946))
|
|
60
|
+
* Tidy `ast_translation.c` ([#2947](https://github.com/ruby/rbs/pull/2947))
|
|
61
|
+
* Auto-generate rbs_ast_ruby_annotations_t union from config.yml ([#2939](https://github.com/ruby/rbs/pull/2939))
|
|
62
|
+
* Speed up RBS::InlineParser on large sources with non-ASCII characters ([#2950](https://github.com/ruby/rbs/pull/2950))
|
|
63
|
+
* Support `def self.method_name` singleton method in inline parser ([#2935](https://github.com/ruby/rbs/pull/2935))
|
|
64
|
+
* This is not prism ([#2951](https://github.com/ruby/rbs/pull/2951))
|
|
65
|
+
* Add RBS::Rewriter and use it in rbs annotate ([#2927](https://github.com/ruby/rbs/pull/2927))
|
|
66
|
+
* Add nullability annotations to AST pointer types ([#2922](https://github.com/ruby/rbs/pull/2922))
|
|
67
|
+
* Support `module-self` inline annotation ([#2921](https://github.com/ruby/rbs/pull/2921))
|
|
68
|
+
* Inline instance variable annotation in module declaration ([#2919](https://github.com/ruby/rbs/pull/2919))
|
|
69
|
+
|
|
70
|
+
#### rbs prototype
|
|
71
|
+
|
|
72
|
+
* Fix nested declarations in rbs prototype rbi ([#3029](https://github.com/ruby/rbs/pull/3029))
|
|
73
|
+
* Deprecate prototype runtime ([#2956](https://github.com/ruby/rbs/pull/2956))
|
|
74
|
+
|
|
75
|
+
#### rbs collection
|
|
76
|
+
|
|
77
|
+
* Clean up partial clone before falling back to full clone ([#2978](https://github.com/ruby/rbs/pull/2978))
|
|
78
|
+
* Suppress spurious warning for non-gem stdlib libraries ([#2929](https://github.com/ruby/rbs/pull/2929))
|
|
79
|
+
|
|
80
|
+
### Miscellaneous
|
|
81
|
+
|
|
82
|
+
* Fix Lint/DuplicateMethods in StringIO_test.rb ([#3010](https://github.com/ruby/rbs/pull/3010))
|
|
83
|
+
* Compressed files must be opened in binary mode ([#2981](https://github.com/ruby/rbs/pull/2981))
|
|
84
|
+
* Fix flaky DirSingletonTest GC failures in test_fchdir and test_for_fd ([#3004](https://github.com/ruby/rbs/pull/3004))
|
|
85
|
+
* Add TruffleRuby CI job ([#2996](https://github.com/ruby/rbs/pull/2996))
|
|
86
|
+
* Update the target Ruby version notes to the latest release ([#2962](https://github.com/ruby/rbs/pull/2962))
|
|
87
|
+
* Update docs/inline.md to match current inline parser behavior ([#2953](https://github.com/ruby/rbs/pull/2953))
|
|
88
|
+
* ci: skip Gemfile.lock BUNDLED WITH on ruby-head ([#2952](https://github.com/ruby/rbs/pull/2952))
|
|
89
|
+
* Remove `logger` from sig dependencies ([#2904](https://github.com/ruby/rbs/pull/2904))
|
|
90
|
+
|
|
3
91
|
## 4.0.2 (2026-03-25)
|
|
4
92
|
|
|
5
93
|
### Library changes
|
data/Dockerfile.jruby
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# JRuby verification image for RBS.
|
|
2
|
+
#
|
|
3
|
+
# RBS can't load its MRI C extension on JRuby, so it parses through a
|
|
4
|
+
# WebAssembly build of the parser (see lib/rbs/wasm and docs/wasm_serialization.md).
|
|
5
|
+
# This single-stage image installs the WASI SDK, compiles rbs_parser.wasm and
|
|
6
|
+
# downloads the Chicory/ASM jars into ~/.m2 (via jar-dependencies), then runs the
|
|
7
|
+
# test suite on JRuby. It mirrors .github/workflows/jruby.yml but is self-contained.
|
|
8
|
+
#
|
|
9
|
+
# docker build -f Dockerfile.jruby -t rbs-jruby .
|
|
10
|
+
# docker run --rm rbs-jruby # run the test suite
|
|
11
|
+
# docker run --rm -e RBS_PLATFORM=java rbs-jruby \
|
|
12
|
+
# gem build rbs.gemspec # build the -java gem
|
|
13
|
+
#
|
|
14
|
+
# Bundler is intentionally not used: the development Gemfile pulls in CRuby-only
|
|
15
|
+
# C extensions (bigdecimal, stackprof, ...) that cannot build on JRuby. The few
|
|
16
|
+
# gems the suite needs are installed directly, exactly as the CI does.
|
|
17
|
+
|
|
18
|
+
FROM jruby:10.1.1.0-jdk21
|
|
19
|
+
|
|
20
|
+
# Keep in sync with .github/workflows/wasm.yml and .github/workflows/jruby.yml.
|
|
21
|
+
ARG WASI_SDK_VERSION=33
|
|
22
|
+
ARG WASI_SDK_RELEASE=33.0
|
|
23
|
+
|
|
24
|
+
# build-essential supplies cc/make: on JRuby the prism gem builds libprism.so
|
|
25
|
+
# (loaded via FFI) instead of an MRI C extension, so it needs a C toolchain.
|
|
26
|
+
RUN apt-get update \
|
|
27
|
+
&& apt-get install -y --no-install-recommends git curl ca-certificates build-essential \
|
|
28
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
29
|
+
|
|
30
|
+
# The WASI SDK provides clang, the wasi-libc sysroot and the wasm32 compiler-rt
|
|
31
|
+
# builtins that `rake wasm:build` needs to compile src/**/*.c to WebAssembly.
|
|
32
|
+
RUN set -eux; \
|
|
33
|
+
case "$(uname -m)" in \
|
|
34
|
+
x86_64 | amd64) wasi_arch=x86_64 ;; \
|
|
35
|
+
aarch64 | arm64) wasi_arch=arm64 ;; \
|
|
36
|
+
*) echo "unsupported arch: $(uname -m)" >&2; exit 1 ;; \
|
|
37
|
+
esac; \
|
|
38
|
+
mkdir -p /opt/wasi-sdk; \
|
|
39
|
+
curl -fsSL "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_RELEASE}-${wasi_arch}-linux.tar.gz" \
|
|
40
|
+
| tar xz --strip-components=1 -C /opt/wasi-sdk
|
|
41
|
+
ENV WASI_SDK_PATH=/opt/wasi-sdk
|
|
42
|
+
|
|
43
|
+
# Runtime/test gems the suite needs on JRuby (same set as the jruby.yml CI).
|
|
44
|
+
RUN gem install prism rake rake-compiler test-unit rdoc rspec minitest json-schema pry --no-document
|
|
45
|
+
|
|
46
|
+
WORKDIR /rbs
|
|
47
|
+
COPY . .
|
|
48
|
+
|
|
49
|
+
# Compile rbs_parser.wasm (clang is a subprocess, so the build is engine
|
|
50
|
+
# independent) and download the Chicory + ASM jars into ~/.m2 via jar-dependencies.
|
|
51
|
+
RUN rake wasm:jruby_setup wasm:install_jars
|
|
52
|
+
|
|
53
|
+
CMD ["rake", "test"]
|
data/README.md
CHANGED
|
@@ -54,8 +54,8 @@ end
|
|
|
54
54
|
|
|
55
55
|
## The Target Version
|
|
56
56
|
|
|
57
|
-
* The standard library signatures targets the latest release of Ruby. (`
|
|
58
|
-
* The library code targets non-EOL versions of Ruby. (`>= 3.
|
|
57
|
+
* The standard library signatures targets the [latest release of Ruby](https://www.ruby-lang.org/en/downloads/branches/). (`4.0` as of 2026.)
|
|
58
|
+
* The library code targets [non-EOL versions of Ruby](https://www.ruby-lang.org/en/downloads/branches/). (`>= 3.3` as of 2026.)
|
|
59
59
|
|
|
60
60
|
## Installation
|
|
61
61
|
|
|
@@ -122,7 +122,7 @@ This is only a starting point, and you should edit the output to match your sign
|
|
|
122
122
|
|
|
123
123
|
- `rb` generates from just the available Ruby code
|
|
124
124
|
- `rbi` generates from Sorbet RBI
|
|
125
|
-
- `runtime` generates from runtime API
|
|
125
|
+
- `runtime` generates from runtime API (**deprecated**; see [#2841](https://github.com/ruby/rbs/issues/2841))
|
|
126
126
|
|
|
127
127
|
## Library
|
|
128
128
|
|
data/Rakefile
CHANGED
|
@@ -33,7 +33,14 @@ test_config = lambda do |t|
|
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
if RUBY_ENGINE == "jruby"
|
|
37
|
+
# JRuby runs the parser in WebAssembly instead of the C extension, so there is
|
|
38
|
+
# nothing to compile. The wasm runtime must be assembled first with
|
|
39
|
+
# `rake wasm:jruby_setup` (which needs CRuby + the WASI SDK).
|
|
40
|
+
Rake::TestTask.new(:test, &test_config)
|
|
41
|
+
else
|
|
42
|
+
Rake::TestTask.new(test: :compile, &test_config)
|
|
43
|
+
end
|
|
37
44
|
|
|
38
45
|
multitask :default => [:test, :stdlib_test, :typecheck_test, :rubocop, :validate, :test_doc]
|
|
39
46
|
|
|
@@ -160,6 +167,10 @@ task :templates do
|
|
|
160
167
|
sh "#{ruby} templates/template.rb include/rbs/ast.h"
|
|
161
168
|
sh "#{ruby} templates/template.rb src/ast.c"
|
|
162
169
|
|
|
170
|
+
sh "#{ruby} templates/template.rb include/rbs/serialize.h"
|
|
171
|
+
sh "#{ruby} templates/template.rb src/serialize.c"
|
|
172
|
+
sh "#{ruby} templates/template.rb lib/rbs/wasm/serialization_schema.rb"
|
|
173
|
+
|
|
163
174
|
# Format the generated files
|
|
164
175
|
Rake::Task["format:c"].invoke
|
|
165
176
|
end
|
|
@@ -549,6 +560,97 @@ task :prepare_profiling do
|
|
|
549
560
|
Rake::Task[:"compile"].invoke
|
|
550
561
|
end
|
|
551
562
|
|
|
563
|
+
namespace :wasm do
|
|
564
|
+
WASM_DIR = File.expand_path("wasm", __dir__)
|
|
565
|
+
WASM_OUTPUT = File.join(WASM_DIR, "rbs_parser.wasm")
|
|
566
|
+
|
|
567
|
+
# The parser under src/ is plain, self-contained C with no dependency on the
|
|
568
|
+
# Ruby C API, so it can be compiled to WebAssembly as-is. The only extra
|
|
569
|
+
# translation unit is the entry-point shim under wasm/.
|
|
570
|
+
def wasm_source_files
|
|
571
|
+
Dir.glob(File.join(__dir__, "src/**/*.c")).sort + [File.join(WASM_DIR, "rbs_wasm.c")]
|
|
572
|
+
end
|
|
573
|
+
|
|
574
|
+
# Locate the clang shipped with the WASI SDK.
|
|
575
|
+
#
|
|
576
|
+
# The system clang can target wasm32, but the WASI SDK additionally provides
|
|
577
|
+
# the wasi-libc sysroot and the wasm32 compiler-rt builtins that the link
|
|
578
|
+
# step needs, so we require it explicitly.
|
|
579
|
+
def wasi_clang
|
|
580
|
+
sdk = ENV["WASI_SDK_PATH"]
|
|
581
|
+
if sdk.nil? || sdk.empty?
|
|
582
|
+
raise <<~MSG
|
|
583
|
+
WASI_SDK_PATH is not set.
|
|
584
|
+
|
|
585
|
+
Install the WASI SDK from https://github.com/WebAssembly/wasi-sdk/releases
|
|
586
|
+
and point WASI_SDK_PATH at the extracted directory, for example:
|
|
587
|
+
|
|
588
|
+
export WASI_SDK_PATH=/opt/wasi-sdk
|
|
589
|
+
rake wasm:build
|
|
590
|
+
MSG
|
|
591
|
+
end
|
|
592
|
+
|
|
593
|
+
clang = File.join(sdk, "bin", "clang")
|
|
594
|
+
raise "clang not found at #{clang} (is WASI_SDK_PATH correct?)" unless File.executable?(clang)
|
|
595
|
+
|
|
596
|
+
clang
|
|
597
|
+
end
|
|
598
|
+
|
|
599
|
+
desc "Build the RBS parser as a WebAssembly module (requires WASI_SDK_PATH)"
|
|
600
|
+
task :build do
|
|
601
|
+
mkdir_p WASM_DIR
|
|
602
|
+
sh wasi_clang,
|
|
603
|
+
"--target=wasm32-wasip1",
|
|
604
|
+
# No `main`; the host calls `_initialize` and then the exported functions.
|
|
605
|
+
"-mexec-model=reactor",
|
|
606
|
+
"-std=gnu11",
|
|
607
|
+
"-O2",
|
|
608
|
+
"-Wno-unused-parameter",
|
|
609
|
+
"-I#{File.join(__dir__, "include")}",
|
|
610
|
+
"-o", WASM_OUTPUT,
|
|
611
|
+
*wasm_source_files
|
|
612
|
+
puts "Built #{WASM_OUTPUT}"
|
|
613
|
+
end
|
|
614
|
+
|
|
615
|
+
desc "Build and smoke-test the WebAssembly module (requires wasmtime)"
|
|
616
|
+
task :check => :build do
|
|
617
|
+
wasmtime = ENV["WASMTIME"] || "wasmtime"
|
|
618
|
+
|
|
619
|
+
# `rbs_wasm_selftest` parses a small fixed signature and returns 1 on
|
|
620
|
+
# success. `--invoke` prints the return value to stdout.
|
|
621
|
+
output = IO.popen([wasmtime, "run", "--invoke", "rbs_wasm_selftest", WASM_OUTPUT], err: File::NULL, &:read).to_s.strip
|
|
622
|
+
|
|
623
|
+
if output == "1"
|
|
624
|
+
puts "WebAssembly selftest passed."
|
|
625
|
+
else
|
|
626
|
+
raise "WebAssembly selftest failed: rbs_wasm_selftest returned #{output.inspect} (expected \"1\")"
|
|
627
|
+
end
|
|
628
|
+
end
|
|
629
|
+
|
|
630
|
+
# Where the runtime looks for the module by default (see RBS::WASM::Runtime).
|
|
631
|
+
JRUBY_WASM_DIR = File.expand_path("lib/rbs/wasm", __dir__)
|
|
632
|
+
|
|
633
|
+
desc "Download the Chicory/ASM jars into the local Maven repository (~/.m2). Run on JRuby."
|
|
634
|
+
task :install_jars do
|
|
635
|
+
# Resolves the `jar` requirements from rbs.gemspec via Maven and downloads
|
|
636
|
+
# them (and their transitive deps) into ~/.m2, the same way `gem install`
|
|
637
|
+
# does; the jars are not copied into the gem. The platform is forced to java
|
|
638
|
+
# because Jars::Installer skips non-java gems, and write_require_file is false
|
|
639
|
+
# because lib/rbs_jars.rb is hand-maintained (the generator mangles the
|
|
640
|
+
# `com.dylibso.chicory:runtime` artifact id).
|
|
641
|
+
require "jars/installer"
|
|
642
|
+
spec = Gem::Specification.load("rbs.gemspec")
|
|
643
|
+
spec.platform = "java"
|
|
644
|
+
Jars::Installer.new(spec).install_jars(write_require_file: false)
|
|
645
|
+
end
|
|
646
|
+
|
|
647
|
+
desc "Build rbs_parser.wasm and copy it next to RBS::WASM::Runtime"
|
|
648
|
+
task :jruby_setup => [:build] do
|
|
649
|
+
cp WASM_OUTPUT, File.join(JRUBY_WASM_DIR, "rbs_parser.wasm")
|
|
650
|
+
puts "rbs_parser.wasm is ready under #{JRUBY_WASM_DIR}"
|
|
651
|
+
end
|
|
652
|
+
end
|
|
653
|
+
|
|
552
654
|
namespace :rust do
|
|
553
655
|
namespace :rbs do
|
|
554
656
|
RUST_DIR = File.expand_path("rust", __dir__)
|
data/Steepfile
CHANGED
|
@@ -6,6 +6,15 @@ target :lib do
|
|
|
6
6
|
ignore(
|
|
7
7
|
"lib/rbs/test",
|
|
8
8
|
# "lib/rbs/test.rb"
|
|
9
|
+
|
|
10
|
+
# JRuby-only implementations of RBS::Location and RBS::Parser. Like the C
|
|
11
|
+
# extension, these implement interfaces already described in sig/, and
|
|
12
|
+
# runtime.rb is Java interop, so they are not type-checked here.
|
|
13
|
+
"lib/rbs/wasm/location.rb",
|
|
14
|
+
"lib/rbs/wasm/runtime.rb",
|
|
15
|
+
"lib/rbs/wasm/parser.rb",
|
|
16
|
+
# jar-dependencies require_jar calls for the JRuby runtime; not type-checked.
|
|
17
|
+
"lib/rbs_jars.rb",
|
|
9
18
|
)
|
|
10
19
|
|
|
11
20
|
library "pathname", "json", "logger", "monitor", "tsort", "uri", 'dbm', 'pstore', 'singleton', 'shellwords', 'fileutils', 'find', 'digest', 'prettyprint', 'yaml', "psych", "securerandom"
|