3
3
4
4
module RubyWasm
5
5
class WasiVfsProduct < BuildProduct
6
- attr_reader :install_task
6
+ attr_reader :install_task , :cli_install_task
7
7
8
8
WASI_VFS_VERSION = "0.1.1"
9
9
@@ -23,6 +23,19 @@ def lib_wasi_vfs_a
23
23
ENV [ "LIB_WASI_VFS_A" ] || File . join ( lib_product_build_dir , "libwasi_vfs.a" )
24
24
end
25
25
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
+
26
39
def name
27
40
lib_product_build_dir
28
41
end
@@ -41,6 +54,28 @@ def define_task
41
54
mv File . join ( tmpdir , "libwasi_vfs.a" ) , lib_wasi_vfs_a
42
55
end
43
56
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 } "
44
79
end
45
80
end
46
81
end
0 commit comments