Skip to content

Commit 9e8450b

Browse files
install wasi-vfs when packaging npm
1 parent 5fe3e86 commit 9e8450b

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

Rakefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ BUILDS = [
4545

4646
LIB_ROOT = File.dirname(__FILE__)
4747

48+
TOOLCHAINS = {}
49+
4850
namespace :build do
4951
BUILDS.each do |params|
5052
name = "#{params[:src]}-#{params[:target]}-#{params[:profile]}"
@@ -60,6 +62,9 @@ namespace :build do
6062
srcdir = File.join(LIB_ROOT, "ext", ext)
6163
RubyWasm::CrossRubyExtProduct.new(srcdir, toolchain)
6264
end
65+
unless TOOLCHAINS.key? toolchain.name
66+
TOOLCHAINS[toolchain.name] = toolchain
67+
end
6368
end
6469
end
6570
end

lib/ruby_wasm/build_system/product/wasi_vfs.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ class WasiVfsProduct < BuildProduct
99

1010
def initialize(build_dir)
1111
@build_dir = build_dir
12+
@cli_path = ENV["WASI_VFS_CLI"] || Toolchain.find_path("wasi-vfs")
13+
@need_fetch_cli = @cli_path.nil?
14+
@cli_path ||= File.join(cli_product_build_dir, "wasi-vfs")
1215
end
1316

1417
def lib_product_build_dir
@@ -32,7 +35,7 @@ def cli_product_build_dir
3235
end
3336

3437
def cli_bin_path
35-
ENV["WASI_VFS_CLI"] || File.join(cli_product_build_dir, "wasi-vfs")
38+
@cli_path
3639
end
3740

3841
def name
@@ -60,7 +63,7 @@ def define_task
6063
sh "curl -L -o #{zipfiel} #{self.cli_download_url}"
6164
sh "unzip #{zipfiel} -d #{cli_product_build_dir}"
6265
end
63-
cli_install_deps = ENV["WASI_VFS_CLI"] ? [] : [cli_bin_path]
66+
cli_install_deps = @need_fetch_cli ? [cli_bin_path] : []
6467
@cli_install_task = task "wasi-vfs-cli:install" => cli_install_deps
6568
end
6669

tasks/packaging.rake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ WAPM_PACKAGES = [
99
]
1010

1111
namespace :npm do
12+
wasi_vfs = RubyWasm::WasiVfsProduct.new("build")
13+
wasi_vfs.define_task
14+
tools = {
15+
"WASI_VFS_CLI" => wasi_vfs.cli_bin_path,
16+
"WASMOPT" => TOOLCHAINS["wasi-sdk"].wasm_opt,
17+
}
1218
NPM_PACKAGES.each do |pkg|
1319
base_dir = Dir.pwd
1420
pkg_dir = "#{Dir.pwd}/packages/npm-packages/#{pkg[:name]}"
1521

1622
desc "Build npm package #{pkg[:name]}"
17-
task pkg[:name] => ["build:#{pkg[:build]}"] do
23+
task pkg[:name] => ["build:#{pkg[:build]}", wasi_vfs.cli_install_task] do
1824
sh "npm ci", chdir: pkg_dir
1925
sh "#{pkg_dir}/build-package.sh #{base_dir}/rubies/#{pkg[:build]}"
2026
sh "npm pack", chdir: pkg_dir

0 commit comments

Comments
 (0)