Skip to content

Commit fea2ed7

Browse files
install wasi-vfs cli on demand
1 parent 39b16ee commit fea2ed7

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

lib/ruby_wasm/build_system/product/wasi_vfs.rb

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

44
module RubyWasm
55
class WasiVfsProduct < BuildProduct
6-
attr_reader :install_task
6+
attr_reader :install_task, :cli_install_task
77

88
WASI_VFS_VERSION = "0.1.1"
99

@@ -23,6 +23,19 @@ def lib_wasi_vfs_a
2323
ENV["LIB_WASI_VFS_A"] || File.join(lib_product_build_dir, "libwasi_vfs.a")
2424
end
2525

26+
def cli_product_build_dir
27+
ENV["WASI_VFS_CLI"] ||
28+
File.join(
29+
@build_dir,
30+
RbConfig::CONFIG["host"],
31+
"wasi-vfs-#{WASI_VFS_VERSION}"
32+
)
33+
end
34+
35+
def cli_bin_path
36+
File.join(cli_product_build_dir, "wasi-vfs")
37+
end
38+
2639
def name
2740
lib_product_build_dir
2841
end
@@ -41,6 +54,28 @@ def define_task
4154
mv File.join(tmpdir, "libwasi_vfs.a"), lib_wasi_vfs_a
4255
end
4356
end
57+
58+
file(cli_bin_path) do
59+
mkdir_p cli_product_build_dir
60+
zipfiel = File.join(cli_product_build_dir, "wasi-vfs-cli.zip")
61+
sh "curl -L -o #{zipfiel} #{self.cli_download_url}"
62+
sh "unzip #{zipfiel} -d #{cli_product_build_dir}"
63+
end
64+
cli_install_deps = ENV["WASI_VFS_CLI"] ? [] : [cli_bin_path]
65+
@cli_install_task = task "wasi-vfs-cli:install" => cli_install_deps
66+
end
67+
68+
def cli_download_url
69+
assets = [
70+
[/x86_64-linux/, "wasi-vfs-cli-x86_64-unknown-linux-gnu.zip"],
71+
[/x86_64-darwin/, "wasi-vfs-cli-x86_64-apple-darwin.zip"],
72+
[/arm64-darwin/, "wasi-vfs-cli-aarch64-apple-darwin.zip"]
73+
]
74+
asset = assets.find { |os, _| os =~ RUBY_PLATFORM }&.at(1)
75+
if asset.nil?
76+
raise "unsupported platform for fetching wasi-vfs CLI: #{RUBY_PLATFORM}"
77+
end
78+
"https://github.com/kateinoigakukun/wasi-vfs/releases/download/v#{WASI_VFS_VERSION}/#{asset}"
4479
end
4580
end
4681
end

0 commit comments

Comments
 (0)