Skip to content

Commit 9f3fed3

Browse files
Introduce rbs-based type check
1 parent 3e57dde commit 9f3fed3

File tree

7 files changed

+300
-16
lines changed

7 files changed

+300
-16
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ group :development do
66
gem "rake"
77
gem "syntax_tree", "~> 3.5"
88
gem "webrick"
9+
gem "steep"
910
end

Steepfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
D = Steep::Diagnostic
2+
3+
target :lib do
4+
signature "sig"
5+
6+
check "lib"
7+
# RBS's stdlib signatures don't have rake signatures yet.
8+
ignore "lib/ruby_wasm/rake_task.rb"
9+
10+
library "digest"
11+
library "tmpdir"
12+
library "fileutils"
13+
library "open-uri"
14+
library "uri"
15+
16+
configure_code_diagnostics(D::Ruby.default)
17+
end

lib/ruby_wasm/build/product/crossruby.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,11 @@ def configure_args(build_triple, toolchain)
250250
case target
251251
when "wasm32-unknown-wasi"
252252
xldflags << @wasi_vfs.lib_wasi_vfs_a if @wasi_vfs
253-
args << %Q(WASMOPT=#{@toolchain.wasm_opt})
254-
args << %Q(WASI_SDK_PATH=#{@toolchain.wasi_sdk_path})
253+
# TODO: Find a way to force cast or update API
254+
# @type var wasi_sdk_path: untyped
255+
wasi_sdk_path = @toolchain
256+
args << %Q(WASMOPT=#{wasi_sdk_path.wasm_opt})
257+
args << %Q(WASI_SDK_PATH=#{wasi_sdk_path.wasi_sdk_path})
255258
when "wasm32-unknown-emscripten"
256259
ldflags.concat(%w[-s MODULARIZE=1])
257260
else

lib/ruby_wasm/build/product/wasi_vfs.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ class WasiVfsProduct < BuildProduct
77
def initialize(build_dir)
88
@build_dir = build_dir
99
@need_fetch_lib = ENV["LIB_WASI_VFS_A"].nil?
10-
@cli_path = ENV["WASI_VFS_CLI"] || Toolchain.find_path("wasi-vfs")
10+
@cli_path =
11+
ENV["WASI_VFS_CLI"] || Toolchain.find_path("wasi-vfs") ||
12+
File.join(cli_product_build_dir, "wasi-vfs")
1113
@need_fetch_cli = @cli_path.nil?
12-
@cli_path ||= File.join(cli_product_build_dir, "wasi-vfs")
1314
end
1415

1516
def lib_product_build_dir
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module RubyWasm
2-
class WitBindgen < ::Rake::TaskLib
2+
class WitBindgen
33
attr_reader :bin_path
44

55
def initialize(
@@ -15,17 +15,17 @@ def initialize(
1515
def install
1616
return if File.exist?(@bin_path)
1717
RubyWasm::Toolchain.check_executable("cargo")
18-
system *[
19-
"cargo",
20-
"install",
21-
"--git",
22-
"https://github.com/bytecodealliance/wit-bindgen",
23-
"--rev",
24-
@revision,
25-
"--root",
26-
@tool_dir,
27-
"wit-bindgen-cli"
28-
]
18+
Kernel.system(
19+
"cargo",
20+
"install",
21+
"--git",
22+
"https://github.com/bytecodealliance/wit-bindgen",
23+
"--rev",
24+
@revision,
25+
"--root",
26+
@tool_dir,
27+
"wit-bindgen-cli"
28+
)
2929
end
3030
end
3131
end

sig/open_uri.rbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# TODO: Upstream OpenURI sigs to rbs/stdlib
2+
module OpenURI
3+
def self.open_uri: [T] (*untyped, **untyped) { (untyped) -> T } -> T
4+
end

sig/ruby_wasm/build.rbs

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
module RubyWasm
2+
VERSION: String
3+
4+
class BuildParams < Struct[untyped]
5+
attr_accessor name(): String
6+
attr_accessor target(): String
7+
attr_accessor default_exts(): String
8+
end
9+
10+
class BuildProduct
11+
def name: -> String
12+
end
13+
14+
class AutoconfProduct < BuildProduct
15+
@target: String
16+
@toolchain: Emscripten | WASISDK
17+
18+
def initialize: (String target, Emscripten | WASISDK toolchain) -> void
19+
def system_triplet_args: -> Array[String]
20+
| -> Array[String]
21+
def tools_args: -> Array[String]
22+
| -> Array[String]
23+
def configure_args: -> Array[String]
24+
| -> Array[String]
25+
end
26+
27+
class BuildSource < BuildProduct
28+
@params: Hash[untyped, untyped]
29+
@build_dir: String
30+
31+
def initialize: (untyped params, String build_dir) -> void
32+
def name: -> String
33+
def cache_key: (Digest::SHA256 digest) -> Digest::SHA256
34+
def src_dir: -> String
35+
def configure_file: -> String
36+
def fetch: (BuildExecutor executor) -> Array[untyped]
37+
def build: (BuildExecutor executor) -> void
38+
end
39+
40+
class BaseRubyProduct < BuildProduct
41+
@build_dir: String
42+
@source: BuildSource
43+
@channel: untyped
44+
45+
def initialize: (String build_dir, BuildSource source) -> void
46+
def product_build_dir: -> String
47+
def install_dir: -> String
48+
def name: -> String
49+
def build: (BuildExecutor executor) -> void
50+
end
51+
52+
class ZlibProduct < AutoconfProduct
53+
ZLIB_VERSION: String
54+
@build_dir: String
55+
56+
attr_reader target: String
57+
def initialize: (String build_dir, untyped target, Emscripten | WASISDK toolchain) -> void
58+
def product_build_dir: -> String
59+
def destdir: -> String
60+
def install_root: -> String
61+
def name: -> String
62+
def configure_args: -> Array[String]
63+
def build: (BuildExecutor executor) -> void
64+
end
65+
66+
class LibYAMLProduct < AutoconfProduct
67+
LIBYAML_VERSION: String
68+
@build_dir: String
69+
70+
attr_reader target: String
71+
def initialize: (String build_dir, untyped target, Emscripten | WASISDK toolchain) -> void
72+
def product_build_dir: -> String
73+
def destdir: -> String
74+
def install_root: -> String
75+
def name: -> String
76+
def build: (BuildExecutor executor) -> void
77+
end
78+
79+
class OpenSSLProduct < AutoconfProduct
80+
OPENSSL_VERSION: String
81+
@build_dir: String
82+
83+
attr_reader target: String
84+
attr_reader install_task: untyped
85+
def initialize: (String build_dir, untyped target, Emscripten | WASISDK toolchain) -> void
86+
def product_build_dir: -> String
87+
def destdir: -> String
88+
def install_root: -> String
89+
def name: -> String
90+
def configure_args: -> Array[String]
91+
def build: (BuildExecutor executor) -> void
92+
end
93+
94+
class WasiVfsProduct < BuildProduct
95+
WASI_VFS_VERSION: String
96+
@build_dir: String
97+
@need_fetch_lib: bool
98+
@cli_path: String
99+
@need_fetch_cli: bool
100+
101+
def initialize: (String build_dir) -> void
102+
def lib_product_build_dir: -> String
103+
def lib_wasi_vfs_a: -> String
104+
def cli_product_build_dir: -> String
105+
def cli_bin_path: -> String
106+
def name: -> String
107+
def build: (BuildExecutor executor) -> void
108+
def install_cli: -> bool?
109+
def cli_download_url: -> String
110+
end
111+
112+
class CrossRubyExtProduct < BuildProduct
113+
@toolchain: untyped
114+
@srcdir: untyped
115+
116+
attr_reader name: String
117+
def initialize: (untyped srcdir, untyped toolchain, ?name: nil) -> void
118+
def product_build_dir: (untyped crossruby) -> String
119+
def linklist: (untyped crossruby) -> String
120+
def make_args: (untyped crossruby) -> Array[String]
121+
def build: (BuildExecutor executor, untyped crossruby) -> void
122+
def do_extconf: (BuildExecutor executor, untyped crossruby) -> untyped
123+
def do_install_rb: (BuildExecutor executor, untyped crossruby) -> untyped
124+
def cache_key: (untyped digest) -> Array[String]
125+
end
126+
127+
class CrossRubyProduct < AutoconfProduct
128+
@params: BuildParams
129+
@rubies_dir: String
130+
@build_dir: String
131+
@baseruby: BaseRubyProduct
132+
@libyaml: LibYAMLProduct
133+
@zlib: ZlibProduct
134+
@openssl: OpenSSLProduct
135+
@wasi_vfs: WasiVfsProduct
136+
137+
attr_reader source: BuildSource
138+
attr_reader toolchain: Emscripten | WASISDK
139+
attr_accessor user_exts: Array[CrossRubyExtProduct]
140+
attr_accessor wasmoptflags: Array[String]
141+
attr_accessor cppflags: Array[String]
142+
attr_accessor cflags: Array[String]
143+
attr_accessor ldflags: Array[String]
144+
attr_accessor debugflags: Array[String]
145+
attr_accessor xcflags: Array[String]
146+
attr_accessor xldflags: Array[String]
147+
def initialize: (BuildParams params, String build_dir, String rubies_dir, BaseRubyProduct baseruby, BuildSource source, Emscripten | WASISDK toolchain, ?user_exts: Array[untyped]) -> void
148+
def configure: (BuildExecutor executor, ?reconfigure: bool) -> untyped
149+
def build_exts: (BuildExecutor executor) -> bool?
150+
def build: (BuildExecutor executor, ?remake: bool, ?reconfigure: bool) -> bool?
151+
def clean: (BuildExecutor executor) -> void
152+
def name: -> String
153+
def cache_key: (Digest::SHA256 digest) -> Array[untyped]
154+
def build_dir: -> String
155+
def ext_build_dir: -> String
156+
def with_libyaml: (LibYAMLProduct libyaml) -> LibYAMLProduct
157+
def with_zlib: (ZlibProduct zlib) -> ZlibProduct
158+
def with_wasi_vfs: (WasiVfsProduct wasi_vfs) -> WasiVfsProduct
159+
def with_openssl: (OpenSSLProduct openssl) -> OpenSSLProduct
160+
def dest_dir: -> String
161+
def artifact: -> String
162+
def extinit_obj: -> String
163+
def extinit_c_erb: -> String
164+
def baseruby_path: -> String
165+
def configure_args: (String build_triple, Emscripten | WASISDK toolchain) -> Array[String]
166+
end
167+
168+
class WitBindgen
169+
@build_dir: untyped
170+
@tool_dir: String
171+
@revision: String
172+
173+
attr_reader bin_path: String
174+
def initialize: (build_dir: untyped, ?revision: String) -> void
175+
def install: -> void
176+
end
177+
178+
class Toolchain
179+
@tools: Hash[untyped, untyped]
180+
@tools_cache: Hash[untyped, untyped]
181+
182+
attr_reader name: String
183+
def initialize: -> void
184+
def find_tool: (Symbol name) -> bot
185+
def check_envvar: (untyped name) -> nil
186+
def self.get: (untyped target, ?String? build_dir) -> (Emscripten | WASISDK)
187+
def self.find_path: (String command) -> String?
188+
def self.check_executable: (String command) -> String
189+
def cc: -> nil
190+
def ranlib: -> nil
191+
def ld: -> nil
192+
def ar: -> nil
193+
end
194+
195+
class WASISDK < Toolchain
196+
@wasm_opt_path: String
197+
@need_fetch_wasi_sdk: bool
198+
@need_fetch_binaryen: bool
199+
@tools: Hash[Symbol, String]
200+
@wasi_sdk_path: String
201+
@binaryen_version: Integer
202+
@version_major: Integer
203+
@version_minor: Integer
204+
@binaryen_path: String
205+
206+
def initialize: (?String? wasi_sdk_path, ?build_dir: String?, ?version_major: Integer, ?version_minor: Integer, ?binaryen_version: Integer) -> void
207+
def find_tool: (Symbol name) -> String
208+
def wasm_opt: -> String
209+
def wasi_sdk_path: -> String
210+
def download_url: (Integer? version_major, Integer? version_minor) -> String
211+
def binaryen_download_url: (Integer? version) -> String
212+
def install_wasi_sdk: -> void
213+
def install_binaryen: -> void
214+
def install: -> void
215+
end
216+
217+
class Emscripten < Toolchain
218+
@tools: Hash[Symbol, String]
219+
220+
def initialize: -> void
221+
def install: -> nil
222+
def find_tool: (Symbol name) -> String
223+
end
224+
225+
class BuildExecutor
226+
def system: (*untyped, **untyped) -> bool?
227+
def rm_rf: (FileUtils::pathlist list) -> void
228+
def rm_f: (FileUtils::pathlist list) -> void
229+
def cp_r: (FileUtils::pathlist src, path dest) -> void
230+
def mv: (FileUtils::pathlist src, path dest) -> void
231+
def mkdir_p: (FileUtils::pathlist list) -> void
232+
def write: (String path, _ToS data) -> void
233+
end
234+
235+
class Downloader
236+
def format_size: (untyped size) -> untyped
237+
238+
def download: (untyped url, untyped dest, untyped message) -> untyped
239+
end
240+
241+
class BuildTask
242+
@build_dir: String
243+
@rubies_dir: String
244+
@openssl: OpenSSLProduct
245+
246+
attr_accessor name: untyped
247+
attr_reader source: BuildSource
248+
attr_reader target: untyped
249+
attr_reader toolchain: Emscripten | WASISDK
250+
attr_reader libyaml: LibYAMLProduct
251+
attr_reader zlib: ZlibProduct
252+
attr_reader wasi_vfs: WasiVfsProduct
253+
attr_reader baseruby: BaseRubyProduct
254+
attr_reader crossruby: CrossRubyProduct
255+
def initialize: (untyped name, target: untyped, src: untyped, ?toolchain: nil, ?build_dir: nil, ?rubies_dir: nil, **untyped) -> void
256+
def hexdigest: -> String
257+
end
258+
end

0 commit comments

Comments
 (0)