Skip to content

Commit 263e2b7

Browse files
make user_exts configurable in task block
1 parent 9b1edba commit 263e2b7

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

Rakefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ namespace :build do
5656
end
5757
options = params
5858
.merge(BUILD_PROFILES[params[:profile]])
59-
.merge(name: name, src: source, user_exts: user_exts, toolchain: toolchain)
59+
.merge(name: name, src: source, toolchain: toolchain)
6060
options.delete :profile
61-
RubyWasm::BuildTask.new(name, **options)
61+
options.delete :user_exts
62+
RubyWasm::BuildTask.new(name, **options) do |t|
63+
t.crossruby.user_exts = user_exts
64+
end
6265
end
6366
end

lib/ruby_wasm/build_system/build_params.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ module RubyWasm
22
BuildParams =
33
Struct.new(
44
:name,
5-
:src,
65
:target,
76
:debug,
87
:default_exts,
9-
:user_exts,
108
:wasmoptflags,
119
keyword_init: true
1210
)

lib/ruby_wasm/build_system/product/crossruby.rb

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,25 @@ def define_task(crossruby)
6262

6363
class CrossRubyProduct < BuildProduct
6464
attr_reader :source, :toolchain, :build, :configure
65-
66-
def initialize(params, build_dir, rubies_dir, baseruby, source, toolchain)
65+
attr_accessor :user_exts
66+
67+
def initialize(
68+
params,
69+
build_dir,
70+
rubies_dir,
71+
baseruby,
72+
source,
73+
toolchain,
74+
user_exts: []
75+
)
6776
@params = params
6877
@rubies_dir = rubies_dir
6978
@build_dir = build_dir
7079
@baseruby = baseruby
7180
@source = source
7281
@toolchain = toolchain
7382
@dep_tasks = []
83+
@user_exts = user_exts
7484
end
7585

7686
def define_task
@@ -92,12 +102,12 @@ def define_task
92102
sh "make rbconfig.rb", chdir: build_dir
93103
end
94104

95-
user_ext_products = @params.user_exts
96-
user_ext_tasks = user_ext_products.map { |prod| prod.define_task(self) }
105+
user_ext_products = @user_exts
106+
user_ext_tasks = @user_exts.map { |prod| prod.define_task(self) }
97107
extinit_task =
98108
task extinit_obj => [@configure, extinit_c_erb] + user_ext_tasks do
99109
mkdir_p File.dirname(extinit_obj)
100-
sh %Q(ruby #{extinit_c_erb} #{user_ext_products.map(&:name).join(" ")} | #{toolchain.cc} -c -x c - -o #{extinit_obj})
110+
sh %Q(ruby #{extinit_c_erb} #{@user_exts.map(&:name).join(" ")} | #{toolchain.cc} -c -x c - -o #{extinit_obj})
101111
end
102112

103113
install =
@@ -115,7 +125,7 @@ def define_task
115125
ruby_api_version =
116126
`#{baseruby_path} -e 'print RbConfig::CONFIG["ruby_version"]'`
117127
# TODO: move copying logic to ext product
118-
user_ext_products.each do |ext|
128+
@user_exts.each do |ext|
119129
ext_lib = File.join(ext.srcdir, "lib")
120130
next unless File.exist?(ext_lib)
121131
cp_r(
@@ -173,7 +183,6 @@ def dep_tasks
173183
def configure_args(build_triple, toolchain)
174184
target = @params.target
175185
default_exts = @params.default_exts
176-
user_exts = @params.user_exts
177186

178187
ldflags =
179188
if @params.debug
@@ -204,7 +213,7 @@ def configure_args(build_triple, toolchain)
204213
raise "unknown target: #{target}"
205214
end
206215

207-
(user_exts || []).each { |lib| xldflags << "@#{lib.linklist(self)}" }
216+
(@user_exts || []).each { |lib| xldflags << "@#{lib.linklist(self)}" }
208217
xldflags << extinit_obj
209218

210219
xcflags = []

lib/ruby_wasm/rake_task.rb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def initialize(
2828
name,
2929
target:,
3030
src:,
31-
user_exts: [],
3231
toolchain: nil,
3332
build_dir: nil,
3433
rubies_dir: nil,
@@ -39,7 +38,6 @@ def initialize(
3938
@build_dir = build_dir || File.join(Dir.pwd, "build")
4039
@rubies_dir = rubies_dir || File.join(Dir.pwd, "rubies")
4140
@toolchain = toolchain || RubyWasm::Toolchain.get(target)
42-
@user_exts = user_exts
4341

4442
@libyaml =
4543
add_product RubyWasm::LibYAMLProduct.new(@build_dir, @target, @toolchain)
@@ -49,14 +47,7 @@ def initialize(
4947
@baseruby = add_product RubyWasm::BaseRubyProduct.new(@build_dir, @source)
5048

5149
build_params =
52-
RubyWasm::BuildParams.new(
53-
options.merge(
54-
name: name,
55-
src: @source,
56-
target: @target,
57-
user_exts: @user_exts
58-
)
59-
)
50+
RubyWasm::BuildParams.new(options.merge(name: name, target: @target))
6051

6152
@crossruby =
6253
add_product RubyWasm::CrossRubyProduct.new(

0 commit comments

Comments
 (0)