Skip to content

Commit 9f89df1

Browse files
build wit-bindgen if needed
1 parent 3dc798e commit 9f89df1

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

lib/ruby_wasm/build_system/toolchain.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require_relative "./toolchain/wit_bindgen"
2+
13
module RubyWasm
24
class Toolchain < ::Rake::TaskLib
35
attr_reader :name
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module RubyWasm
2+
class WitBindgen < ::Rake::TaskLib
3+
attr_reader :bin_path
4+
5+
def initialize(build_dir:, revision: "bb33644b4fd21ecf43761f63c472cdfffe57e300")
6+
@build_dir = build_dir
7+
@tool_dir = File.join(@build_dir, "toolchain", "wit-bindgen")
8+
@bin_path = File.join(@tool_dir, "bin", "wit-bindgen")
9+
@revision = revision
10+
end
11+
12+
def define_task
13+
file @bin_path do
14+
RubyWasm::Toolchain.check_executable("cargo")
15+
sh *[
16+
"cargo", "install",
17+
"--git", "https://github.com/bytecodealliance/wit-bindgen",
18+
"--rev", @revision, "--root", @tool_dir,
19+
"wit-bindgen-cli",
20+
]
21+
end
22+
@task ||= task "wit-bindgen:install" => @bin_path
23+
end
24+
25+
def install_task
26+
@task
27+
end
28+
end
29+
end

tasks/check.rake

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
namespace :check do
2-
task :bindgen_c do
3-
RubyWasm::Toolchain.check_executable("wit-bindgen")
2+
wit_bindgen = RubyWasm::WitBindgen.new(build_dir: "build")
3+
wit_bindgen.define_task
4+
task :bindgen_c => wit_bindgen.install_task do
45
wits = [
56
["ext/witapi/bindgen/rb-abi-guest.wit", "--export"],
67
["ext/js/bindgen/rb-js-abi-host.wit", "--import"],
78
]
89
wits.each do |wit|
910
path, mode = wit
10-
sh "wit-bindgen c #{mode} #{path} --out-dir #{File.dirname(path)}"
11+
sh "#{wit_bindgen.bin_path} c #{mode} #{path} --out-dir #{File.dirname(path)}"
1112
end
1213
end
1314

14-
task :bindgen_js do
15-
sh *%w(
16-
wit-bindgen js
17-
--import ext/witapi/bindgen/rb-abi-guest.wit
18-
--export ext/js/bindgen/rb-js-abi-host.wit
19-
--out-dir packages/npm-packages/ruby-wasm-wasi/src/bindgen
20-
)
15+
task :bindgen_js => wit_bindgen.install_task do
16+
sh *[
17+
wit_bindgen.bin_path, "js",
18+
"--import", "ext/witapi/bindgen/rb-abi-guest.wit",
19+
"--export", "ext/js/bindgen/rb-js-abi-host.wit",
20+
"--out-dir", "packages/npm-packages/ruby-wasm-wasi/src/bindgen",
21+
]
2122
end
2223

2324
desc "Check wit-bindgen'ed sources are up-to-date"

0 commit comments

Comments
 (0)