2
2
require_relative "./build_system"
3
3
4
4
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
+
5
27
def initialize (
6
28
name ,
7
29
target :,
8
30
src :,
9
- extensions : [ ] ,
31
+ user_exts : [ ] ,
10
32
toolchain : nil ,
11
33
build_dir : nil ,
12
34
rubies_dir : nil ,
13
- **options ,
14
- &task_block
35
+ **options
15
36
)
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
19
43
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)
26
50
27
51
build_params =
28
52
RubyWasm ::BuildParams . new (
29
53
options . merge (
30
54
name : name ,
31
- src : source ,
32
- target : target ,
33
- user_exts : extensions
55
+ src : @ source,
56
+ target : @ target,
57
+ user_exts : @user_exts
34
58
)
35
59
)
36
60
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
49
77
end
50
78
51
79
private
@@ -54,7 +82,12 @@ def add_product(product)
54
82
@@products ||= { }
55
83
return @@products [ product . name ] if @@products [ product . name ]
56
84
@@products [ product . name ] = product
57
- product . define_task
85
+ @products_to_define ||= [ ]
86
+ @products_to_define << product
58
87
product
59
88
end
89
+
90
+ def define
91
+ @products_to_define . each ( &:define_task )
92
+ end
60
93
end
0 commit comments