Skip to content

Commit f63cd84

Browse files
Remove rake dependency from wasi_vfs and wit-bindgen product
1 parent c3c3f62 commit f63cd84

File tree

6 files changed

+40
-53
lines changed

6 files changed

+40
-53
lines changed

lib/ruby_wasm/build_system/product/crossruby.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def build_exts
130130
def build(remake: false, reconfigure: false)
131131
FileUtils.mkdir_p dest_dir
132132
FileUtils.mkdir_p build_dir
133-
[@source, @baseruby, @libyaml, @zlib].each(&:build)
133+
[@source, @baseruby, @libyaml, @zlib, @wasi_vfs].each(&:build)
134134
dep_tasks.each(&:invoke)
135135
configure(reconfigure: reconfigure)
136136
build_exts
@@ -168,7 +168,6 @@ def with_zlib(zlib)
168168

169169
def with_wasi_vfs(wasi_vfs)
170170
@wasi_vfs = wasi_vfs
171-
wasi_vfs.install_task&.tap { |t| @dep_tasks << t }
172171
end
173172

174173
def dest_dir

lib/ruby_wasm/build_system/product/wasi_vfs.rb

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
require "rake"
21
require_relative "./product"
32

43
module RubyWasm
54
class WasiVfsProduct < BuildProduct
6-
attr_reader :install_task, :cli_install_task
7-
85
WASI_VFS_VERSION = "0.1.1"
96

107
def initialize(build_dir)
@@ -43,29 +40,25 @@ def name
4340
lib_product_build_dir
4441
end
4542

46-
def define_task
47-
file(lib_wasi_vfs_a) do
48-
require "tmpdir"
49-
lib_wasi_vfs_url =
50-
"https://github.com/kateinoigakukun/wasi-vfs/releases/download/v#{WASI_VFS_VERSION}/libwasi_vfs-wasm32-unknown-unknown.zip"
51-
Dir.mktmpdir do |tmpdir|
52-
sh "curl -L #{lib_wasi_vfs_url} -o #{tmpdir}/libwasi_vfs.zip"
53-
sh "unzip #{tmpdir}/libwasi_vfs.zip -d #{tmpdir}"
54-
mkdir_p File.dirname(lib_wasi_vfs_a)
55-
mv File.join(tmpdir, "libwasi_vfs.a"), lib_wasi_vfs_a
56-
end
43+
def build
44+
return if !@need_fetch_lib && File.exist?(lib_wasi_vfs_a)
45+
require "tmpdir"
46+
lib_wasi_vfs_url =
47+
"https://github.com/kateinoigakukun/wasi-vfs/releases/download/v#{WASI_VFS_VERSION}/libwasi_vfs-wasm32-unknown-unknown.zip"
48+
Dir.mktmpdir do |tmpdir|
49+
system "curl -L #{lib_wasi_vfs_url} -o #{tmpdir}/libwasi_vfs.zip"
50+
system "unzip #{tmpdir}/libwasi_vfs.zip -d #{tmpdir}"
51+
FileUtils.mkdir_p File.dirname(lib_wasi_vfs_a)
52+
FileUtils.mv File.join(tmpdir, "libwasi_vfs.a"), lib_wasi_vfs_a
5753
end
58-
lib_install_deps = @need_fetch_lib ? [lib_wasi_vfs_a] : []
59-
@install_task = task "wasi-vfs:install" => lib_install_deps
54+
end
6055

61-
file(cli_bin_path) do
62-
mkdir_p cli_product_build_dir
63-
zipfiel = File.join(cli_product_build_dir, "wasi-vfs-cli.zip")
64-
sh "curl -L -o #{zipfiel} #{self.cli_download_url}"
65-
sh "unzip #{zipfiel} -d #{cli_product_build_dir}"
66-
end
67-
cli_install_deps = @need_fetch_cli ? [cli_bin_path] : []
68-
@cli_install_task = task "wasi-vfs-cli:install" => cli_install_deps
56+
def install_cli
57+
return if !@need_fetch_cli && File.exist?(cli_bin_path)
58+
FileUtils.mkdir_p cli_product_build_dir
59+
zipfile = File.join(cli_product_build_dir, "wasi-vfs-cli.zip")
60+
system "curl -L -o #{zipfile} #{self.cli_download_url}"
61+
system "unzip #{zipfile} -d #{cli_product_build_dir}"
6962
end
7063

7164
def cli_download_url

lib/ruby_wasm/build_system/toolchain/wit_bindgen.rb

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,20 @@ def initialize(
1212
@revision = revision
1313
end
1414

15-
def define_task
16-
file @bin_path do
17-
RubyWasm::Toolchain.check_executable("cargo")
18-
sh *[
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-
]
29-
end
30-
@task ||= task "wit-bindgen:install" => @bin_path
31-
end
32-
33-
def install_task
34-
@task
15+
def install
16+
return if File.exist?(@bin_path)
17+
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+
]
3529
end
3630
end
3731
end

lib/ruby_wasm/rake_task.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def initialize(
4545

4646
@libyaml = RubyWasm::LibYAMLProduct.new(@build_dir, @target, @toolchain)
4747
@zlib = RubyWasm::ZlibProduct.new(@build_dir, @target, @toolchain)
48-
@wasi_vfs = add_product RubyWasm::WasiVfsProduct.new(@build_dir)
48+
@wasi_vfs = RubyWasm::WasiVfsProduct.new(@build_dir)
4949
@source = RubyWasm::BuildSource.new(src, @build_dir)
5050
@baseruby = RubyWasm::BaseRubyProduct.new(@build_dir, @source)
5151

tasks/check.rake

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace :check do
22
wit_bindgen = RubyWasm::WitBindgen.new(build_dir: "build")
3-
wit_bindgen.define_task
4-
task :bindgen_c => wit_bindgen.install_task do
3+
task :bindgen_c do
4+
wit_bindgen.install
55
wits = [
66
["ext/witapi/bindgen/rb-abi-guest.wit", "--export"],
77
["ext/js/bindgen/rb-js-abi-host.wit", "--import"],
@@ -12,7 +12,8 @@ namespace :check do
1212
end
1313
end
1414

15-
task :bindgen_js => wit_bindgen.install_task do
15+
task :bindgen_js do
16+
wit_bindgen.install
1617
sh *[
1718
wit_bindgen.bin_path, "host", "js",
1819
"--import", "ext/witapi/bindgen/rb-abi-guest.wit",
@@ -23,4 +24,4 @@ namespace :check do
2324

2425
desc "Check wit-bindgen'ed sources are up-to-date"
2526
task :bindgen => [:bindgen_c, :bindgen_js]
26-
end
27+
end

tasks/packaging.rake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ WAPM_PACKAGES = [
1010

1111
namespace :npm do
1212
wasi_vfs = RubyWasm::WasiVfsProduct.new("build")
13-
wasi_vfs.define_task
1413
wasi_sdk = TOOLCHAINS["wasi-sdk"]
1514
tools = {
1615
"WASI_VFS_CLI" => wasi_vfs.cli_bin_path,
@@ -21,7 +20,8 @@ namespace :npm do
2120
pkg_dir = "#{Dir.pwd}/packages/npm-packages/#{pkg[:name]}"
2221

2322
desc "Build npm package #{pkg[:name]}"
24-
task pkg[:name] => ["build:#{pkg[:build]}", wasi_vfs.cli_install_task, wasi_sdk.binaryen_install_task] do
23+
task pkg[:name] => ["build:#{pkg[:build]}", wasi_sdk.binaryen_install_task] do
24+
wasi_vfs.install_cli
2525
sh "npm ci", chdir: pkg_dir
2626
sh tools, "#{pkg_dir}/build-package.sh #{base_dir}/rubies/#{pkg[:build]}"
2727
sh "npm pack", chdir: pkg_dir

0 commit comments

Comments
 (0)