Class: RubyWasm::CrossRubyProduct
- Inherits:
-
AutoconfProduct
- Object
- BuildProduct
- AutoconfProduct
- RubyWasm::CrossRubyProduct
- Includes:
- _Cacheable
- Defined in:
- lib/ruby_wasm/build/product/crossruby.rb,
sig/ruby_wasm/build.rbs
Instance Attribute Summary collapse
-
#cflags ⇒ Array[String]
Returns the value of attribute cflags.
-
#cppflags ⇒ Array[String]
Returns the value of attribute cppflags.
-
#debugflags ⇒ Array[String]
Returns the value of attribute debugflags.
-
#ldflags ⇒ Array[String]
Returns the value of attribute ldflags.
-
#source ⇒ BuildSource
readonly
Returns the value of attribute source.
-
#target ⇒ Target
readonly
Returns the value of attribute target.
-
#toolchain ⇒ Toolchain
readonly
Returns the value of attribute toolchain.
-
#user_exts ⇒ Array[CrossRubyExtProduct]
Returns the value of attribute user_exts.
-
#wasmoptflags ⇒ Array[String]
Returns the value of attribute wasmoptflags.
-
#xcflags ⇒ Array[String]
Returns the value of attribute xcflags.
-
#xldflags ⇒ Array[String]
Returns the value of attribute xldflags.
Instance Method Summary collapse
- #artifact ⇒ String
- #baseruby_path ⇒ String
- #build(executor, remake: false, reconfigure: false) ⇒ void
- #build_dir ⇒ String
- #build_exts(executor) ⇒ void
- #cache_key(digest) ⇒ Object
- #clean(executor) ⇒ void
- #configure(executor, reconfigure: false) ⇒ void
- #configure_args(build_triple, toolchain) ⇒ Array[String]
- #dest_dir ⇒ String
- #dump_ast_path ⇒ String
- #ext_build_dir ⇒ String
- #extinit_c_erb ⇒ String
- #extinit_obj ⇒ String
-
#initialize(params, build_dir, rubies_dir, baseruby, source, toolchain) ⇒ CrossRubyProduct
constructor
A new instance of CrossRubyProduct.
- #name ⇒ String
- #need_extinit_obj? ⇒ Boolean
- #need_exts_build? ⇒ Boolean
- #rbconfig_rb ⇒ String?
- #with_libyaml(libyaml) ⇒ LibYAMLProduct
- #with_openssl(openssl) ⇒ OpenSSLProduct
- #with_wasi_vfs(wasi_vfs) ⇒ WasiVfsProduct?
- #with_zlib(zlib) ⇒ ZlibProduct
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.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 161 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 ⇒ Array[String]
Returns the value of attribute cflags.
152 153 154 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 152 def cflags @cflags end |
#cppflags ⇒ Array[String]
Returns the value of attribute cppflags.
152 153 154 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 152 def cppflags @cppflags end |
#debugflags ⇒ Array[String]
Returns the value of attribute debugflags.
152 153 154 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 152 def debugflags @debugflags end |
#ldflags ⇒ Array[String]
Returns the value of attribute ldflags.
152 153 154 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 152 def ldflags @ldflags end |
#source ⇒ BuildSource (readonly)
Returns the value of attribute source.
151 152 153 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 151 def source @source end |
#target ⇒ Target (readonly)
Returns the value of attribute target.
151 152 153 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 151 def target @target end |
#toolchain ⇒ Toolchain (readonly)
Returns the value of attribute toolchain.
151 152 153 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 151 def toolchain @toolchain end |
#user_exts ⇒ Array[CrossRubyExtProduct]
Returns the value of attribute user_exts.
152 153 154 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 152 def user_exts @user_exts end |
#wasmoptflags ⇒ Array[String]
Returns the value of attribute wasmoptflags.
152 153 154 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 152 def wasmoptflags @wasmoptflags end |
#xcflags ⇒ Array[String]
Returns the value of attribute xcflags.
152 153 154 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 152 def xcflags @xcflags end |
#xldflags ⇒ Array[String]
Returns the value of attribute xldflags.
152 153 154 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 152 def xldflags @xldflags end |
Instance Method Details
#artifact ⇒ String
305 306 307 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 305 def artifact File.join(@rubies_dir, "#{name}.tar.gz") end |
#baseruby_path ⇒ String
321 322 323 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 321 def baseruby_path File.join(@baseruby.install_dir, "bin/ruby") end |
#build(executor, remake: false, reconfigure: false) ⇒ void
This method returns an undefined value.
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 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 204 def build(executor, remake: false, reconfigure: false) executor.mkdir_p dest_dir executor.mkdir_p build_dir @toolchain.install(executor) [@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 unless target.pic? # HACK: force static linking for non-pic target executor.rm_f File.join(build_dir, "ruby") end 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 ⇒ String
277 278 279 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 277 def build_dir File.join(@build_dir, @params.target.to_s, name) end |
#build_exts(executor) ⇒ void
This method returns an undefined value.
196 197 198 199 200 201 202 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 196 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
264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 264 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) ⇒ void
This method returns an undefined value.
253 254 255 256 257 258 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 253 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) ⇒ void
This method returns an undefined value.
179 180 181 182 183 184 185 186 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 179 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) ⇒ Array[String]
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 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 329 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}) # Use the host-built dump_ast so cross builds don't try to execute the # target-side wasm dump_ast while generating .rbinc files. args << %Q(--with-dump-ast=#{dump_ast_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}) # NOTE: wasi-libc 22 and later defines stubs for fchmod and chmod # but they just return ENOTSUP, and ruby's configure doesn't check # the runtime behavior. So we need to tell configure that # these functions are not available. # https://github.com/WebAssembly/wasi-libc/pull/463 args << %Q(ac_cv_func_fchmod=no) args << %Q(ac_cv_func_chmod=no) # TODO: wasi-libc 22 and later started using musl's realpath impl but # it broke Kernel#require on @bjorn3/browser_wasi_shim setup for some # reason. So we disable it for now. args << %Q(ac_cv_func_realpath=no) 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" unless @params.target.pic? # TODO: Remove this hack after dropping Ruby 3.2 support args << "ac_cv_func_dlopen=no" end args end |
#dest_dir ⇒ String
301 302 303 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 301 def dest_dir File.join(@rubies_dir, name) end |
#dump_ast_path ⇒ String
325 326 327 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 325 def dump_ast_path File.join(@baseruby.product_build_dir, "dump_ast") end |
#ext_build_dir ⇒ String
281 282 283 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 281 def ext_build_dir File.join(@build_dir, @params.target.to_s, name + "-ext") end |
#extinit_c_erb ⇒ String
313 314 315 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 313 def extinit_c_erb File.("../crossruby/extinit.c.erb", __FILE__) end |
#extinit_obj ⇒ String
309 310 311 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 309 def extinit_obj "#{ext_build_dir}/extinit.o" end |
#name ⇒ String
260 261 262 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 260 def name @params.name end |
#need_extinit_obj? ⇒ Boolean
192 193 194 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 192 def need_extinit_obj? need_exts_build? && !@target.pic? end |
#need_exts_build? ⇒ Boolean
188 189 190 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 188 def need_exts_build? @user_exts.any? end |
#rbconfig_rb ⇒ String?
317 318 319 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 317 def rbconfig_rb Dir.glob(File.join(dest_dir, "usr/local/lib/ruby/*/wasm32-wasi/rbconfig.rb")).first end |
#with_libyaml(libyaml) ⇒ LibYAMLProduct
285 286 287 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 285 def with_libyaml(libyaml) @libyaml = libyaml end |
#with_openssl(openssl) ⇒ OpenSSLProduct
297 298 299 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 297 def with_openssl(openssl) @openssl = openssl end |
#with_wasi_vfs(wasi_vfs) ⇒ WasiVfsProduct?
293 294 295 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 293 def with_wasi_vfs(wasi_vfs) @wasi_vfs = wasi_vfs end |
#with_zlib(zlib) ⇒ ZlibProduct
289 290 291 |
# File 'lib/ruby_wasm/build/product/crossruby.rb', line 289 def with_zlib(zlib) @zlib = zlib end |