Skip to content

Commit f45d018

Browse files
rake format
1 parent b7ff15d commit f45d018

File tree

4 files changed

+114
-70
lines changed

4 files changed

+114
-70
lines changed

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ NPM_PACKAGES = [
2929
name: "ruby-head-wasm-wasi",
3030
ruby_version: "head",
3131
gemfile: "packages/npm-packages/ruby-head-wasm-wasi/Gemfile",
32-
target: "wasm32-unknown-wasip1",
32+
target: "wasm32-unknown-wasip1"
3333
},
3434
{
3535
name: "ruby-head-wasm-wasip2",
3636
ruby_version: "head",
3737
gemfile: "packages/npm-packages/ruby-head-wasm-wasip2/Gemfile",
3838
target: "wasm32-unknown-wasip2",
39-
enable_component_model: true,
39+
enable_component_model: true
4040
},
4141
{
4242
name: "ruby-3.4-wasm-wasi",

lib/ruby_wasm/build/executor.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,7 @@ def system(*args, chdir: nil, env: nil)
152152
kwargs = {}
153153
kwargs[:chdir] = chdir if chdir
154154
kwargs[:exception] = true
155-
if env
156-
Kernel.system(env, *args, **kwargs)
157-
else
158-
Kernel.system(*args, **kwargs)
159-
end
155+
env ? Kernel.system(env, *args, **kwargs) : Kernel.system(*args, **kwargs)
160156
end
161157
end
162158

lib/ruby_wasm/build/toolchain.rb

Lines changed: 78 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ def check_envvar(name)
1919
def self.get(target, options, build_dir = nil)
2020
case target
2121
when /^wasm32-unknown-wasi/
22-
return RubyWasm::WASISDK.new(build_dir: build_dir, version: options[:wasi_sdk_version])
22+
return(
23+
RubyWasm::WASISDK.new(
24+
build_dir: build_dir,
25+
version: options[:wasi_sdk_version]
26+
)
27+
)
2328
when "wasm32-unknown-emscripten"
2429
return RubyWasm::Emscripten.new
2530
else
@@ -71,7 +76,8 @@ def initialize(
7176
@version = version
7277
end
7378

74-
@binaryen = Binaryen.new(build_dir: build_dir, binaryen_version: binaryen_version)
79+
@binaryen =
80+
Binaryen.new(build_dir: build_dir, binaryen_version: binaryen_version)
7581

7682
@tools = {
7783
cc: "#{wasi_sdk_path}/bin/clang",
@@ -103,44 +109,55 @@ def download_url
103109
major, _ = @version.split(".").map(&:to_i)
104110
# @type var assets: Array[[Regexp, Array[String]]]
105111
assets = [
106-
[/x86_64-linux/, [
107-
"wasi-sdk-#{@version}-x86_64-linux.tar.gz",
108-
# For wasi-sdk version < 23.0
109-
"wasi-sdk-#{@version}-linux.tar.gz",
110-
]],
111-
[/arm64e?-darwin/, [
112-
"wasi-sdk-#{@version}-arm64-macos.tar.gz",
113-
# For wasi-sdk version < 23.0
114-
"wasi-sdk-#{@version}-macos.tar.gz",
115-
]],
116-
[/x86_64-darwin/, [
117-
"wasi-sdk-#{@version}-x86_64-macos.tar.gz",
118-
# For wasi-sdk version < 23.0
119-
"wasi-sdk-#{@version}-macos.tar.gz",
120-
]],
112+
[
113+
/x86_64-linux/,
114+
[
115+
"wasi-sdk-#{@version}-x86_64-linux.tar.gz",
116+
# For wasi-sdk version < 23.0
117+
"wasi-sdk-#{@version}-linux.tar.gz"
118+
]
119+
],
120+
[
121+
/arm64e?-darwin/,
122+
[
123+
"wasi-sdk-#{@version}-arm64-macos.tar.gz",
124+
# For wasi-sdk version < 23.0
125+
"wasi-sdk-#{@version}-macos.tar.gz"
126+
]
127+
],
128+
[
129+
/x86_64-darwin/,
130+
[
131+
"wasi-sdk-#{@version}-x86_64-macos.tar.gz",
132+
# For wasi-sdk version < 23.0
133+
"wasi-sdk-#{@version}-macos.tar.gz"
134+
]
135+
]
121136
]
122-
asset = assets.find do |os, candidates|
123-
os =~ RUBY_PLATFORM
124-
end
137+
asset = assets.find { |os, candidates| os =~ RUBY_PLATFORM }
125138
if asset.nil?
126139
raise "unsupported platform for fetching WASI SDK: #{RUBY_PLATFORM}"
127140
end
128141
_, candidates = asset
129-
candidates_urls = candidates.map do |candidate|
130-
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-#{major}/#{candidate}"
131-
end
142+
candidates_urls =
143+
candidates.map do |candidate|
144+
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-#{major}/#{candidate}"
145+
end
132146
require "net/http"
133147
# Find an asset that exists by checking HEAD response to see if the asset exists
134148
candidates_urls.each do |url_str|
135149
# @type var url: URI::HTTPS
136150
url = URI.parse(url_str)
137-
ok = Net::HTTP.start(url.host, url.port, use_ssl: url.scheme == 'https') do |http|
138-
response = http.head(url.request_uri)
139-
next response.code == "302"
140-
end
141-
if ok
142-
return url_str
143-
end
151+
ok =
152+
Net::HTTP.start(
153+
url.host,
154+
url.port,
155+
use_ssl: url.scheme == "https"
156+
) do |http|
157+
response = http.head(url.request_uri)
158+
next response.code == "302"
159+
end
160+
return url_str if ok
144161
end
145162
raise "WASI SDK asset not found: #{candidates_urls.join(", ")}"
146163
end
@@ -151,11 +168,21 @@ def install_wasi_sdk(executor)
151168
File.join(File.dirname(@wasi_sdk_path), "wasi-sdk-#{@version}.tar.gz")
152169
unless File.exist? wasi_sdk_tarball
153170
FileUtils.mkdir_p File.dirname(wasi_sdk_tarball)
154-
executor.system "curl", "-fsSL", "-o", wasi_sdk_tarball, self.download_url
171+
executor.system "curl",
172+
"-fsSL",
173+
"-o",
174+
wasi_sdk_tarball,
175+
self.download_url
155176
end
156177
unless File.exist? @wasi_sdk_path
157178
FileUtils.mkdir_p @wasi_sdk_path
158-
executor.system "tar", "-C", @wasi_sdk_path, "--strip-component", "1", "-xzf", wasi_sdk_tarball
179+
executor.system "tar",
180+
"-C",
181+
@wasi_sdk_path,
182+
"--strip-component",
183+
"1",
184+
"-xzf",
185+
wasi_sdk_tarball
159186
end
160187
end
161188

@@ -218,20 +245,35 @@ def install(executor)
218245
binaryen_tarball = File.expand_path("../binaryen.tar.gz", @binaryen_path)
219246
unless File.exist? binaryen_tarball
220247
FileUtils.mkdir_p File.dirname(binaryen_tarball)
221-
executor.system "curl", "-L", "-o", binaryen_tarball, self.download_url(@binaryen_version)
248+
executor.system "curl",
249+
"-L",
250+
"-o",
251+
binaryen_tarball,
252+
self.download_url(@binaryen_version)
222253
end
223254

224255
unless File.exist? @binaryen_path
225256
FileUtils.mkdir_p @binaryen_path
226-
executor.system "tar", "-C", @binaryen_path, "--strip-component", "1", "-xzf", binaryen_tarball
257+
executor.system "tar",
258+
"-C",
259+
@binaryen_path,
260+
"--strip-component",
261+
"1",
262+
"-xzf",
263+
binaryen_tarball
227264
end
228265
end
229-
230266
end
231267

232268
class Emscripten < Toolchain
233269
def initialize
234-
@tools = { cc: "emcc", cxx: "em++", ld: "emcc", ar: "emar", ranlib: "emranlib" }
270+
@tools = {
271+
cc: "emcc",
272+
cxx: "em++",
273+
ld: "emcc",
274+
ar: "emar",
275+
ranlib: "emranlib"
276+
}
235277
@name = "emscripten"
236278
end
237279

lib/ruby_wasm/cli.rb

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,17 @@ def compute_build_alias(options)
214214
end
215215
# FIXME: We should have a way to specify extensions to be included by users.
216216
# For now, assume all default extensions available in the head revision are available.
217-
return {
218-
name: "local",
219-
src: {
220-
type: "local",
221-
path: src_name,
222-
patches: []
223-
},
224-
all_default_exts: RubyWasm::Packager::ALL_DEFAULT_EXTS,
225-
}
217+
return(
218+
{
219+
name: "local",
220+
src: {
221+
type: "local",
222+
path: src_name,
223+
patches: []
224+
},
225+
all_default_exts: RubyWasm::Packager::ALL_DEFAULT_EXTS
226+
}
227+
)
226228
end
227229
# Otherwise, it's an unknown source.
228230
raise(
@@ -243,52 +245,56 @@ def self.build_config_aliases(root)
243245
src: {
244246
type: "github",
245247
repo: "ruby/ruby",
246-
rev: "master",
248+
rev: "master"
247249
},
248250
all_default_exts: RubyWasm::Packager::ALL_DEFAULT_EXTS,
249-
wasi_sdk_version: "23.0",
251+
wasi_sdk_version: "23.0"
250252
},
251253
{
252254
name: "3.4",
253255
src: {
254256
type: "tarball",
255-
url: "https://cache.ruby-lang.org/pub/ruby/3.4/ruby-3.4.1.tar.gz",
257+
url: "https://cache.ruby-lang.org/pub/ruby/3.4/ruby-3.4.1.tar.gz"
256258
},
257-
all_default_exts: "cgi/escape,continuation,coverage,date,digest/bubblebabble,digest,digest/md5,digest/rmd160,digest/sha1,digest/sha2,etc,fcntl,json,json/generator,json/parser,objspace,pathname,psych,rbconfig/sizeof,ripper,stringio,strscan,monitor,zlib,openssl",
258-
wasi_sdk_version: "22.0",
259+
all_default_exts:
260+
"cgi/escape,continuation,coverage,date,digest/bubblebabble,digest,digest/md5,digest/rmd160,digest/sha1,digest/sha2,etc,fcntl,json,json/generator,json/parser,objspace,pathname,psych,rbconfig/sizeof,ripper,stringio,strscan,monitor,zlib,openssl",
261+
wasi_sdk_version: "22.0"
259262
},
260263
{
261264
name: "3.3",
262265
src: {
263266
type: "tarball",
264-
url: "https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.3.tar.gz",
267+
url: "https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.3.tar.gz"
265268
},
266-
all_default_exts: "bigdecimal,cgi/escape,continuation,coverage,date,dbm,digest/bubblebabble,digest,digest/md5,digest/rmd160,digest/sha1,digest/sha2,etc,fcntl,fiber,gdbm,json,json/generator,json/parser,nkf,objspace,pathname,psych,racc/cparse,rbconfig/sizeof,ripper,stringio,strscan,monitor,zlib,openssl",
267-
wasi_sdk_version: "22.0",
269+
all_default_exts:
270+
"bigdecimal,cgi/escape,continuation,coverage,date,dbm,digest/bubblebabble,digest,digest/md5,digest/rmd160,digest/sha1,digest/sha2,etc,fcntl,fiber,gdbm,json,json/generator,json/parser,nkf,objspace,pathname,psych,racc/cparse,rbconfig/sizeof,ripper,stringio,strscan,monitor,zlib,openssl",
271+
wasi_sdk_version: "22.0"
268272
},
269273
{
270274
name: "3.2",
271275
src: {
272276
type: "tarball",
273-
url: "https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.4.tar.gz",
277+
url: "https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.4.tar.gz"
274278
},
275-
all_default_exts: "bigdecimal,cgi/escape,continuation,coverage,date,dbm,digest/bubblebabble,digest,digest/md5,digest/rmd160,digest/sha1,digest/sha2,etc,fcntl,fiber,gdbm,json,json/generator,json/parser,nkf,objspace,pathname,psych,racc/cparse,rbconfig/sizeof,ripper,stringio,strscan,monitor,zlib,openssl",
276-
wasi_sdk_version: "22.0",
279+
all_default_exts:
280+
"bigdecimal,cgi/escape,continuation,coverage,date,dbm,digest/bubblebabble,digest,digest/md5,digest/rmd160,digest/sha1,digest/sha2,etc,fcntl,fiber,gdbm,json,json/generator,json/parser,nkf,objspace,pathname,psych,racc/cparse,rbconfig/sizeof,ripper,stringio,strscan,monitor,zlib,openssl",
281+
wasi_sdk_version: "22.0"
277282
}
278283
]
279284

280285
# Set the name in the source config.
281-
aliases.each do |config|
282-
config[:src][:name] = config[:name]
283-
end
286+
aliases.each { |config| config[:src][:name] = config[:name] }
284287

285288
# Apply bundled and user-specified `<root>/patches` directories.
286289
aliases.each do |config|
287290
patches_dirs = [bundled_patches_path, File.join(root, "patches")]
288-
config[:src][:patches] = patches_dirs.flat_map do |patches_dir|
289-
Dir[File.join(patches_dir, config[:name], "*.patch")]
290-
.map { |p| File.expand_path(p) }
291-
end.uniq
291+
config[:src][:patches] = patches_dirs
292+
.flat_map do |patches_dir|
293+
Dir[File.join(patches_dir, config[:name], "*.patch")].map do |p|
294+
File.expand_path(p)
295+
end
296+
end
297+
.uniq
292298
end
293299

294300
# Pin the revisions based on build_manifest.json if available.

0 commit comments

Comments
 (0)