Class: RubyWasm::CrossRubyProduct
- Inherits:
-
AutoconfProduct
- Object
- BuildProduct
- AutoconfProduct
- RubyWasm::CrossRubyProduct
- Defined in:
- lib/ruby_wasm/build/product/crossruby.rb
Instance Attribute Summary collapse
-
#cflags ⇒ Object
Returns the value of attribute cflags.
-
#cppflags ⇒ Object
Returns the value of attribute cppflags.
-
#debugflags ⇒ Object
Returns the value of attribute debugflags.
-
#ldflags ⇒ Object
Returns the value of attribute ldflags.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#toolchain ⇒ Object
readonly
Returns the value of attribute toolchain.
-
#user_exts ⇒ Object
Returns the value of attribute user_exts.
-
#wasmoptflags ⇒ Object
Returns the value of attribute wasmoptflags.
-
#xcflags ⇒ Object
Returns the value of attribute xcflags.
-
#xldflags ⇒ Object
Returns the value of attribute xldflags.
Instance Method Summary collapse
- #artifact ⇒ Object
- #baseruby_path ⇒ Object
- #build(executor, remake: false, reconfigure: false) ⇒ Object
- #build_dir ⇒ Object
- #build_exts(executor) ⇒ Object
- #cache_key(digest) ⇒ Object
- #clean(executor) ⇒ Object
- #configure(executor, reconfigure: false) ⇒ Object
- #configure_args(build_triple, toolchain) ⇒ Object
- #dest_dir ⇒ Object
- #ext_build_dir ⇒ Object
- #extinit_c_erb ⇒ Object
- #extinit_obj ⇒ Object
-
#initialize(params, build_dir, rubies_dir, baseruby, source, toolchain) ⇒ CrossRubyProduct
constructor
A new instance of CrossRubyProduct.
- #name ⇒ Object
- #need_extinit_obj? ⇒ Boolean
- #need_exts_build? ⇒ Boolean
- #with_libyaml(libyaml) ⇒ Object
- #with_openssl(openssl) ⇒ Object
- #with_wasi_vfs(wasi_vfs) ⇒ Object
- #with_zlib(zlib) ⇒ Object
Methods inherited from AutoconfProduct
#system_triplet_args, #tools_args
Constructor Details
#initialize(params, build_dir, rubies_dir, baseruby, source, toolchain) ⇒ CrossRubyProduct
Returns a new instance of CrossRubyProduct.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 153 def initialize(params, build_dir, rubies_dir, baseruby, source, toolchain) @params = params @rubies_dir = rubies_dir @build_dir = build_dir @baseruby = baseruby @source = source @toolchain = toolchain @user_exts = [] @wasmoptflags = [] @cppflags = [] @cflags = [] @ldflags = [] @debugflags = [] @xcflags = [] @xldflags = [] super(@params.target, @toolchain) end |
Instance Attribute Details
#cflags ⇒ Object
Returns the value of attribute cflags.
144 145 146 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 144 def cflags @cflags end |
#cppflags ⇒ Object
Returns the value of attribute cppflags.
144 145 146 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 144 def cppflags @cppflags end |
#debugflags ⇒ Object
Returns the value of attribute debugflags.
144 145 146 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 144 def debugflags @debugflags end |
#ldflags ⇒ Object
Returns the value of attribute ldflags.
144 145 146 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 144 def ldflags @ldflags end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
143 144 145 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 143 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
143 144 145 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 143 def target @target end |
#toolchain ⇒ Object (readonly)
Returns the value of attribute toolchain.
143 144 145 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 143 def toolchain @toolchain end |
#user_exts ⇒ Object
Returns the value of attribute user_exts.
144 145 146 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 144 def user_exts @user_exts end |
#wasmoptflags ⇒ Object
Returns the value of attribute wasmoptflags.
144 145 146 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 144 def wasmoptflags @wasmoptflags end |
#xcflags ⇒ Object
Returns the value of attribute xcflags.
144 145 146 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 144 def xcflags @xcflags end |
#xldflags ⇒ Object
Returns the value of attribute xldflags.
144 145 146 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 144 def xldflags @xldflags end |
Instance Method Details
#artifact ⇒ Object
293 294 295 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 293 def artifact File.join(@rubies_dir, "#{name}.tar.gz") end |
#baseruby_path ⇒ Object
305 306 307 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 305 def baseruby_path File.join(@baseruby.install_dir, "bin/ruby") end |
#build(executor, remake: false, reconfigure: false) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 196 def build(executor, remake: false, reconfigure: false) executor.mkdir_p dest_dir executor.mkdir_p build_dir @toolchain.install [@source, @baseruby, @libyaml, @zlib, @openssl, @wasi_vfs].each do |prod| next unless prod executor.begin_section prod.class, prod.name, "Building" prod.build(executor) executor.end_section prod.class, prod.name end executor.begin_section self.class, name, "Configuring" configure(executor, reconfigure: reconfigure) executor.end_section self.class, name build_exts(executor) if need_exts_build? executor.begin_section self.class, name, "Building" if need_extinit_obj? executor.mkdir_p File.dirname(extinit_obj) executor.system "ruby", extinit_c_erb, *@user_exts.map { |ext| ext.feature_name(self) }, "--cc", toolchain.cc, "--output", extinit_obj end install_dir = File.join(build_dir, "install") if !File.exist?(install_dir) || remake || reconfigure executor.system "make", "-j#{executor.process_count}", "install", "DESTDIR=#{install_dir}", chdir: build_dir end executor.rm_rf dest_dir executor.cp_r install_dir, dest_dir @user_exts.each { |ext| ext.do_install_rb(executor, self) } executor.system "tar", "cfz", artifact, "-C", @rubies_dir, name executor.end_section self.class, name end |
#build_dir ⇒ Object
265 266 267 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 265 def build_dir File.join(@build_dir, @params.target.to_s, name) end |
#build_exts(executor) ⇒ Object
188 189 190 191 192 193 194 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 188 def build_exts(executor) @user_exts.each do |prod| executor.begin_section prod.class, prod.name, "Building" prod.build(executor, self, []) executor.end_section prod.class, prod.name end end |
#cache_key(digest) ⇒ Object
252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 252 def cache_key(digest) @params.target.cache_key(digest) digest << @params.default_exts @wasmoptflags.each { |f| digest << f } @cppflags.each { |f| digest << f } @cflags.each { |f| digest << f } @ldflags.each { |f| digest << f } @debugflags.each { |f| digest << f } @xcflags.each { |f| digest << f } @xldflags.each { |f| digest << f } @user_exts.each { |ext| ext.cache_key(digest) } end |
#clean(executor) ⇒ Object
241 242 243 244 245 246 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 241 def clean(executor) executor.rm_rf dest_dir executor.rm_rf build_dir executor.rm_rf ext_build_dir executor.rm_f artifact end |
#configure(executor, reconfigure: false) ⇒ Object
171 172 173 174 175 176 177 178 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 171 def configure(executor, reconfigure: false) if !File.exist?("#{build_dir}/Makefile") || reconfigure args = configure_args(RbConfig::CONFIG["host"], toolchain) executor.system source.configure_file, *args, chdir: build_dir end # NOTE: we need rbconfig.rb at configuration time to build user given extensions with mkmf executor.system "make", "rbconfig.rb", chdir: build_dir end |
#configure_args(build_triple, toolchain) ⇒ Object
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 309 def configure_args(build_triple, toolchain) target = @params.target.triple default_exts = @params.default_exts ldflags = @ldflags.dup xldflags = @xldflags.dup args = self.system_triplet_args + ["--build", build_triple] args << "--with-static-linked-ext" unless @params.target.pic? args << %Q(--with-ext=#{default_exts}) args << %Q(--with-libyaml-dir=#{@libyaml.install_root}) args << %Q(--with-zlib-dir=#{@zlib.install_root}) args << %Q(--with-openssl-dir=#{@openssl.install_root}) if @openssl args << %Q(--with-baseruby=#{baseruby_path}) case target when /^wasm32-unknown-wasi/ xldflags << @wasi_vfs.lib_wasi_vfs_a if @wasi_vfs # TODO: Find a way to force cast or update API # @type var wasi_sdk_path: untyped wasi_sdk_path = @toolchain args << %Q(WASMOPT=#{wasi_sdk_path.wasm_opt}) args << %Q(WASI_SDK_PATH=#{wasi_sdk_path.wasi_sdk_path}) when "wasm32-unknown-emscripten" ldflags.concat(%w[-s MODULARIZE=1]) env_emcc_ldflags = ENV["RUBY_WASM_EMCC_LDFLAGS"] || "" unless env_emcc_ldflags.empty? ldflags << env_emcc_ldflags end else raise "unknown target: #{target}" end args.concat(self.tools_args) (@user_exts || []).each { |lib| xldflags << "@#{lib.linklist(self)}" } xldflags << extinit_obj if need_extinit_obj? cflags = @cflags.dup xcflags = @xcflags.dup xcflags << "-DWASM_SETJMP_STACK_BUFFER_SIZE=24576" xcflags << "-DWASM_FIBER_STACK_BUFFER_SIZE=24576" xcflags << "-DWASM_SCAN_STACK_BUFFER_SIZE=24576" args << %Q(LDFLAGS=#{ldflags.join(" ")}) args << %Q(XLDFLAGS=#{xldflags.join(" ")}) args << %Q(CFLAGS=#{cflags.join(" ")}) args << %Q(XCFLAGS=#{xcflags.join(" ")}) args << %Q(debugflags=#{@debugflags.join(" ")}) args << %Q(cppflags=#{@cppflags.join(" ")}) unless wasmoptflags.empty? args << %Q(wasmoptflags=#{@wasmoptflags.join(" ")}) end args << "--disable-install-doc" args end |
#dest_dir ⇒ Object
289 290 291 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 289 def dest_dir File.join(@rubies_dir, name) end |
#ext_build_dir ⇒ Object
269 270 271 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 269 def ext_build_dir File.join(@build_dir, @params.target.to_s, name + "-ext") end |
#extinit_c_erb ⇒ Object
301 302 303 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 301 def extinit_c_erb File.("../crossruby/extinit.c.erb", __FILE__) end |
#extinit_obj ⇒ Object
297 298 299 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 297 def extinit_obj "#{ext_build_dir}/extinit.o" end |
#name ⇒ Object
248 249 250 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 248 def name @params.name end |
#need_extinit_obj? ⇒ Boolean
184 185 186 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 184 def need_extinit_obj? need_exts_build? && !@target.pic? end |
#need_exts_build? ⇒ Boolean
180 181 182 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 180 def need_exts_build? @user_exts.any? end |
#with_libyaml(libyaml) ⇒ Object
273 274 275 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 273 def with_libyaml(libyaml) @libyaml = libyaml end |
#with_openssl(openssl) ⇒ Object
285 286 287 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 285 def with_openssl(openssl) @openssl = openssl end |
#with_wasi_vfs(wasi_vfs) ⇒ Object
281 282 283 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 281 def with_wasi_vfs(wasi_vfs) @wasi_vfs = wasi_vfs end |
#with_zlib(zlib) ⇒ Object
277 278 279 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 277 def with_zlib(zlib) @zlib = zlib end |