Class: RubyWasm::WasiVfsProduct

Inherits:
BuildProduct show all
Defined in:
lib/ruby_wasm/build/product/wasi_vfs.rb

Constant Summary collapse

WASI_VFS_VERSION =
"0.5.0"

Instance Method Summary collapse

Constructor Details

#initialize(build_dir) ⇒ WasiVfsProduct

Returns a new instance of WasiVfsProduct.



7
8
9
10
# File 'lib/ruby_wasm/build/product/wasi_vfs.rb', line 7

def initialize(build_dir)
  @build_dir = build_dir
  @need_fetch_lib = ENV["LIB_WASI_VFS_A"].nil?
end

Instance Method Details

#build(executor) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ruby_wasm/build/product/wasi_vfs.rb', line 28

def build(executor)
  return if !@need_fetch_lib || File.exist?(lib_wasi_vfs_a)
  require "tmpdir"
  lib_wasi_vfs_url =
    "https://github.com/kateinoigakukun/wasi-vfs/releases/download/v#{WASI_VFS_VERSION}/libwasi_vfs-wasm32-unknown-unknown.zip"
  Dir.mktmpdir do |tmpdir|
    executor.system "curl",
                    "-L",
                    lib_wasi_vfs_url,
                    "-o",
                    "#{tmpdir}/libwasi_vfs.zip"
    executor.system "unzip", "#{tmpdir}/libwasi_vfs.zip", "-d", tmpdir
    executor.mkdir_p File.dirname(lib_wasi_vfs_a)
    executor.mv File.join(tmpdir, "libwasi_vfs.a"), lib_wasi_vfs_a
  end
end

#lib_product_build_dirObject



12
13
14
15
16
17
18
# File 'lib/ruby_wasm/build/product/wasi_vfs.rb', line 12

def lib_product_build_dir
  File.join(
    @build_dir,
    "wasm32-unknown-wasip1",
    "wasi-vfs-#{WASI_VFS_VERSION}"
  )
end

#lib_wasi_vfs_aObject



20
21
22
# File 'lib/ruby_wasm/build/product/wasi_vfs.rb', line 20

def lib_wasi_vfs_a
  ENV["LIB_WASI_VFS_A"] || File.join(lib_product_build_dir, "libwasi_vfs.a")
end

#nameObject



24
25
26
# File 'lib/ruby_wasm/build/product/wasi_vfs.rb', line 24

def name
  "wasi-vfs-#{WASI_VFS_VERSION}-#{RbConfig::CONFIG["host"]}"
end