Skip to content

Commit d5c7482

Browse files
Merge pull request #308 from ruby/pr-83d6a25e8fc9b4178f125b1878fecc2fb96d1117
Introduce rbs-based type check
2 parents 3e57dde + 26b798a commit d5c7482

File tree

9 files changed

+303
-19
lines changed

9 files changed

+303
-19
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/downloader.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def format_size(size)
1212

1313
def download(url, dest, message)
1414
require "open-uri"
15-
content_length = nil
15+
content_length = 0
1616
uri = URI.parse(url)
1717
OpenURI.open_uri(
1818
uri,

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/openssl.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
module RubyWasm
55
class OpenSSLProduct < AutoconfProduct
6-
attr_reader :target, :install_task
6+
attr_reader :target
77

88
OPENSSL_VERSION = "3.0.5"
99

lib/ruby_wasm/build/product/wasi_vfs.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ 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")
11-
@need_fetch_cli = @cli_path.nil?
12-
@cli_path ||= File.join(cli_product_build_dir, "wasi-vfs")
10+
installed_cli_path =
11+
ENV["WASI_VFS_CLI"] || Toolchain.find_path("wasi-vfs")
12+
@need_fetch_cli = installed_cli_path.nil?
13+
@cli_path =
14+
installed_cli_path || File.join(cli_product_build_dir, "wasi-vfs")
1315
end
1416

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

0 commit comments

Comments
 (0)