ruby_wasm 2.5.1-aarch64-linux-musl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.clang-format +8 -0
- data/CONTRIBUTING.md +128 -0
- data/Gemfile +17 -0
- data/LICENSE +21 -0
- data/NOTICE +1293 -0
- data/README.md +154 -0
- data/Rakefile +164 -0
- data/Steepfile +24 -0
- data/benchmarks/vm_deep_call.rb +55 -0
- data/docs/api.md +2 -0
- data/docs/cheat_sheet.md +195 -0
- data/docs/faq.md +25 -0
- data/exe/rbwasm +7 -0
- data/ext/.gitignore +2 -0
- data/ext/README.md +11 -0
- data/ext/extinit.c.erb +32 -0
- data/lib/ruby_wasm/3.1/ruby_wasm.so +0 -0
- data/lib/ruby_wasm/3.2/ruby_wasm.so +0 -0
- data/lib/ruby_wasm/3.3/ruby_wasm.so +0 -0
- data/lib/ruby_wasm/build/build_params.rb +3 -0
- data/lib/ruby_wasm/build/downloader.rb +18 -0
- data/lib/ruby_wasm/build/executor.rb +191 -0
- data/lib/ruby_wasm/build/product/baseruby.rb +37 -0
- data/lib/ruby_wasm/build/product/crossruby.rb +360 -0
- data/lib/ruby_wasm/build/product/libyaml.rb +70 -0
- data/lib/ruby_wasm/build/product/openssl.rb +93 -0
- data/lib/ruby_wasm/build/product/product.rb +39 -0
- data/lib/ruby_wasm/build/product/ruby_source.rb +103 -0
- data/lib/ruby_wasm/build/product/wasi_vfs.rb +45 -0
- data/lib/ruby_wasm/build/product/zlib.rb +70 -0
- data/lib/ruby_wasm/build/product.rb +8 -0
- data/lib/ruby_wasm/build/target.rb +24 -0
- data/lib/ruby_wasm/build/toolchain/wit_bindgen.rb +31 -0
- data/lib/ruby_wasm/build/toolchain.rb +193 -0
- data/lib/ruby_wasm/build.rb +92 -0
- data/lib/ruby_wasm/cli.rb +347 -0
- data/lib/ruby_wasm/packager/component_adapter/wasi_snapshot_preview1.command.wasm +0 -0
- data/lib/ruby_wasm/packager/component_adapter/wasi_snapshot_preview1.reactor.wasm +0 -0
- data/lib/ruby_wasm/packager/component_adapter.rb +14 -0
- data/lib/ruby_wasm/packager/core.rb +333 -0
- data/lib/ruby_wasm/packager/file_system.rb +160 -0
- data/lib/ruby_wasm/packager.rb +96 -0
- data/lib/ruby_wasm/rake_task.rb +60 -0
- data/lib/ruby_wasm/util.rb +15 -0
- data/lib/ruby_wasm/version.rb +3 -0
- data/lib/ruby_wasm.rb +34 -0
- data/package-lock.json +9777 -0
- data/package.json +12 -0
- data/rakelib/check.rake +37 -0
- data/rakelib/ci.rake +152 -0
- data/rakelib/doc.rake +29 -0
- data/rakelib/format.rake +35 -0
- data/rakelib/gem.rake +22 -0
- data/rakelib/packaging.rake +165 -0
- data/rakelib/version.rake +40 -0
- data/sig/open_uri.rbs +4 -0
- data/sig/ruby_wasm/build.rbs +327 -0
- data/sig/ruby_wasm/cli.rbs +51 -0
- data/sig/ruby_wasm/ext.rbs +26 -0
- data/sig/ruby_wasm/packager.rbs +122 -0
- data/sig/ruby_wasm/util.rbs +5 -0
- data/tools/clang-format-diff.sh +18 -0
- data/tools/exe/rbminify +12 -0
- data/tools/lib/syntax_tree/minify_ruby.rb +63 -0
- metadata +114 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
require_relative "./product"
|
2
|
+
|
3
|
+
module RubyWasm
|
4
|
+
class OpenSSLProduct < AutoconfProduct
|
5
|
+
attr_reader :target
|
6
|
+
|
7
|
+
OPENSSL_VERSION = "3.2.0"
|
8
|
+
|
9
|
+
def initialize(build_dir, target, toolchain)
|
10
|
+
@build_dir = build_dir
|
11
|
+
@target = target
|
12
|
+
super(target, toolchain)
|
13
|
+
end
|
14
|
+
|
15
|
+
def product_build_dir
|
16
|
+
File.join(@build_dir, target.to_s, "openssl-#{OPENSSL_VERSION}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def destdir
|
20
|
+
File.join(product_build_dir, "opt")
|
21
|
+
end
|
22
|
+
|
23
|
+
def install_root
|
24
|
+
File.join(destdir, "usr", "local")
|
25
|
+
end
|
26
|
+
|
27
|
+
def name
|
28
|
+
"openssl-#{OPENSSL_VERSION}-#{target}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def configure_args
|
32
|
+
args = %w[
|
33
|
+
gcc
|
34
|
+
-static
|
35
|
+
-no-asm
|
36
|
+
-no-threads
|
37
|
+
-no-afalgeng
|
38
|
+
-no-ui-console
|
39
|
+
-no-tests
|
40
|
+
-no-sock
|
41
|
+
-no-dgram
|
42
|
+
--libdir=lib
|
43
|
+
-Wl,--allow-undefined
|
44
|
+
]
|
45
|
+
if @target.triple.start_with?("wasm32-unknown-wasi")
|
46
|
+
args.concat %w[
|
47
|
+
-D_WASI_EMULATED_SIGNAL
|
48
|
+
-D_WASI_EMULATED_PROCESS_CLOCKS
|
49
|
+
-D_WASI_EMULATED_MMAN
|
50
|
+
-D_WASI_EMULATED_GETPID
|
51
|
+
-DNO_CHMOD
|
52
|
+
-DHAVE_FORK=0
|
53
|
+
]
|
54
|
+
end
|
55
|
+
|
56
|
+
if @target.pic?
|
57
|
+
args << "-fPIC"
|
58
|
+
end
|
59
|
+
|
60
|
+
args + tools_args
|
61
|
+
end
|
62
|
+
|
63
|
+
def build(executor)
|
64
|
+
return if File.exist?(File.join(install_root, "lib", "libssl.a"))
|
65
|
+
|
66
|
+
executor.mkdir_p File.dirname(product_build_dir)
|
67
|
+
executor.rm_rf product_build_dir
|
68
|
+
executor.mkdir_p product_build_dir
|
69
|
+
tarball_path =
|
70
|
+
File.join(product_build_dir, "openssl-#{OPENSSL_VERSION}.tar.gz")
|
71
|
+
executor.system "curl",
|
72
|
+
"-o",
|
73
|
+
tarball_path,
|
74
|
+
"-L",
|
75
|
+
"https://www.openssl.org/source/openssl-#{OPENSSL_VERSION}.tar.gz"
|
76
|
+
executor.system "tar",
|
77
|
+
"xzf",
|
78
|
+
tarball_path,
|
79
|
+
"-C",
|
80
|
+
product_build_dir,
|
81
|
+
"--strip-components=1"
|
82
|
+
|
83
|
+
executor.system "./Configure", *configure_args, chdir: product_build_dir
|
84
|
+
# Use "install_sw" instead of "install" because it tries to install docs and it's very slow.
|
85
|
+
# OpenSSL build system doesn't have well support for parallel build, so force -j1.
|
86
|
+
executor.system "make",
|
87
|
+
"-j1",
|
88
|
+
"install_dev",
|
89
|
+
"DESTDIR=#{destdir}",
|
90
|
+
chdir: product_build_dir
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module RubyWasm
|
2
|
+
class BuildProduct
|
3
|
+
def name
|
4
|
+
raise NotImplementedError, "identifiable product name must be implemented"
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class AutoconfProduct < BuildProduct
|
9
|
+
def initialize(target, toolchain)
|
10
|
+
@target = target
|
11
|
+
@toolchain = toolchain
|
12
|
+
end
|
13
|
+
def system_triplet_args
|
14
|
+
args = []
|
15
|
+
case @target.triple
|
16
|
+
when /^wasm32-unknown-wasi/
|
17
|
+
args.concat(%W[--host wasm32-wasi])
|
18
|
+
when "wasm32-unknown-emscripten"
|
19
|
+
args.concat(%W[--host wasm32-emscripten])
|
20
|
+
else
|
21
|
+
raise "unknown target: #{@target.triple}"
|
22
|
+
end
|
23
|
+
args
|
24
|
+
end
|
25
|
+
|
26
|
+
def tools_args
|
27
|
+
args = []
|
28
|
+
args << "CC=#{@toolchain.cc}"
|
29
|
+
args << "LD=#{@toolchain.ld}"
|
30
|
+
args << "AR=#{@toolchain.ar}"
|
31
|
+
args << "RANLIB=#{@toolchain.ranlib}"
|
32
|
+
args
|
33
|
+
end
|
34
|
+
|
35
|
+
def configure_args
|
36
|
+
system_triplet_args + tools_args
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require_relative "./product"
|
2
|
+
|
3
|
+
module RubyWasm
|
4
|
+
class BuildSource < BuildProduct
|
5
|
+
def initialize(params, build_dir)
|
6
|
+
@params = params
|
7
|
+
@build_dir = build_dir
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
@params[:name]
|
12
|
+
end
|
13
|
+
|
14
|
+
def cache_key(digest)
|
15
|
+
digest << @params[:type]
|
16
|
+
case @params[:type]
|
17
|
+
when "github"
|
18
|
+
digest << @params[:rev]
|
19
|
+
when "tarball"
|
20
|
+
digest << @params[:url]
|
21
|
+
when "local"
|
22
|
+
digest << File.mtime(@params[:path]).to_i.to_s
|
23
|
+
else
|
24
|
+
raise "unknown source type: #{@params[:type]}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def src_dir
|
29
|
+
File.join(@build_dir, "checkouts", @params[:name])
|
30
|
+
end
|
31
|
+
|
32
|
+
def configure_file
|
33
|
+
File.join(src_dir, "configure")
|
34
|
+
end
|
35
|
+
|
36
|
+
def fetch(executor)
|
37
|
+
case @params[:type]
|
38
|
+
when "github"
|
39
|
+
repo_url = "https://github.com/#{@params[:repo]}.git"
|
40
|
+
executor.mkdir_p src_dir
|
41
|
+
executor.system "git", "init", chdir: src_dir
|
42
|
+
executor.system "git",
|
43
|
+
"remote",
|
44
|
+
"add",
|
45
|
+
"origin",
|
46
|
+
repo_url,
|
47
|
+
chdir: src_dir
|
48
|
+
executor.system(
|
49
|
+
"git",
|
50
|
+
"fetch",
|
51
|
+
"--depth",
|
52
|
+
"1",
|
53
|
+
"origin",
|
54
|
+
"#{@params[:rev]}:origin/#{@params[:rev]}",
|
55
|
+
chdir: src_dir
|
56
|
+
)
|
57
|
+
executor.system(
|
58
|
+
"git",
|
59
|
+
"checkout",
|
60
|
+
"origin/#{@params[:rev]}",
|
61
|
+
chdir: src_dir
|
62
|
+
)
|
63
|
+
when "tarball"
|
64
|
+
executor.mkdir_p src_dir
|
65
|
+
tarball_path =
|
66
|
+
File.join(File.dirname(src_dir), File.basename(src_dir) + ".tar.gz")
|
67
|
+
executor.system("curl", "-L", "-o", tarball_path, @params[:url])
|
68
|
+
executor.system(
|
69
|
+
"tar",
|
70
|
+
"xf",
|
71
|
+
tarball_path,
|
72
|
+
"-C",
|
73
|
+
src_dir,
|
74
|
+
"--strip-components=1"
|
75
|
+
)
|
76
|
+
when "local"
|
77
|
+
executor.mkdir_p File.dirname(src_dir)
|
78
|
+
executor.ln_s File.expand_path(@params[:path]), src_dir
|
79
|
+
else
|
80
|
+
raise "unknown source type: #{@params[:type]}"
|
81
|
+
end
|
82
|
+
(@params[:patches] || []).each do |patch_path|
|
83
|
+
executor.system "patch", "-p1", "-i", patch_path, chdir: src_dir
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def build(executor)
|
88
|
+
fetch(executor) unless File.exist?(src_dir)
|
89
|
+
unless File.exist?(configure_file)
|
90
|
+
executor.system "ruby",
|
91
|
+
"tool/downloader.rb",
|
92
|
+
"-d",
|
93
|
+
"tool",
|
94
|
+
"-e",
|
95
|
+
"gnu",
|
96
|
+
"config.guess",
|
97
|
+
"config.sub",
|
98
|
+
chdir: src_dir
|
99
|
+
executor.system "./autogen.sh", chdir: src_dir
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative "./product"
|
2
|
+
|
3
|
+
module RubyWasm
|
4
|
+
class WasiVfsProduct < BuildProduct
|
5
|
+
WASI_VFS_VERSION = "0.5.0"
|
6
|
+
|
7
|
+
def initialize(build_dir)
|
8
|
+
@build_dir = build_dir
|
9
|
+
@need_fetch_lib = ENV["LIB_WASI_VFS_A"].nil?
|
10
|
+
end
|
11
|
+
|
12
|
+
def lib_product_build_dir
|
13
|
+
File.join(
|
14
|
+
@build_dir,
|
15
|
+
"wasm32-unknown-wasip1",
|
16
|
+
"wasi-vfs-#{WASI_VFS_VERSION}"
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def lib_wasi_vfs_a
|
21
|
+
ENV["LIB_WASI_VFS_A"] || File.join(lib_product_build_dir, "libwasi_vfs.a")
|
22
|
+
end
|
23
|
+
|
24
|
+
def name
|
25
|
+
"wasi-vfs-#{WASI_VFS_VERSION}-#{RbConfig::CONFIG["host"]}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def build(executor)
|
29
|
+
return if !@need_fetch_lib || File.exist?(lib_wasi_vfs_a)
|
30
|
+
require "tmpdir"
|
31
|
+
lib_wasi_vfs_url =
|
32
|
+
"https://github.com/kateinoigakukun/wasi-vfs/releases/download/v#{WASI_VFS_VERSION}/libwasi_vfs-wasm32-unknown-unknown.zip"
|
33
|
+
Dir.mktmpdir do |tmpdir|
|
34
|
+
executor.system "curl",
|
35
|
+
"-L",
|
36
|
+
lib_wasi_vfs_url,
|
37
|
+
"-o",
|
38
|
+
"#{tmpdir}/libwasi_vfs.zip"
|
39
|
+
executor.system "unzip", "#{tmpdir}/libwasi_vfs.zip", "-d", tmpdir
|
40
|
+
executor.mkdir_p File.dirname(lib_wasi_vfs_a)
|
41
|
+
executor.mv File.join(tmpdir, "libwasi_vfs.a"), lib_wasi_vfs_a
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require_relative "./product"
|
2
|
+
|
3
|
+
module RubyWasm
|
4
|
+
class ZlibProduct < AutoconfProduct
|
5
|
+
attr_reader :target
|
6
|
+
|
7
|
+
ZLIB_VERSION = "1.3.1"
|
8
|
+
|
9
|
+
def initialize(build_dir, target, toolchain)
|
10
|
+
@build_dir = build_dir
|
11
|
+
@target = target
|
12
|
+
super(target, toolchain)
|
13
|
+
end
|
14
|
+
|
15
|
+
def product_build_dir
|
16
|
+
File.join(@build_dir, target.to_s, "zlib-#{ZLIB_VERSION}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def destdir
|
20
|
+
File.join(product_build_dir, "opt")
|
21
|
+
end
|
22
|
+
|
23
|
+
def install_root
|
24
|
+
File.join(destdir, "usr", "local")
|
25
|
+
end
|
26
|
+
|
27
|
+
def name
|
28
|
+
"zlib-#{ZLIB_VERSION}-#{target}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def configure_args
|
32
|
+
args = %w[CHOST=linux]
|
33
|
+
|
34
|
+
args + tools_args
|
35
|
+
end
|
36
|
+
|
37
|
+
def build(executor)
|
38
|
+
return if Dir.exist?(install_root)
|
39
|
+
|
40
|
+
executor.mkdir_p File.dirname(product_build_dir)
|
41
|
+
executor.rm_rf product_build_dir
|
42
|
+
executor.mkdir_p product_build_dir
|
43
|
+
|
44
|
+
tarball_path = File.join(product_build_dir, "zlib-#{ZLIB_VERSION}.tar.gz")
|
45
|
+
executor.system "curl",
|
46
|
+
"-o",
|
47
|
+
tarball_path,
|
48
|
+
"-L",
|
49
|
+
"https://github.com/madler/zlib/releases/download/v#{ZLIB_VERSION}/zlib-#{ZLIB_VERSION}.tar.gz"
|
50
|
+
executor.system "tar",
|
51
|
+
"xzf",
|
52
|
+
tarball_path,
|
53
|
+
"-C",
|
54
|
+
product_build_dir,
|
55
|
+
"--strip-components=1"
|
56
|
+
|
57
|
+
configure_args = self.configure_args.dup
|
58
|
+
configure_args << "CFLAGS=-fPIC" if target.pic?
|
59
|
+
executor.system "env",
|
60
|
+
*configure_args,
|
61
|
+
"./configure",
|
62
|
+
"--static",
|
63
|
+
chdir: product_build_dir
|
64
|
+
executor.system "make",
|
65
|
+
"install",
|
66
|
+
"DESTDIR=#{destdir}",
|
67
|
+
chdir: product_build_dir
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require_relative "product/product"
|
2
|
+
require_relative "product/ruby_source"
|
3
|
+
require_relative "product/baseruby"
|
4
|
+
require_relative "product/zlib"
|
5
|
+
require_relative "product/libyaml"
|
6
|
+
require_relative "product/openssl"
|
7
|
+
require_relative "product/wasi_vfs"
|
8
|
+
require_relative "product/crossruby"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RubyWasm
|
2
|
+
# A build target representation
|
3
|
+
class Target
|
4
|
+
attr_reader :triple
|
5
|
+
|
6
|
+
def initialize(triple, pic: false)
|
7
|
+
@triple = triple
|
8
|
+
@pic = pic
|
9
|
+
end
|
10
|
+
|
11
|
+
def pic?
|
12
|
+
@pic
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
"#{@triple}#{@pic ? "-pic" : ""}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def cache_key(digest)
|
20
|
+
digest << @triple
|
21
|
+
digest << "pic" if @pic
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module RubyWasm
|
2
|
+
class WitBindgen
|
3
|
+
attr_reader :bin_path
|
4
|
+
|
5
|
+
def initialize(
|
6
|
+
build_dir:,
|
7
|
+
revision: "251e84b89121751f79ac268629e9285082b2596d"
|
8
|
+
)
|
9
|
+
@build_dir = build_dir
|
10
|
+
@tool_dir = File.join(@build_dir, "toolchain", "wit-bindgen")
|
11
|
+
@bin_path = File.join(@tool_dir, "bin", "wit-bindgen")
|
12
|
+
@revision = revision
|
13
|
+
end
|
14
|
+
|
15
|
+
def install
|
16
|
+
return if File.exist?(@bin_path)
|
17
|
+
RubyWasm::Toolchain.check_executable("cargo")
|
18
|
+
Kernel.system(
|
19
|
+
"cargo",
|
20
|
+
"install",
|
21
|
+
"--git",
|
22
|
+
"https://github.com/bytecodealliance/wit-bindgen",
|
23
|
+
"--rev",
|
24
|
+
@revision,
|
25
|
+
"--root",
|
26
|
+
@tool_dir,
|
27
|
+
"wit-bindgen-cli"
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
require_relative "./toolchain/wit_bindgen"
|
2
|
+
|
3
|
+
module RubyWasm
|
4
|
+
class Toolchain
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@tools = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_tool(name)
|
12
|
+
raise "not implemented"
|
13
|
+
end
|
14
|
+
|
15
|
+
def check_envvar(name)
|
16
|
+
raise "missing environment variable: #{name}" if ENV[name].nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.get(target, build_dir = nil)
|
20
|
+
case target
|
21
|
+
when /^wasm32-unknown-wasi/
|
22
|
+
return RubyWasm::WASISDK.new(build_dir: build_dir)
|
23
|
+
when "wasm32-unknown-emscripten"
|
24
|
+
return RubyWasm::Emscripten.new
|
25
|
+
else
|
26
|
+
raise "unknown target: #{target}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.find_path(command)
|
31
|
+
(ENV["PATH"] || "")
|
32
|
+
.split(File::PATH_SEPARATOR)
|
33
|
+
.each do |path_dir|
|
34
|
+
bin_path = File.join(path_dir, command)
|
35
|
+
return bin_path if File.executable?(bin_path)
|
36
|
+
end
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.check_executable(command)
|
41
|
+
tool = find_path(command)
|
42
|
+
raise "missing executable: #{command}" unless tool
|
43
|
+
tool
|
44
|
+
end
|
45
|
+
|
46
|
+
%i[cc ranlib ld ar].each do |name|
|
47
|
+
define_method(name) do
|
48
|
+
@tools_cache ||= {}
|
49
|
+
@tools_cache[name] ||= find_tool(name)
|
50
|
+
@tools_cache[name]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class WASISDK < Toolchain
|
56
|
+
def initialize(
|
57
|
+
wasi_sdk_path = ENV["WASI_SDK_PATH"],
|
58
|
+
build_dir: nil,
|
59
|
+
version_major: 20,
|
60
|
+
version_minor: 0,
|
61
|
+
binaryen_version: 108
|
62
|
+
)
|
63
|
+
@wasm_opt_path = Toolchain.find_path("wasm-opt")
|
64
|
+
@need_fetch_wasi_sdk = wasi_sdk_path.nil?
|
65
|
+
@need_fetch_binaryen = @wasm_opt_path.nil?
|
66
|
+
|
67
|
+
if @need_fetch_wasi_sdk
|
68
|
+
if build_dir.nil?
|
69
|
+
raise "build_dir is required when WASI_SDK_PATH is not set"
|
70
|
+
end
|
71
|
+
wasi_sdk_path = File.join(build_dir, "toolchain", "wasi-sdk")
|
72
|
+
@version_major = version_major
|
73
|
+
@version_minor = version_minor
|
74
|
+
end
|
75
|
+
|
76
|
+
if @need_fetch_binaryen
|
77
|
+
if build_dir.nil?
|
78
|
+
raise "build_dir is required when wasm-opt not installed in PATH"
|
79
|
+
end
|
80
|
+
@binaryen_path = File.join(build_dir, "toolchain", "binaryen")
|
81
|
+
@binaryen_version = binaryen_version
|
82
|
+
@wasm_opt_path = File.join(@binaryen_path, "bin", "wasm-opt")
|
83
|
+
end
|
84
|
+
|
85
|
+
@tools = {
|
86
|
+
cc: "#{wasi_sdk_path}/bin/clang",
|
87
|
+
ld: "#{wasi_sdk_path}/bin/clang",
|
88
|
+
ar: "#{wasi_sdk_path}/bin/llvm-ar",
|
89
|
+
ranlib: "#{wasi_sdk_path}/bin/llvm-ranlib"
|
90
|
+
}
|
91
|
+
@wasi_sdk_path = wasi_sdk_path
|
92
|
+
@name = "wasi-sdk"
|
93
|
+
end
|
94
|
+
|
95
|
+
def find_tool(name)
|
96
|
+
if !File.exist?(@tools[name]) && !ENV["WASI_SDK_PATH"].nil?
|
97
|
+
raise "missing tool '#{name}' at #{@tools[name]}"
|
98
|
+
end
|
99
|
+
@tools[name]
|
100
|
+
end
|
101
|
+
|
102
|
+
def wasm_opt
|
103
|
+
@wasm_opt_path
|
104
|
+
end
|
105
|
+
|
106
|
+
def wasi_sdk_path
|
107
|
+
@wasi_sdk_path
|
108
|
+
end
|
109
|
+
|
110
|
+
def download_url(version_major, version_minor)
|
111
|
+
version = "#{version_major}.#{version_minor}"
|
112
|
+
assets = [
|
113
|
+
[/x86_64-linux/, "wasi-sdk-#{version}-linux.tar.gz"],
|
114
|
+
[/(arm64e?|x86_64)-darwin/, "wasi-sdk-#{version}-macos.tar.gz"]
|
115
|
+
]
|
116
|
+
asset = assets.find { |os, _| os =~ RUBY_PLATFORM }&.at(1)
|
117
|
+
if asset.nil?
|
118
|
+
raise "unsupported platform for fetching WASI SDK: #{RUBY_PLATFORM}"
|
119
|
+
end
|
120
|
+
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-#{version_major}/#{asset}"
|
121
|
+
end
|
122
|
+
|
123
|
+
def binaryen_download_url(version)
|
124
|
+
assets = [
|
125
|
+
[
|
126
|
+
/x86_64-linux/,
|
127
|
+
"binaryen-version_#{@binaryen_version}-x86_64-linux.tar.gz"
|
128
|
+
],
|
129
|
+
[
|
130
|
+
/x86_64-darwin/,
|
131
|
+
"binaryen-version_#{@binaryen_version}-x86_64-macos.tar.gz"
|
132
|
+
],
|
133
|
+
[
|
134
|
+
/arm64e?-darwin/,
|
135
|
+
"binaryen-version_#{@binaryen_version}-arm64-macos.tar.gz"
|
136
|
+
]
|
137
|
+
]
|
138
|
+
asset = assets.find { |os, _| os =~ RUBY_PLATFORM }&.at(1)
|
139
|
+
if asset.nil?
|
140
|
+
raise "unsupported platform for fetching Binaryen: #{RUBY_PLATFORM}"
|
141
|
+
end
|
142
|
+
"https://github.com/WebAssembly/binaryen/releases/download/version_#{@binaryen_version}/#{asset}"
|
143
|
+
end
|
144
|
+
|
145
|
+
def install_wasi_sdk
|
146
|
+
return unless @need_fetch_wasi_sdk
|
147
|
+
wasi_sdk_tarball =
|
148
|
+
File.join(File.dirname(@wasi_sdk_path), "wasi-sdk.tar.gz")
|
149
|
+
unless File.exist? wasi_sdk_tarball
|
150
|
+
FileUtils.mkdir_p File.dirname(wasi_sdk_tarball)
|
151
|
+
system "curl -L -o #{wasi_sdk_tarball} #{self.download_url(@version_major, @version_minor)}"
|
152
|
+
end
|
153
|
+
unless File.exist? @wasi_sdk_path
|
154
|
+
FileUtils.mkdir_p @wasi_sdk_path
|
155
|
+
system "tar -C #{@wasi_sdk_path} --strip-component 1 -xzf #{wasi_sdk_tarball}"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def install_binaryen
|
160
|
+
return unless @need_fetch_binaryen
|
161
|
+
binaryen_tarball = File.expand_path("../binaryen.tar.gz", @binaryen_path)
|
162
|
+
unless File.exist? binaryen_tarball
|
163
|
+
FileUtils.mkdir_p File.dirname(binaryen_tarball)
|
164
|
+
system "curl -L -o #{binaryen_tarball} #{self.binaryen_download_url(@binaryen_version)}"
|
165
|
+
end
|
166
|
+
|
167
|
+
unless File.exist? @binaryen_path
|
168
|
+
FileUtils.mkdir_p @binaryen_path
|
169
|
+
system "tar -C #{@binaryen_path} --strip-component 1 -xzf #{binaryen_tarball}"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def install
|
174
|
+
install_wasi_sdk
|
175
|
+
install_binaryen
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
class Emscripten < Toolchain
|
180
|
+
def initialize
|
181
|
+
@tools = { cc: "emcc", ld: "emcc", ar: "emar", ranlib: "emranlib" }
|
182
|
+
@name = "emscripten"
|
183
|
+
end
|
184
|
+
|
185
|
+
def install
|
186
|
+
end
|
187
|
+
|
188
|
+
def find_tool(name)
|
189
|
+
Toolchain.check_executable(@tools[name])
|
190
|
+
@tools[name]
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require_relative "build/build_params"
|
2
|
+
require_relative "build/product"
|
3
|
+
require_relative "build/toolchain"
|
4
|
+
require_relative "build/executor"
|
5
|
+
require_relative "build/target"
|
6
|
+
|
7
|
+
class RubyWasm::Build
|
8
|
+
# Source to build from.
|
9
|
+
attr_reader :source
|
10
|
+
|
11
|
+
# Target to build for.
|
12
|
+
attr_reader :target
|
13
|
+
|
14
|
+
# Toolchain for the build.
|
15
|
+
# Defaults to the Toolchain.get for the target.
|
16
|
+
attr_reader :toolchain
|
17
|
+
|
18
|
+
# LibYAML product to build.
|
19
|
+
attr_reader :libyaml
|
20
|
+
|
21
|
+
# zlib product to build.
|
22
|
+
attr_reader :zlib
|
23
|
+
|
24
|
+
# wasi-vfs product used by the crossruby.
|
25
|
+
attr_reader :wasi_vfs
|
26
|
+
|
27
|
+
# BaseRuby product to build.
|
28
|
+
attr_reader :baseruby
|
29
|
+
|
30
|
+
# CrossRuby product to build.
|
31
|
+
attr_reader :crossruby
|
32
|
+
|
33
|
+
def initialize(
|
34
|
+
name,
|
35
|
+
target:,
|
36
|
+
src:,
|
37
|
+
toolchain:,
|
38
|
+
build_dir:,
|
39
|
+
rubies_dir:,
|
40
|
+
wasi_vfs: :default,
|
41
|
+
**options
|
42
|
+
)
|
43
|
+
@target = target
|
44
|
+
@build_dir = build_dir
|
45
|
+
@rubies_dir = rubies_dir
|
46
|
+
@toolchain = (toolchain || RubyWasm::Toolchain.get(target, @build_dir))
|
47
|
+
|
48
|
+
@libyaml = RubyWasm::LibYAMLProduct.new(@build_dir, @target, @toolchain)
|
49
|
+
@zlib = RubyWasm::ZlibProduct.new(@build_dir, @target, @toolchain)
|
50
|
+
@wasi_vfs = wasi_vfs == :default ? RubyWasm::WasiVfsProduct.new(@build_dir) : wasi_vfs
|
51
|
+
@source = RubyWasm::BuildSource.new(src, @build_dir)
|
52
|
+
@baseruby = RubyWasm::BaseRubyProduct.new(@build_dir, @source)
|
53
|
+
@openssl = RubyWasm::OpenSSLProduct.new(@build_dir, @target, @toolchain)
|
54
|
+
|
55
|
+
build_params =
|
56
|
+
RubyWasm::BuildParams.new(
|
57
|
+
name: name,
|
58
|
+
target: target,
|
59
|
+
default_exts: options[:default_exts]
|
60
|
+
)
|
61
|
+
|
62
|
+
@crossruby =
|
63
|
+
RubyWasm::CrossRubyProduct.new(
|
64
|
+
build_params,
|
65
|
+
@build_dir,
|
66
|
+
@rubies_dir,
|
67
|
+
@baseruby,
|
68
|
+
@source,
|
69
|
+
@toolchain
|
70
|
+
)
|
71
|
+
|
72
|
+
@crossruby.with_libyaml @libyaml
|
73
|
+
@crossruby.with_zlib @zlib
|
74
|
+
@crossruby.with_wasi_vfs @wasi_vfs
|
75
|
+
@crossruby.with_openssl @openssl
|
76
|
+
end
|
77
|
+
|
78
|
+
def cache_key(digest)
|
79
|
+
@source.cache_key(digest)
|
80
|
+
@crossruby.cache_key(digest)
|
81
|
+
digest << @build_dir
|
82
|
+
digest << @rubies_dir
|
83
|
+
@target.cache_key(digest)
|
84
|
+
digest << @toolchain.name
|
85
|
+
digest << @libyaml.name
|
86
|
+
digest << @zlib.name
|
87
|
+
digest << @openssl.name
|
88
|
+
if wasi_vfs = @wasi_vfs
|
89
|
+
digest << wasi_vfs.name
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|