Skip to content

Commit 9b1edba

Browse files
add public APIs to rake task class
1 parent 14ab3d0 commit 9b1edba

File tree

3 files changed

+63
-29
lines changed

3 files changed

+63
-29
lines changed

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace :build do
5656
end
5757
options = params
5858
.merge(BUILD_PROFILES[params[:profile]])
59-
.merge(name: name, src: source, extensions: user_exts, toolchain: toolchain)
59+
.merge(name: name, src: source, user_exts: user_exts, toolchain: toolchain)
6060
options.delete :profile
6161
RubyWasm::BuildTask.new(name, **options)
6262
end

lib/ruby_wasm/build_system/build_params.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module RubyWasm
77
:debug,
88
:default_exts,
99
:user_exts,
10+
:wasmoptflags,
1011
keyword_init: true
1112
)
1213
end

lib/ruby_wasm/rake_task.rb

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,78 @@
22
require_relative "./build_system"
33

44
class RubyWasm::BuildTask < ::Rake::TaskLib
5+
# Name of the task.
6+
attr_accessor :name
7+
8+
# Source to build from.
9+
attr_reader :source
10+
11+
# Toolchain for the build.
12+
# Defaults to the Toolchain.get for the target.
13+
attr_reader :toolchain
14+
15+
# LibYAML product to build.
16+
attr_reader :libyaml
17+
18+
# zlib product to build.
19+
attr_reader :zlib
20+
21+
# BaseRuby product to build.
22+
attr_reader :baseruby
23+
24+
# CrossRuby product to build.
25+
attr_reader :crossruby
26+
527
def initialize(
628
name,
729
target:,
830
src:,
9-
extensions: [],
31+
user_exts: [],
1032
toolchain: nil,
1133
build_dir: nil,
1234
rubies_dir: nil,
13-
**options,
14-
&task_block
35+
**options
1536
)
16-
build_dir ||= File.join(Dir.pwd, "build")
17-
rubies_dir ||= File.join(Dir.pwd, "rubies")
18-
toolchain ||= RubyWasm::Toolchain.get target
37+
@name = name
38+
@target = target
39+
@build_dir = build_dir || File.join(Dir.pwd, "build")
40+
@rubies_dir = rubies_dir || File.join(Dir.pwd, "rubies")
41+
@toolchain = toolchain || RubyWasm::Toolchain.get(target)
42+
@user_exts = user_exts
1943

20-
libyaml =
21-
add_product RubyWasm::LibYAMLProduct.new(build_dir, target, toolchain)
22-
zlib = add_product RubyWasm::ZlibProduct.new(build_dir, target, toolchain)
23-
24-
source = add_product RubyWasm::BuildSource.new(src, build_dir)
25-
baseruby = add_product RubyWasm::BaseRubyProduct.new(build_dir, source)
44+
@libyaml =
45+
add_product RubyWasm::LibYAMLProduct.new(@build_dir, @target, @toolchain)
46+
@zlib =
47+
add_product RubyWasm::ZlibProduct.new(@build_dir, @target, @toolchain)
48+
@source = add_product RubyWasm::BuildSource.new(src, @build_dir)
49+
@baseruby = add_product RubyWasm::BaseRubyProduct.new(@build_dir, @source)
2650

2751
build_params =
2852
RubyWasm::BuildParams.new(
2953
options.merge(
3054
name: name,
31-
src: source,
32-
target: target,
33-
user_exts: extensions
55+
src: @source,
56+
target: @target,
57+
user_exts: @user_exts
3458
)
3559
)
3660

37-
product =
38-
RubyWasm::CrossRubyProduct.new(
39-
build_params,
40-
build_dir,
41-
rubies_dir,
42-
baseruby,
43-
source,
44-
toolchain
45-
)
46-
product.with_libyaml libyaml
47-
product.with_zlib zlib
48-
product.define_task
61+
@crossruby =
62+
add_product RubyWasm::CrossRubyProduct.new(
63+
build_params,
64+
@build_dir,
65+
@rubies_dir,
66+
@baseruby,
67+
@source,
68+
@toolchain
69+
)
70+
@crossruby.with_libyaml @libyaml
71+
@crossruby.with_zlib @zlib
72+
73+
yield self if block_given?
74+
75+
add_product @crossruby
76+
define
4977
end
5078

5179
private
@@ -54,7 +82,12 @@ def add_product(product)
5482
@@products ||= {}
5583
return @@products[product.name] if @@products[product.name]
5684
@@products[product.name] = product
57-
product.define_task
85+
@products_to_define ||= []
86+
@products_to_define << product
5887
product
5988
end
89+
90+
def define
91+
@products_to_define.each(&:define_task)
92+
end
6093
end

0 commit comments

Comments
 (0)