Skip to content

ruby-head-wasm-wasi build fails on current Ruby head because cross build runs wasm dump_ast instead of host dump_ast #629

@ledsun

Description

@ledsun

Summary

Building ruby-head-wasm-wasi against current Ruby head fails during .rbinc generation in the cross build.
The failure occurs because the build executes ./dump_ast, which is a wasm binary, instead of a host-built dump_ast.

Although Ruby head supports providing a host dump_ast via --with-dump-ast, the generated Makefile still uses the target-side binary when it is not specified.

Environment

The Ruby source used by the failing build was:

This reproduces on a clean build with:

rm -rf build
rake npm:ruby-head-wasm-wasi

Results:

./dump_ast: 151: Syntax error: "(" unexpected
make: *** [uncommon.mk:1307: /home/ledsun/ruby.wasm/build/checkouts/head/io.rbinc] Error 1
Try running with `rake --verbose` for more complete output.
bundler: failed to load command: /home/ledsun/ruby.wasm/exe/rbwasm (/home/ledsun/ruby.wasm/exe/rbwasm)
/home/ledsun/ruby.wasm/lib/ruby_wasm/build/executor.rb:77:in 'RubyWasm::BuildExecutor#system': Command failed with status (2): 'make' '-j8' 'install' 'DESTDIR=/home/ledsun/ruby.wasm/build/wasm32-unknown-wasip1/ruby-head-wasm32-unknown-wasip1-full-61ff6b0c74de0393d023cecfb9d1d7be/install' (RuntimeError)
        from /home/ledsun/ruby.wasm/lib/ruby_wasm/build/product/crossruby.rb:238:in 'RubyWasm::CrossRubyProduct#build'

Related change

This behavior appears after:

This change introduces support for --with-dump-ast, but the fallback behavior still uses ./dump_ast even in cross builds.
The generated Makefile contains:

DUMP_AST = ./dump_ast$(EXEEXT)

As a result, .rbinc generation invokes the target-side dump_ast instead of a host executable.

Proposed fix

Pass the host-built dump_ast explicitly to configure:

--with-dump-ast=/path/to/host/baseruby-build/dump_ast

This ensures .rbinc generation uses a host executable.

ruby.wasm already passes --with-baseruby, so it can also pass --with-dump-ast.

Minimal patch:

diff --git a/lib/ruby_wasm/build/product/crossruby.rb b/lib/ruby_wasm/build/product/crossruby.rb
@@
     def baseruby_path
       File.join(@baseruby.install_dir, "bin/ruby")
     end
+
+    def dump_ast_path
+      File.join(@baseruby.product_build_dir, "dump_ast")
+    end
@@
       args << %Q(--with-zlib-dir=#{@zlib.install_root})
       args << %Q(--with-openssl-dir=#{@openssl.install_root}) if @openssl
       args << %Q(--with-baseruby=#{baseruby_path})
+      args << %Q(--with-dump-ast=#{dump_ast_path})

This resolves the issue by avoiding execution of the wasm dump_ast.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions