rbs 4.1.0.pre.1 → 4.1.0.pre.2
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/.github/workflows/c-check.yml +3 -0
- data/.github/workflows/dependabot.yml +1 -1
- data/.github/workflows/jruby.yml +67 -0
- data/.github/workflows/milestone.yml +4 -1
- data/.github/workflows/ruby.yml +12 -0
- data/.github/workflows/rust.yml +3 -0
- data/.github/workflows/truffleruby.yml +54 -0
- data/.github/workflows/typecheck.yml +3 -0
- data/.github/workflows/wasm.yml +53 -0
- data/.github/workflows/windows.yml +6 -0
- data/.gitignore +7 -0
- data/README.md +3 -3
- data/Rakefile +116 -1
- data/Steepfile +7 -0
- data/core/array.rbs +144 -144
- 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/hash.rbs +117 -101
- data/core/integer.rbs +21 -58
- data/core/io.rbs +25 -7
- data/core/module.rbs +88 -74
- data/core/numeric.rbs +3 -0
- data/core/object_space/weak_key_map.rbs +7 -7
- data/core/range.rbs +23 -23
- data/core/rbs/ops.rbs +154 -0
- data/core/rbs/unnamed/argf.rbs +3 -3
- data/core/set.rbs +3 -3
- data/core/struct.rbs +16 -16
- data/core/thread.rbs +6 -6
- data/docs/CONTRIBUTING.md +2 -1
- data/docs/inline.md +36 -6
- data/docs/rbs_by_example.md +20 -20
- 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/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/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 +217 -0
- data/lib/rbs/wasm/serialization_schema.rb +110 -0
- data/lib/rbs.rb +13 -2
- data/rbs.gemspec +19 -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/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/lexstate.c +5 -1
- data/src/serialize.c +958 -0
- data/src/util/rbs_allocator.c +1 -4
- data/stdlib/abbrev/0/array.rbs +1 -1
- data/stdlib/csv/0/csv.rbs +5 -5
- data/stdlib/digest/0/digest.rbs +1 -1
- data/stdlib/etc/0/etc.rbs +18 -4
- data/stdlib/fileutils/0/fileutils.rbs +21 -21
- data/stdlib/json/0/json.rbs +6 -6
- data/stdlib/openssl/0/openssl.rbs +5 -5
- 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/tsort/0/cyclic.rbs +1 -1
- data/stdlib/tsort/0/interfaces.rbs +8 -8
- data/stdlib/tsort/0/tsort.rbs +9 -9
- data/stdlib/zlib/0/gzip_reader.rbs +2 -2
- data/wasm/README.md +59 -0
- data/wasm/rbs_wasm.c +411 -0
- metadata +21 -5
- data/.vscode/extensions.json +0 -5
- data/.vscode/settings.json +0 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 125952c7d052ff2adaa683375a5e5079c4019f43ea9bc86546a4efd9eed2ed0e
|
|
4
|
+
data.tar.gz: 8df793a9e6419ec7d4d137fec60811e0eadc68e8ebe6359a149cad43deb26f6e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 254fc00d7c4bf3910796b4af6b573cf0be978b68a1db193a703a90e44e18df53b7399611d8acd40bff853e2c21fffd83468815fa24f71bdb36255b5cf164907a
|
|
7
|
+
data.tar.gz: 0b4bf3195dede912a3eee97ea770e9c99b907eea6e7e28b5492818ee64d6128dc9d0262bab70d127c2e946a3f7f77536fa4a3fa884ea576f746231abcbfd9458
|
|
@@ -14,7 +14,7 @@ jobs:
|
|
|
14
14
|
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
|
|
15
15
|
steps:
|
|
16
16
|
- name: Dependabot metadata
|
|
17
|
-
uses: dependabot/fetch-metadata@
|
|
17
|
+
uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
|
|
18
18
|
id: metadata
|
|
19
19
|
- name: Checkout repository
|
|
20
20
|
uses: actions/checkout@v6
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
name: JRuby
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
pull_request:
|
|
8
|
+
paths:
|
|
9
|
+
- ".github/workflows/jruby.yml"
|
|
10
|
+
- "include/**"
|
|
11
|
+
- "src/**"
|
|
12
|
+
- "wasm/**"
|
|
13
|
+
- "lib/**"
|
|
14
|
+
- "sig/**"
|
|
15
|
+
- "core/**"
|
|
16
|
+
- "stdlib/**"
|
|
17
|
+
- "test/**"
|
|
18
|
+
- "Rakefile"
|
|
19
|
+
- "rbs.gemspec"
|
|
20
|
+
|
|
21
|
+
permissions:
|
|
22
|
+
contents: read
|
|
23
|
+
|
|
24
|
+
env:
|
|
25
|
+
# Keep in sync with .github/workflows/wasm.yml.
|
|
26
|
+
WASI_SDK_VERSION: "33"
|
|
27
|
+
WASI_SDK_RELEASE: "33.0"
|
|
28
|
+
|
|
29
|
+
jobs:
|
|
30
|
+
test:
|
|
31
|
+
name: jruby
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/checkout@v6
|
|
35
|
+
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
|
|
36
|
+
|
|
37
|
+
# Build the .wasm and fetch the Chicory jars with CRuby + the WASI SDK,
|
|
38
|
+
# then run RBS itself on JRuby against those artifacts.
|
|
39
|
+
- name: Set up Ruby (to assemble the WebAssembly runtime)
|
|
40
|
+
uses: ruby/setup-ruby@v1
|
|
41
|
+
with:
|
|
42
|
+
ruby-version: ruby
|
|
43
|
+
bundler: none
|
|
44
|
+
- name: Update rubygems & bundler
|
|
45
|
+
run: gem update --system
|
|
46
|
+
- name: Install gems
|
|
47
|
+
run: |
|
|
48
|
+
bundle config set --local without libs:profilers
|
|
49
|
+
bundle install --jobs 4 --retry 3
|
|
50
|
+
- name: Install the WASI SDK
|
|
51
|
+
run: |
|
|
52
|
+
url="https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_RELEASE}-x86_64-linux.tar.gz"
|
|
53
|
+
mkdir -p "$HOME/wasi-sdk"
|
|
54
|
+
curl -sSL "$url" | tar xz --strip-components=1 -C "$HOME/wasi-sdk"
|
|
55
|
+
echo "WASI_SDK_PATH=$HOME/wasi-sdk" >> "$GITHUB_ENV"
|
|
56
|
+
- name: Assemble the JRuby runtime (rbs_parser.wasm + Chicory jars)
|
|
57
|
+
run: bundle exec rake wasm:jruby_setup
|
|
58
|
+
|
|
59
|
+
- name: Set up JRuby
|
|
60
|
+
uses: ruby/setup-ruby@v1
|
|
61
|
+
with:
|
|
62
|
+
ruby-version: jruby
|
|
63
|
+
bundler: none
|
|
64
|
+
- name: Install runtime and test gems
|
|
65
|
+
run: gem install prism rake rake-compiler test-unit rdoc rspec minitest json-schema pry --no-document
|
|
66
|
+
- name: Run the test suite on JRuby
|
|
67
|
+
run: jruby -S rake test
|
|
@@ -4,6 +4,9 @@ on:
|
|
|
4
4
|
pull_request:
|
|
5
5
|
types: [opened, edited, labeled, unlabeled, milestoned, demilestoned, synchronize]
|
|
6
6
|
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
7
10
|
jobs:
|
|
8
11
|
check:
|
|
9
12
|
runs-on: ubuntu-latest
|
|
@@ -27,7 +30,7 @@ jobs:
|
|
|
27
30
|
echo "RBS::VERSION = $version (major=$major, minor=$minor, patch=$patch)"
|
|
28
31
|
|
|
29
32
|
- name: Check milestone
|
|
30
|
-
uses: actions/github-script@
|
|
33
|
+
uses: actions/github-script@v9
|
|
31
34
|
with:
|
|
32
35
|
script: |
|
|
33
36
|
const pr = context.payload.pull_request;
|
data/.github/workflows/ruby.yml
CHANGED
|
@@ -7,6 +7,9 @@ on:
|
|
|
7
7
|
pull_request: {}
|
|
8
8
|
merge_group: {}
|
|
9
9
|
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
|
|
10
13
|
jobs:
|
|
11
14
|
test:
|
|
12
15
|
runs-on: "ubuntu-latest"
|
|
@@ -63,6 +66,9 @@ jobs:
|
|
|
63
66
|
if: ${{ contains(matrix.ruby, 'head') }}
|
|
64
67
|
run: |
|
|
65
68
|
bundle config set force_ruby_platform true
|
|
69
|
+
- name: Ignore Gemfile.lock's BUNDLED WITH on ruby-head
|
|
70
|
+
if: ${{ contains(matrix.ruby, 'head') }}
|
|
71
|
+
run: bundle config set --local version system
|
|
66
72
|
- name: Skip installing type checkers
|
|
67
73
|
if: ${{ ! contains(matrix.job, 'typecheck_test') }}
|
|
68
74
|
run: |
|
|
@@ -106,6 +112,9 @@ jobs:
|
|
|
106
112
|
if: ${{ contains(matrix.ruby, 'head') }}
|
|
107
113
|
run: |
|
|
108
114
|
bundle config set force_ruby_platform true
|
|
115
|
+
- name: Ignore Gemfile.lock's BUNDLED WITH on ruby-head
|
|
116
|
+
if: ${{ contains(matrix.ruby, 'head') }}
|
|
117
|
+
run: bundle config set --local version system
|
|
109
118
|
- name: bin/setup
|
|
110
119
|
run: |
|
|
111
120
|
bin/setup
|
|
@@ -140,6 +149,9 @@ jobs:
|
|
|
140
149
|
if: ${{ contains(matrix.ruby, 'head') }}
|
|
141
150
|
run: |
|
|
142
151
|
bundle config set force_ruby_platform true
|
|
152
|
+
- name: Ignore Gemfile.lock's BUNDLED WITH on ruby-head
|
|
153
|
+
if: ${{ contains(matrix.ruby, 'head') }}
|
|
154
|
+
run: bundle config set --local version system
|
|
143
155
|
- name: bin/setup
|
|
144
156
|
run: |
|
|
145
157
|
bin/setup
|
data/.github/workflows/rust.yml
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
name: TruffleRuby
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
pull_request: {}
|
|
8
|
+
merge_group: {}
|
|
9
|
+
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
test:
|
|
15
|
+
runs-on: "ubuntu-latest"
|
|
16
|
+
strategy:
|
|
17
|
+
fail-fast: false
|
|
18
|
+
matrix:
|
|
19
|
+
ruby: ['truffleruby']
|
|
20
|
+
job:
|
|
21
|
+
- test
|
|
22
|
+
env:
|
|
23
|
+
RANDOMIZE_STDLIB_TEST_ORDER: "true"
|
|
24
|
+
# TruffleRuby warns and falls back to US-ASCII unless the locale is UTF-8.
|
|
25
|
+
LANG: "en_US.UTF-8"
|
|
26
|
+
steps:
|
|
27
|
+
- uses: actions/checkout@v6
|
|
28
|
+
- uses: ruby/setup-ruby@v1
|
|
29
|
+
with:
|
|
30
|
+
ruby-version: ${{ matrix.ruby }}
|
|
31
|
+
bundler: none
|
|
32
|
+
- name: Set working directory as safe
|
|
33
|
+
run: git config --global --add safe.directory $(pwd)
|
|
34
|
+
- name: Install dependencies
|
|
35
|
+
run: |
|
|
36
|
+
sudo apt-get update
|
|
37
|
+
sudo apt-get install -y libdb-dev curl autoconf automake m4 libtool python3
|
|
38
|
+
- name: Update rubygems & bundler
|
|
39
|
+
run: |
|
|
40
|
+
ruby -v
|
|
41
|
+
gem update --system
|
|
42
|
+
- name: install erb
|
|
43
|
+
run: gem install erb
|
|
44
|
+
- name: bundle config
|
|
45
|
+
run: |
|
|
46
|
+
# Profilers and the typecheck tooling are not needed for the smoke test,
|
|
47
|
+
# and some of them do not support TruffleRuby.
|
|
48
|
+
bundle config set --local without 'profilers typecheck_test'
|
|
49
|
+
- name: bin/setup
|
|
50
|
+
run: |
|
|
51
|
+
bin/setup
|
|
52
|
+
- name: Run test
|
|
53
|
+
run: |
|
|
54
|
+
bundle exec rake ${{ matrix.job }}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
name: WebAssembly
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
pull_request:
|
|
8
|
+
paths:
|
|
9
|
+
- ".github/workflows/wasm.yml"
|
|
10
|
+
- "Rakefile"
|
|
11
|
+
- "include/**"
|
|
12
|
+
- "src/**"
|
|
13
|
+
- "wasm/**"
|
|
14
|
+
|
|
15
|
+
permissions:
|
|
16
|
+
contents: read
|
|
17
|
+
|
|
18
|
+
env:
|
|
19
|
+
# Pinned so the smoke test is reproducible. Bump together when upgrading.
|
|
20
|
+
WASI_SDK_VERSION: "33"
|
|
21
|
+
WASI_SDK_RELEASE: "33.0"
|
|
22
|
+
WASMTIME_VERSION: "v45.0.2"
|
|
23
|
+
|
|
24
|
+
jobs:
|
|
25
|
+
build:
|
|
26
|
+
name: wasm:check
|
|
27
|
+
runs-on: ubuntu-latest
|
|
28
|
+
steps:
|
|
29
|
+
- uses: actions/checkout@v6
|
|
30
|
+
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
|
|
31
|
+
- name: Set up Ruby
|
|
32
|
+
uses: ruby/setup-ruby@v1
|
|
33
|
+
with:
|
|
34
|
+
ruby-version: ruby
|
|
35
|
+
bundler: none
|
|
36
|
+
- name: Update rubygems & bundler
|
|
37
|
+
run: gem update --system
|
|
38
|
+
- name: Install gems
|
|
39
|
+
run: |
|
|
40
|
+
bundle config set --local without libs:profilers
|
|
41
|
+
bundle install --jobs 4 --retry 3
|
|
42
|
+
- name: Install the WASI SDK
|
|
43
|
+
run: |
|
|
44
|
+
url="https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_RELEASE}-x86_64-linux.tar.gz"
|
|
45
|
+
mkdir -p "$HOME/wasi-sdk"
|
|
46
|
+
curl -sSL "$url" | tar xz --strip-components=1 -C "$HOME/wasi-sdk"
|
|
47
|
+
echo "WASI_SDK_PATH=$HOME/wasi-sdk" >> "$GITHUB_ENV"
|
|
48
|
+
- name: Install wasmtime
|
|
49
|
+
uses: bytecodealliance/actions/wasmtime/setup@v1
|
|
50
|
+
with:
|
|
51
|
+
version: ${{ env.WASMTIME_VERSION }}
|
|
52
|
+
- name: Build and smoke-test the WebAssembly module
|
|
53
|
+
run: bundle exec rake wasm:check
|
|
@@ -7,6 +7,9 @@ on:
|
|
|
7
7
|
pull_request: {}
|
|
8
8
|
merge_group: {}
|
|
9
9
|
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
|
|
10
13
|
jobs:
|
|
11
14
|
compile:
|
|
12
15
|
runs-on: "windows-latest"
|
|
@@ -35,6 +38,9 @@ jobs:
|
|
|
35
38
|
bundled_gems = JSON.parse(res)["gems"].map{_1["gem"]}
|
|
36
39
|
system "gem uninstall #{bundled_gems.join(" ")} --force", exception: true
|
|
37
40
|
'
|
|
41
|
+
- name: Ignore Gemfile.lock's BUNDLED WITH on dev Ruby
|
|
42
|
+
if: ${{ matrix.ruby == 'ucrt' || matrix.ruby == 'mswin' }}
|
|
43
|
+
run: bundle config set --local version system
|
|
38
44
|
- name: bundle install
|
|
39
45
|
run: |
|
|
40
46
|
bundle config set without profilers libs
|
data/.gitignore
CHANGED
|
@@ -29,3 +29,10 @@ ext/rbs_extension/.cache
|
|
|
29
29
|
# Rust crate vendored RBS source (managed by rake rust:rbs:sync or rust:rbs:symlink)
|
|
30
30
|
rust/ruby-rbs-sys/vendor/rbs/
|
|
31
31
|
rust/ruby-rbs/vendor/rbs/
|
|
32
|
+
|
|
33
|
+
# Compiled WebAssembly module (built by rake wasm:build)
|
|
34
|
+
wasm/*.wasm
|
|
35
|
+
|
|
36
|
+
# JRuby runtime artifacts (assembled by rake wasm:jruby_setup, bundled in the JRuby gem)
|
|
37
|
+
lib/rbs/wasm/*.wasm
|
|
38
|
+
lib/rbs/wasm/jars/
|
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,110 @@ 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 and jars by default (see
|
|
631
|
+
# RBS::WASM::Runtime). These are build artifacts, bundled into the JRuby gem.
|
|
632
|
+
JRUBY_WASM_DIR = File.expand_path("lib/rbs/wasm", __dir__)
|
|
633
|
+
CHICORY_VERSION = ENV.fetch("CHICORY_VERSION", "1.7.5")
|
|
634
|
+
# `compiler` is Chicory's AOT compiler (wasm -> JVM bytecode); the asm* jars
|
|
635
|
+
# are the ow2 ASM libraries it depends on. Keep ASM_VERSION in sync with what
|
|
636
|
+
# the pinned Chicory release declares.
|
|
637
|
+
CHICORY_JARS = %w[wasm runtime log wasi compiler].freeze
|
|
638
|
+
ASM_VERSION = ENV.fetch("ASM_VERSION", "9.9.1")
|
|
639
|
+
ASM_JARS = %w[asm asm-tree asm-util asm-commons asm-analysis].freeze
|
|
640
|
+
|
|
641
|
+
desc "Download the Chicory and ASM jars the JRuby runtime needs into lib/rbs/wasm/jars"
|
|
642
|
+
task :vendor_jars do
|
|
643
|
+
require "open-uri"
|
|
644
|
+
require "fileutils"
|
|
645
|
+
|
|
646
|
+
jars_dir = File.join(JRUBY_WASM_DIR, "jars")
|
|
647
|
+
FileUtils.mkdir_p(jars_dir)
|
|
648
|
+
|
|
649
|
+
downloads = CHICORY_JARS.map { |name| ["#{name}.jar", "https://repo1.maven.org/maven2/com/dylibso/chicory/#{name}/#{CHICORY_VERSION}/#{name}-#{CHICORY_VERSION}.jar"] }
|
|
650
|
+
downloads += ASM_JARS.map { |name| ["#{name}.jar", "https://repo1.maven.org/maven2/org/ow2/asm/#{name}/#{ASM_VERSION}/#{name}-#{ASM_VERSION}.jar"] }
|
|
651
|
+
|
|
652
|
+
downloads.each do |filename, url|
|
|
653
|
+
puts "Downloading #{url}"
|
|
654
|
+
URI.open(url) { |io| File.binwrite(File.join(jars_dir, filename), io.read) } # steep:ignore
|
|
655
|
+
end
|
|
656
|
+
|
|
657
|
+
puts "Vendored Chicory #{CHICORY_VERSION} + ASM #{ASM_VERSION} into #{jars_dir}"
|
|
658
|
+
end
|
|
659
|
+
|
|
660
|
+
desc "Assemble everything the JRuby gem needs: the .wasm and the Chicory jars"
|
|
661
|
+
task :jruby_setup => [:build, :vendor_jars] do
|
|
662
|
+
cp WASM_OUTPUT, File.join(JRUBY_WASM_DIR, "rbs_parser.wasm")
|
|
663
|
+
puts "JRuby runtime is ready under #{JRUBY_WASM_DIR}"
|
|
664
|
+
end
|
|
665
|
+
end
|
|
666
|
+
|
|
552
667
|
namespace :rust do
|
|
553
668
|
namespace :rbs do
|
|
554
669
|
RUST_DIR = File.expand_path("rust", __dir__)
|
data/Steepfile
CHANGED
|
@@ -6,6 +6,13 @@ 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",
|
|
9
16
|
)
|
|
10
17
|
|
|
11
18
|
library "pathname", "json", "logger", "monitor", "tsort", "uri", 'dbm', 'pstore', 'singleton', 'shellwords', 'fileutils', 'find', 'digest', 'prettyprint', 'yaml', "psych", "securerandom"
|