Skip to content

Commit e1ce538

Browse files
download libwasi_vfs.a on demand at build-time
1 parent 52f341b commit e1ce538

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

lib/ruby_wasm/build_system/product.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
require_relative "product/baseruby"
55
require_relative "product/zlib"
66
require_relative "product/libyaml"
7+
require_relative "product/wasi_vfs"
78
require_relative "product/crossruby"

lib/ruby_wasm/build_system/product/crossruby.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ def with_zlib(zlib)
165165
@dep_tasks << zlib.install_task
166166
end
167167

168+
def with_wasi_vfs(wasi_vfs)
169+
@wasi_vfs = wasi_vfs
170+
@dep_tasks << wasi_vfs.install_task
171+
end
172+
168173
def dest_dir
169174
File.join(@rubies_dir, name)
170175
end
@@ -209,9 +214,7 @@ def configure_args(build_triple, toolchain)
209214

210215
case target
211216
when "wasm32-unknown-wasi"
212-
unless toolchain.lib_wasi_vfs_a.nil?
213-
xldflags << toolchain.lib_wasi_vfs_a
214-
end
217+
xldflags << @wasi_vfs.lib_wasi_vfs_a if @wasi_vfs
215218
when "wasm32-unknown-emscripten"
216219
ldflags.concat(%w[-s MODULARIZE=1])
217220
args.concat(%w[CC=emcc LD=emcc AR=emar RANLIB=emranlib])
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
require "rake"
2+
require_relative "./product"
3+
4+
module RubyWasm
5+
class WasiVfsProduct < BuildProduct
6+
attr_reader :install_task
7+
8+
WASI_VFS_VERSION = "0.1.1"
9+
10+
def initialize(build_dir)
11+
@build_dir = build_dir
12+
end
13+
14+
def lib_product_build_dir
15+
File.join(
16+
@build_dir,
17+
"wasm32-unknown-wasi",
18+
"wasi-vfs-#{WASI_VFS_VERSION}"
19+
)
20+
end
21+
22+
def lib_wasi_vfs_a
23+
File.join(lib_product_build_dir, "libwasi_vfs.a")
24+
end
25+
26+
def name
27+
lib_product_build_dir
28+
end
29+
30+
def define_task
31+
@install_task =
32+
file(lib_wasi_vfs_a) do
33+
require "tmpdir"
34+
lib_wasi_vfs_url =
35+
"https://github.com/kateinoigakukun/wasi-vfs/releases/download/v#{WASI_VFS_VERSION}/libwasi_vfs-wasm32-unknown-unknown.zip"
36+
Dir.mktmpdir do |tmpdir|
37+
sh "curl -L #{lib_wasi_vfs_url} -o #{tmpdir}/libwasi_vfs.zip"
38+
sh "unzip #{tmpdir}/libwasi_vfs.zip -d #{tmpdir}"
39+
mkdir_p File.dirname(lib_wasi_vfs_a)
40+
mv File.join(tmpdir, "libwasi_vfs.a"), lib_wasi_vfs_a
41+
end
42+
end
43+
end
44+
end
45+
end

lib/ruby_wasm/rake_task.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def initialize(
4343
add_product RubyWasm::LibYAMLProduct.new(@build_dir, @target, @toolchain)
4444
@zlib =
4545
add_product RubyWasm::ZlibProduct.new(@build_dir, @target, @toolchain)
46+
@wasi_vfs = add_product RubyWasm::WasiVfsProduct.new(@build_dir)
4647
@source = add_product RubyWasm::BuildSource.new(src, @build_dir)
4748
@baseruby = add_product RubyWasm::BaseRubyProduct.new(@build_dir, @source)
4849

@@ -64,6 +65,7 @@ def initialize(
6465

6566
@crossruby.with_libyaml @libyaml
6667
@crossruby.with_zlib @zlib
68+
@crossruby.with_wasi_vfs @wasi_vfs
6769

6870
@crossruby.define_task
6971
end

0 commit comments

Comments
 (0)