Skip to content

Conversation

@nishidayuya
Copy link
Contributor

Thanks for your useful post and this repository.

This pull-request makes this repository runnable on zig-0.14.0 (currently released version).

tested versions

yuya@yoshiyuki|22:39:22|0|12.10% zig version
0.14.0
yuya@yoshiyuki|22:41:35|0|12.10% ruby -v
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +YJIT +PRISM [x86_64-linux]

before pull-request

run "rake benchmark" => build error
yuya@yoshiyuki|22:41:39|0|12.10% git rev-parse HEAD
621b6188ca89f7cffd525cb741f0a05cd31a32ee
yuya@yoshiyuki|22:42:16|0|12.10% rake benchmark
cd ext/zig_rb
/home/yuya/.local/share/mise/installs/ruby/3.4.3/bin/ruby extconf.rb
make
RUBY_LIBDIR=/home/yuya/.local/share/mise/installs/ruby/3.4.3/lib RUBY_HDRDIR=/home/yuya/.local/share/mise/installs/ruby/3.4.3/include/ruby-3.4.0 RUBY_ARCHHDRDIR=/home/yuya/.local/share/mise/installs/ruby/3.4.3/include/ruby-3.4.0/x86_64-linux zig build -Doptimize=ReleaseFast
/home/yuya/src/github.com/katafrakt/zig-ruby/ext/zig_rb/build.zig:16:9: error: local variable is never mutated
    var ruby_archhdrdir = std.os.getenv("RUBY_ARCHHDRDIR") orelse "";
        ^~~~~~~~~~~~~~~
/home/yuya/src/github.com/katafrakt/zig-ruby/ext/zig_rb/build.zig:16:9: note: consider using 'const'
/home/yuya/src/github.com/katafrakt/zig-ruby/ext/zig_rb/build.zig:14:9: error: local variable is never mutated
    var ruby_hdrdir = std.os.getenv("RUBY_HDRDIR") orelse "";
        ^~~~~~~~~~~
/home/yuya/src/github.com/katafrakt/zig-ruby/ext/zig_rb/build.zig:14:9: note: consider using 'const'
/home/yuya/src/github.com/katafrakt/zig-ruby/ext/zig_rb/build.zig:12:9: error: local variable is never mutated
    var ruby_libdir = std.os.getenv("RUBY_LIBDIR") orelse "";
        ^~~~~~~~~~~
/home/yuya/src/github.com/katafrakt/zig-ruby/ext/zig_rb/build.zig:12:9: note: consider using 'const'
/home/yuya/src/github.com/katafrakt/zig-ruby/ext/zig_rb/build.zig:3:21: error: root source file struct 'std' has no member named 'build'
pub fn build(b: *std.build.Builder) void {
                 ~~~^~~~~~
/home/yuya/.local/share/mise/installs/zig/0.14.0/lib/std/std.zig:1:1: note: struct declared here
pub const ArrayHashMap = array_hash_map.ArrayHashMap;
^~~
referenced by:
    runBuild__anon_24691: /home/yuya/.local/share/mise/installs/zig/0.14.0/lib/std/Build.zig:2426:50
    main: /home/yuya/.local/share/mise/installs/zig/0.14.0/lib/compiler/build_runner.zig:339:29
    5 reference(s) hidden; use '-freference-trace=7' to see all references
make: *** [Makefile:2: all] Error 2
rake aborted!
Command failed with status (2): [make]
/home/yuya/src/github.com/katafrakt/zig-ruby/Rakefile:4:in 'block (2 levels) in <top (required)>'
/home/yuya/src/github.com/katafrakt/zig-ruby/Rakefile:2:in 'block in <top (required)>'
Tasks: TOP => benchmark => compile_ext
(See full trace by running task with --trace)

after pull-request

yuya@yoshiyuki|22:43:54|0|12.10% rake benchmark
cd ext/zig_rb
/home/yuya/.local/share/mise/installs/ruby/3.4.3/bin/ruby extconf.rb
make
RUBY_LIBDIR=/home/yuya/.local/share/mise/installs/ruby/3.4.3/lib RUBY_HDRDIR=/home/yuya/.local/share/mise/installs/ruby/3.4.3/include/ruby-3.4.0 RUBY_ARCHHDRDIR=/home/yuya/.local/share/mise/installs/ruby/3.4.3/include/ruby-3.4.0/x86_64-linux zig build -Doptimize=ReleaseFast
cd -
/home/yuya/.local/share/mise/installs/ruby/3.4.3/bin/ruby benchmark.rb
Ruby: 10, Zig: 10
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +YJIT +PRISM [x86_64-linux]
Warming up --------------------------------------
                Ruby     1.346k i/100ms
                 Zig   211.201k i/100ms
Calculating -------------------------------------
                Ruby     14.490k (± 5.0%) i/s   (69.01 μs/i) -     72.684k in   5.031102s
                 Zig      2.096M (± 6.8%) i/s  (477.03 ns/i) -     10.560M in   5.062901s

Comparison:
                 Zig:  2096306.1 i/s
                Ruby:    14490.5 i/s - 144.67x  slower

@katafrakt
Copy link
Owner

Hey! Sorry for a delayed answer. This is a great follow up to my post.
I finally had a chance to try it out myself and it works great ❤️ Thanks a lot!

@katafrakt katafrakt merged commit 39d7a46 into katafrakt:main Jun 3, 2025
@nishidayuya nishidayuya deleted the follow_zig_0.14.0 branch June 13, 2025 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants