Skip to content

Commit 0ae81e4

Browse files
rake format
tasks/*.rake are added to formatting targets
1 parent 6b68258 commit 0ae81e4

File tree

7 files changed

+126
-98
lines changed

7 files changed

+126
-98
lines changed

Rakefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ BUILDS =
9292
# Skip builds with JS extensions or debug mode for Emscripten
9393
# because JS extensions have incompatible import/export entries
9494
# and debug mode is rarely used for Emscripten.
95-
next !(user_exts.include?("witapi") || user_exts.include?("js") || profile[:debug])
95+
next(
96+
!(
97+
user_exts.include?("witapi") || user_exts.include?("js") ||
98+
profile[:debug]
99+
)
100+
)
96101
end
97102
next true
98103
end

lib/ruby_wasm/build_system/product/crossruby.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ def do_install_rb(crossruby)
7676
def cache_key(digest)
7777
digest << @name
7878
# Compute hash value of files under srcdir
79-
Dir.glob("#{@srcdir}/**/*", File::FNM_DOTMATCH).each do |f|
80-
next if File.directory?(f)
81-
digest << f
82-
digest << File.read(f)
83-
end
79+
Dir
80+
.glob("#{@srcdir}/**/*", File::FNM_DOTMATCH)
81+
.each do |f|
82+
next if File.directory?(f)
83+
digest << f
84+
digest << File.read(f)
85+
end
8486
end
8587
end
8688

@@ -171,14 +173,14 @@ def name
171173
def cache_key(digest)
172174
digest << @params.target
173175
digest << @params.default_exts
174-
@wasmoptflags.each{|f| digest << f }
175-
@cppflags.each{|f| digest << f }
176-
@cflags.each{|f| digest << f }
177-
@ldflags.each{|f| digest << f }
178-
@debugflags.each{|f| digest << f }
179-
@xcflags.each{|f| digest << f }
180-
@xldflags.each{|f| digest << f }
181-
@user_exts.each{|ext| ext.cache_key(digest) }
176+
@wasmoptflags.each { |f| digest << f }
177+
@cppflags.each { |f| digest << f }
178+
@cflags.each { |f| digest << f }
179+
@ldflags.each { |f| digest << f }
180+
@debugflags.each { |f| digest << f }
181+
@xcflags.each { |f| digest << f }
182+
@xldflags.each { |f| digest << f }
183+
@user_exts.each { |ext| ext.cache_key(digest) }
182184
end
183185

184186
def build_dir

tasks/check.rake

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,31 @@ namespace :check do
33
task :install_wit_bindgen do
44
wit_bindgen.install
55
end
6-
task :bindgen_c => :install_wit_bindgen do
6+
task bindgen_c: :install_wit_bindgen do
77
wits = [
8-
["ext/witapi/bindgen/rb-abi-guest.wit", "--export"],
9-
["ext/js/bindgen/rb-js-abi-host.wit", "--import"],
8+
%w[ext/witapi/bindgen/rb-abi-guest.wit --export],
9+
%w[ext/js/bindgen/rb-js-abi-host.wit --import]
1010
]
1111
wits.each do |wit|
1212
path, mode = wit
1313
sh "#{wit_bindgen.bin_path} guest c #{mode} #{path} --out-dir #{File.dirname(path)}"
1414
end
1515
end
1616

17-
task :bindgen_js => :install_wit_bindgen do
17+
task bindgen_js: :install_wit_bindgen do
1818
sh *[
19-
wit_bindgen.bin_path, "host", "js",
20-
"--import", "ext/witapi/bindgen/rb-abi-guest.wit",
21-
"--export", "ext/js/bindgen/rb-js-abi-host.wit",
22-
"--out-dir", "packages/npm-packages/ruby-wasm-wasi/src/bindgen",
23-
]
19+
wit_bindgen.bin_path,
20+
"host",
21+
"js",
22+
"--import",
23+
"ext/witapi/bindgen/rb-abi-guest.wit",
24+
"--export",
25+
"ext/js/bindgen/rb-js-abi-host.wit",
26+
"--out-dir",
27+
"packages/npm-packages/ruby-wasm-wasi/src/bindgen"
28+
]
2429
end
2530

2631
desc "Check wit-bindgen'ed sources are up-to-date"
27-
task :bindgen => [:bindgen_c, :bindgen_js]
32+
task bindgen: %i[bindgen_c bindgen_js]
2833
end

tasks/ci.rake

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,66 @@
11
def latest_build_sources
2-
BUILD_SOURCES.map do |name, src|
3-
case src[:type]
4-
when "github"
5-
url = "https://api.github.com/repos/#{src[:repo]}/commits/#{src[:rev]}"
6-
revision = OpenURI.open_uri(url) { |f| JSON.load(f.read) }
7-
[name, revision["sha"]]
8-
else
9-
raise "#{src[:type]} is not supported to pin source revision"
2+
BUILD_SOURCES
3+
.map do |name, src|
4+
case src[:type]
5+
when "github"
6+
url = "https://api.github.com/repos/#{src[:repo]}/commits/#{src[:rev]}"
7+
revision = OpenURI.open_uri(url) { |f| JSON.load(f.read) }
8+
[name, revision["sha"]]
9+
else
10+
raise "#{src[:type]} is not supported to pin source revision"
11+
end
1012
end
11-
end.to_h
13+
.to_h
1214
end
1315
namespace :ci do
1416
task :rake_task_matrix do
1517
require "pathname"
1618
ruby_cache_keys = {}
17-
BUILD_TASKS.each do |build|
18-
ruby_cache_keys[build.name] = build.hexdigest
19-
end
20-
entries = BUILD_TASKS.map do |build|
21-
{
22-
task: "build:#{build.name}",
23-
artifact: Pathname.new(build.crossruby.artifact).relative_path_from(LIB_ROOT).to_s,
24-
artifact_name: File.basename(build.crossruby.artifact, ".tar.gz"),
25-
builder: build.target,
26-
rubies_cache_key: ruby_cache_keys[build.name],
27-
}
28-
end
29-
entries += NPM_PACKAGES.map do |pkg|
30-
entry = {
31-
task: "npm:#{pkg[:name]}",
32-
prerelease: "npm:configure_prerelease",
33-
artifact: "packages/npm-packages/#{pkg[:name]}/#{pkg[:name]}-*.tgz",
34-
artifact_name: "npm-#{pkg[:name]}",
35-
builder: pkg[:target],
36-
rubies_cache_key: ruby_cache_keys[pkg[:build]],
37-
}
38-
# Run tests only if the package has 'test' script
39-
package_json = JSON.parse(File.read("packages/npm-packages/#{pkg[:name]}/package.json"))
40-
if package_json["scripts"] && package_json["scripts"]["test"]
41-
entry[:test] = "npm:#{pkg[:name]}-check"
19+
BUILD_TASKS.each { |build| ruby_cache_keys[build.name] = build.hexdigest }
20+
entries =
21+
BUILD_TASKS.map do |build|
22+
{
23+
task: "build:#{build.name}",
24+
artifact:
25+
Pathname
26+
.new(build.crossruby.artifact)
27+
.relative_path_from(LIB_ROOT)
28+
.to_s,
29+
artifact_name: File.basename(build.crossruby.artifact, ".tar.gz"),
30+
builder: build.target,
31+
rubies_cache_key: ruby_cache_keys[build.name]
32+
}
33+
end
34+
entries +=
35+
NPM_PACKAGES.map do |pkg|
36+
entry = {
37+
task: "npm:#{pkg[:name]}",
38+
prerelease: "npm:configure_prerelease",
39+
artifact: "packages/npm-packages/#{pkg[:name]}/#{pkg[:name]}-*.tgz",
40+
artifact_name: "npm-#{pkg[:name]}",
41+
builder: pkg[:target],
42+
rubies_cache_key: ruby_cache_keys[pkg[:build]]
43+
}
44+
# Run tests only if the package has 'test' script
45+
package_json =
46+
JSON.parse(
47+
File.read("packages/npm-packages/#{pkg[:name]}/package.json")
48+
)
49+
if package_json["scripts"] && package_json["scripts"]["test"]
50+
entry[:test] = "npm:#{pkg[:name]}-check"
51+
end
52+
entry
53+
end
54+
entries +=
55+
WAPM_PACKAGES.map do |pkg|
56+
{
57+
task: "wapm:#{pkg[:name]}-build",
58+
artifact: "packages/wapm-packages/#{pkg[:name]}/dist",
59+
artifact_name: "wapm-#{pkg[:name]}",
60+
builder: "wasm32-unknown-wasi",
61+
rubies_cache_key: ruby_cache_keys[pkg[:build]]
62+
}
4263
end
43-
entry
44-
end
45-
entries += WAPM_PACKAGES.map do |pkg|
46-
{
47-
task: "wapm:#{pkg[:name]}-build",
48-
artifact: "packages/wapm-packages/#{pkg[:name]}/dist",
49-
artifact_name: "wapm-#{pkg[:name]}",
50-
builder: "wasm32-unknown-wasi",
51-
rubies_cache_key: ruby_cache_keys[pkg[:build]],
52-
}
53-
end
5464
print JSON.generate(entries)
5565
end
5666

tasks/doc.rake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
require 'rdoc/task'
2-
require 'ruby_wasm/version'
1+
require "rdoc/task"
2+
require "ruby_wasm/version"
33

44
RDoc::Task.new do |doc|
5-
doc.main = 'README.md'
5+
doc.main = "README.md"
66
doc.title = "ruby.wasm #{RubyWasm::VERSION} Documentation"
77
doc.rdoc_files = FileList.new %w[*.md lib/**/*.rb ext/**/*.c ext/**/*.rb]
88
end

tasks/format.rake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ namespace :format do
77
"Rakefile",
88
"lib/**/*.rb",
99
"ext/**/*.rb",
10-
"tasks/**/*.rb",
11-
"packages/**/*.rb",
12-
],
10+
"tasks/**/*.rake",
11+
"packages/**/*.rb"
12+
]
1313
)
1414
rescue LoadError
1515
end

tasks/packaging.rake

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ wasi_vfs = RubyWasm::WasiVfsProduct.new(File.join(Dir.pwd, "build"))
22
wasi_sdk = TOOLCHAINS["wasi-sdk"]
33
tools = {
44
"WASI_VFS_CLI" => wasi_vfs.cli_bin_path,
5-
"WASMOPT" => wasi_sdk.wasm_opt,
5+
"WASMOPT" => wasi_sdk.wasm_opt
66
}
77

88
namespace :npm do
@@ -39,7 +39,7 @@ namespace :npm do
3939
end
4040

4141
desc "Bump version"
42-
task :bump_version, [:package, :version] do |t, args|
42+
task :bump_version, %i[package version] do |t, args|
4343
require "json"
4444
package = args[:package] or raise "package name is required"
4545
version = args[:version] or raise "version is required"
@@ -54,17 +54,20 @@ namespace :npm do
5454
# Update package-lock.json
5555
Dir.chdir(pkg_dir) { sh "npm install" }
5656
# Update README.md and other docs
57-
%x(git grep -l #{pkg_name}@#{old_version}).split.each do |file|
57+
`git grep -l #{pkg_name}@#{old_version}`.split.each do |file|
5858
content = File.read(file)
5959
next_nightly = Date.today.strftime("%Y-%m-%d")
60-
content.gsub!(/#{pkg_name}@#{old_version}-\d{4}-\d{2}-\d{2}-a/, "#{pkg_name}@#{version}-#{next_nightly}-a")
60+
content.gsub!(
61+
/#{pkg_name}@#{old_version}-\d{4}-\d{2}-\d{2}-a/,
62+
"#{pkg_name}@#{version}-#{next_nightly}-a"
63+
)
6164
content.gsub!(/#{pkg_name}@#{old_version}/, "#{pkg_name}@#{version}")
6265
File.write(file, content)
6366
end
6467
end
6568

6669
desc "Build all npm packages"
67-
multitask :all => NPM_PACKAGES.map { |pkg| pkg[:name] }
70+
multitask all: NPM_PACKAGES.map { |pkg| pkg[:name] }
6871
end
6972

7073
namespace :wapm do
@@ -76,7 +79,9 @@ namespace :wapm do
7679
wasi_vfs.install_cli
7780
wasi_sdk.install_binaryen
7881
base_dir = Dir.pwd
79-
sh tools, "./build-package.sh #{base_dir}/rubies/#{pkg[:build]}", chdir: pkg_dir
82+
sh tools,
83+
"./build-package.sh #{base_dir}/rubies/#{pkg[:build]}",
84+
chdir: pkg_dir
8085
end
8186

8287
desc "Publish wapm package #{pkg[:name]}"
@@ -87,10 +92,10 @@ namespace :wapm do
8792
end
8893
end
8994

90-
NPM_RELEASE_ARTIFACTS = [
91-
"npm-ruby-head-wasm-emscripten",
92-
"npm-ruby-head-wasm-wasi",
93-
"npm-ruby-3_2-wasm-wasi",
95+
NPM_RELEASE_ARTIFACTS = %w[
96+
npm-ruby-head-wasm-emscripten
97+
npm-ruby-head-wasm-wasi
98+
npm-ruby-3_2-wasm-wasi
9499
]
95100
RELASE_ARTIFACTS =
96101
BUILD_TASKS.map do |build|
@@ -106,11 +111,11 @@ EOS
106111
BUILD_SOURCES.each do |name, source|
107112
case source[:type]
108113
when "github"
109-
url = "https://api.github.com/repos/#{source[:repo]}/commits/#{source[:rev]}"
110-
commit = OpenURI.open_uri(url) do |f|
111-
JSON.load(f.read)
112-
end
113-
output += "| #{name} | [`#{source[:repo]}@#{commit["sha"]}`](https://github.com/ruby/ruby/tree/#{commit["sha"]}) |\n"
114+
url =
115+
"https://api.github.com/repos/#{source[:repo]}/commits/#{source[:rev]}"
116+
commit = OpenURI.open_uri(url) { |f| JSON.load(f.read) }
117+
output +=
118+
"| #{name} | [`#{source[:repo]}@#{commit["sha"]}`](https://github.com/ruby/ruby/tree/#{commit["sha"]}) |\n"
114119
else
115120
raise "unknown source type: #{source[:type]}"
116121
end
@@ -122,8 +127,12 @@ desc "Fetch artifacts of a run of GitHub Actions"
122127
task :fetch_artifacts, [:run_id] do |t, args|
123128
RubyWasm::Toolchain.check_executable("gh")
124129

125-
artifacts = JSON.load(%x(gh api repos/{owner}/{repo}/actions/runs/#{args[:run_id]}/artifacts))
126-
artifacts = artifacts["artifacts"].filter { RELASE_ARTIFACTS.include?(_1["name"]) }
130+
artifacts =
131+
JSON.load(
132+
`gh api repos/{owner}/{repo}/actions/runs/#{args[:run_id]}/artifacts`
133+
)
134+
artifacts =
135+
artifacts["artifacts"].filter { RELASE_ARTIFACTS.include?(_1["name"]) }
127136
mkdir_p "release"
128137
Dir.chdir("release") do
129138
artifacts.each do |artifact|
@@ -141,12 +150,9 @@ task :publish, [:tag] do |t, args|
141150
RubyWasm::Toolchain.check_executable("gh")
142151

143152
nightly = /^\d{4}-\d{2}-\d{2}-.$/.match?(args[:tag])
144-
files = RELASE_ARTIFACTS.flat_map do |artifact|
145-
Dir.glob("release/#{artifact}/*")
146-
end
147-
File.open("release/note.md", "w") do |f|
148-
f.print release_note
149-
end
153+
files =
154+
RELASE_ARTIFACTS.flat_map { |artifact| Dir.glob("release/#{artifact}/*") }
155+
File.open("release/note.md", "w") { |f| f.print release_note }
150156
NPM_RELEASE_ARTIFACTS.each do |artifact|
151157
tarball = Dir.glob("release/#{artifact}/*")
152158
next if tarball.empty?

0 commit comments

Comments
 (0)