rabbit-slide-nishidayuya-2025-04-17-agileware_drinkup_at_rubykaigi2025-ruby_extension_using_zig 2025.4.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 63362863a98b22fa2497349684c2ad9349d1a70b5daa7d4f5785ab923bdf7b8d
4
+ data.tar.gz: ba8dbe04f306ab284b2614af3b9499ef76d1d4843adf039ec5faaa0c09b45440
5
+ SHA512:
6
+ metadata.gz: ebdc92b40a2c529361d746fd2b75cba6302fdb7c1f0cd0ec8e2727e4d00be70486ddb0e60b61f99df6e3cf4817ae365a178907578c60d8d13c9758188b48de46
7
+ data.tar.gz: 1cf25b618954b75ef956dc1bc73411c6adbe3dd1f4930d880cafb65148e2be7f31dc89cb04235f6dde3faa98097d416d5def26053d262613bf16a78b7011c33a
data/.rabbit ADDED
@@ -0,0 +1,2 @@
1
+ --size 1280,800
2
+ ruby_extension_using_zig.md
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # Write Ruby extension using Zig
2
+
3
+ 2025-04-17に開催された[Agileware Drinkup at RubyKaigi 2025](https://agileware.connpass.com/event/348923/)のLT枠での発表資料
4
+
5
+ ## 作者向け
6
+
7
+ ### 表示
8
+
9
+ rake
10
+
11
+ ### 公開
12
+
13
+ rake publish
14
+
15
+ ## 閲覧者向け
16
+
17
+ ### インストール
18
+
19
+ gem install rabbit-slide-nishidayuya-2025-04-17-agileware_drinkup_at_rubykaigi2025-ruby_extension_using_zig
20
+
21
+ ### 表示
22
+
23
+ rabbit rabbit-slide-nishidayuya-2025-04-17-agileware_drinkup_at_rubykaigi2025-ruby_extension_using_zig.gem
24
+
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require "rabbit/task/slide"
2
+
3
+ # Edit ./config.yaml to customize meta data
4
+
5
+ spec = nil
6
+ Rabbit::Task::Slide.new do |task|
7
+ spec = task.spec
8
+ # spec.files += Dir.glob("doc/**/*.*")
9
+ # spec.files -= Dir.glob("private/**/*.*")
10
+ # spec.add_runtime_dependency("rabbit-theme-YOUR-THEME")
11
+ end
12
+
13
+ desc "Tag #{spec.version}"
14
+ task :tag do
15
+ sh("git", "tag", "-a", spec.version.to_s, "-m", "Publish #{spec.version}")
16
+ sh("git", "push", "--tags")
17
+ end
data/config.yaml ADDED
@@ -0,0 +1,27 @@
1
+ ---
2
+ id: 2025-04-17-agileware_drinkup_at_rubykaigi2025-ruby_extension_using_zig
3
+ base_name: ruby_extension_using_zig
4
+ tags:
5
+ - ruby
6
+ - ruby_extension
7
+ - zig
8
+ presentation_date: '2025-04-17'
9
+ presentation_start_time:
10
+ presentation_end_time:
11
+ version: 2025.4.17.0
12
+ licenses:
13
+ - CC-BY-4.0
14
+ slideshare_id:
15
+ speaker_deck_id:
16
+ vimeo_id:
17
+ youtube_id:
18
+ width: 1280
19
+ height: 800
20
+ source_code_uri:
21
+ author:
22
+ markup_language: :markdown
23
+ name: Yuya.Nishida.
24
+ email:
25
+ rubygems_user: nishidayuya
26
+ slideshare_user:
27
+ speaker_deck_user: nishidayuya
Binary file
@@ -0,0 +1,174 @@
1
+ # Write Ruby extension using Zig
2
+
3
+ author
4
+ : @nishidayuya
5
+
6
+ date
7
+ : 2025-04-17
8
+ Agileware Drinkup at RubyKaigi 2025 LT
9
+
10
+ allotted-time
11
+ : 5m
12
+
13
+ theme
14
+ : lightning-simple
15
+
16
+ start-time
17
+ : 2025-04-17
18
+
19
+ end-time
20
+ : 2025-04-17
21
+
22
+ # @nishidayuya (GitHub, X)
23
+
24
+ - NaCl's programmer. Matz is our fellow.
25
+ - from Ruby City Matz-e(松江市)
26
+ - now Matz-yama city(松山市)
27
+ - i collected RubyKaigi 2024 X posts.
28
+ - from `#rubykaigiA #rubykaigiB #rubykaigiC #rubykaigi #rubykaigi2024`
29
+ - to https://togetter.com/li/2369438
30
+ - i will collect RubyKaigi 2025's, too! (posfie)
31
+
32
+ # main issue
33
+
34
+ # Write Ruby extension using Zig
35
+
36
+ # what? Write Ruby extension using Zig
37
+
38
+ - many Ruby extension using C.
39
+ - Rust can write, too:
40
+ - `bundle gem --ext=rust foo`
41
+ - since bundler-3.4.0 (ruby-3.2.0 is bundled)
42
+
43
+ # what's Zig?
44
+
45
+ - a programming language.
46
+ - Zig can write dynamic link library as C, Rust, and so on.
47
+
48
+
49
+
50
+ - Zig can write Ruby extension, I think 🤔
51
+
52
+
53
+
54
+ - try it!
55
+
56
+ # today, i will:
57
+
58
+ - write a method, by Zig code.
59
+ - call it.
60
+ - then output return value.
61
+
62
+ ```console
63
+ ruby -r./zig-out/lib/libzig_ruby_module.so \
64
+ -e 'p(ZigRubyModule.add(1, 2))'
65
+ ```
66
+
67
+ # step0: run "zig init"
68
+
69
+ ```console
70
+ $ zig init
71
+ info: created build.zig
72
+ info: created build.zig.zon
73
+ info: created src/main.zig
74
+ info: created src/root.zig
75
+ info: see `zig build --help` for a menu of options
76
+ ```
77
+
78
+ # step1: write entrypoint
79
+
80
+ `Init_{so name}` function
81
+
82
+ ```
83
+ const ruby = @cImport(@cInclude("ruby/ruby.h"));
84
+ //...
85
+ pub export fn Init_libzig_ruby_module() void {
86
+ const rb_mZigRubyModule =
87
+ ruby.rb_define_module("ZigRubyModule");
88
+ ruby.rb_define_singleton_method(
89
+ rb_mZigRubyModule,
90
+ "add",
91
+ rb_mZigRubyModule_s_add,
92
+ 2,
93
+ );
94
+ }
95
+ ```
96
+
97
+ # step2: implement method
98
+
99
+ ```
100
+ fn rb_mZigRubyModule_s_add(...) callconv(.c) ruby.VALUE {
101
+ var ap = @cVaStart();
102
+ defer @cVaEnd(&ap);
103
+
104
+ _ = @cVaArg(&ap, ruby.VALUE); // dummy
105
+ const o1 = @cVaArg(&ap, ruby.VALUE);
106
+ const o2 = @cVaArg(&ap, ruby.VALUE);
107
+ const n1 = ruby.NUM2INT(o1);
108
+ const n2 = ruby.NUM2INT(o2);
109
+ const sum = add(n1, n2);
110
+ return ruby.INT2NUM(sum);
111
+ }
112
+ ```
113
+
114
+ # step3: fix build rule
115
+
116
+ ```diff
117
+ diff --git a/build.zig b/build.zig
118
+ index d8a38d8..62eb5c3 100644
119
+ --- a/build.zig
120
+ +++ b/build.zig
121
+ @@ -48,10 +48,17 @@ pub fn build(b: *std.Build) void {
122
+ // This creates a `std.Build.Step.Compile`, which is the build step responsible
123
+ // for actually invoking the compiler.
124
+ const lib = b.addLibrary(.{
125
+ - .linkage = .static,
126
+ + .linkage = .dynamic,
127
+ .name = "zig_ruby_module",
128
+ .root_module = lib_mod,
129
+ });
130
+ + // ruby -rmkmf -e 'p(RbConfig::CONFIG["libdir"])'
131
+ + lib.addLibraryPath(std.Build.LazyPath{ .cwd_relative = "/home/yuya/.local/share/mise/installs/ruby/3.4.3/lib" });
132
+ + // ruby -rmkmf -e 'p(RbConfig::CONFIG["rubyhdrdir"])'
133
+ + lib.addIncludePath(std.Build.LazyPath{ .cwd_relative = "/home/yuya/.local/share/mise/installs/ruby/3.4.3/include/ruby-3.4.0" });
134
+ + // ruby -rmkmf -e 'p(RbConfig::CONFIG["rubyarchhdrdir"])'
135
+ + lib.addIncludePath(std.Build.LazyPath{ .cwd_relative = "/home/yuya/.local/share/mise/installs/ruby/3.4.3/include/ruby-3.4.0/x86_64-linux" });
136
+ + lib.linkSystemLibrary("c");
137
+
138
+ // This declares intent for the library to be installed into the standard
139
+ // location when the user invokes the "install" step (the default step when
140
+ ```
141
+
142
+ # demo
143
+
144
+ # demo
145
+
146
+ - `zig init`
147
+ - write `Init_libzig_ruby_module`
148
+ - implement method
149
+ - `fn rb_mZigRubyModule_s_add(...) callconv(.c) ruby.VALUE {`
150
+ - fix build rule
151
+ - `ruby -r./zig-out/lib/libzig_ruby_module.so -e 'p(ZigRubyModule.add(1, 2))'`
152
+
153
+ # congrats! 🎉
154
+
155
+ # i was writing CFP for RubyKaigi 2025,
156
+
157
+ # , but...
158
+
159
+ # i was writing CFP for RubyKaigi 2025, but...
160
+
161
+ ![](images/katafrakt_me_2022_12_25.png){:height='250'}
162
+
163
+ - i found a blog:
164
+ - written by Paweł Świątkowski on 2022-12-25!
165
+ - ~~(zig-0.14.0 (current version) cannot build it.)~~
166
+ - i sent pull-request to fix it.
167
+
168
+ # i was writing CFP for RubyKaigi 2025, but...
169
+
170
+ # i wrote WHEEL! 🛞
171
+
172
+ # i could not write CFP. 😭
173
+
174
+ # Thanks! \\n by @nishidayuya
@@ -0,0 +1,76 @@
1
+ # Rubyの拡張ライブラリをプログラミング言語Zigで書く
2
+
3
+ author
4
+ : 西田雄也
5
+
6
+ date
7
+ : 2025-04-17
8
+ Agileware Drinkup at RubyKaigi 2025 LT
9
+
10
+ allotted-time
11
+ : 5m
12
+
13
+ theme
14
+ : lightning-simple
15
+
16
+ start-time
17
+ : 2025-04-17
18
+
19
+ end-time
20
+ : 2025-04-17
21
+
22
+ # 自己紹介
23
+
24
+ - 西田雄也
25
+ - GitHub・X: `@nishidayuya`
26
+ - ネットワーク応用通信研究所
27
+ - Matz江市からMatz山市に参上
28
+ - [RubyKaigi2024のXポストまとめました](https://togetter.com/li/2369438)
29
+ - 今年もまとめます!
30
+
31
+ # さて
32
+
33
+ # 本題
34
+
35
+ # Rubyの拡張ライブラリをZigで書く
36
+
37
+ # どういうことか? Rubyの拡張ライブラリをZigで書く
38
+
39
+ - CのライブラリをRubyから呼び出せるための仕組み→拡張ライブラリ
40
+ - 多くはC言語で書かれている.
41
+ - Rustでも書ける:
42
+ - `bundle gem --ext=rust foo`
43
+ - ruby-3.2.0で同梱されたbundler-3.4.0以降
44
+
45
+ # Zigってなに?
46
+
47
+ - プログラミング言語の一つ
48
+ - C言語やRustと同様にCのライブラリが書ける
49
+ - Cのライブラリが書けるってことはRubyの拡張ライブラリが書けるのでは?
50
+
51
+
52
+
53
+ - やってみた
54
+
55
+ # 今日やること
56
+
57
+ ```console
58
+ ruby -r./zig-out/lib/libzig_ruby_module.so \
59
+ -e 'p(ZigRubyModule.add(1, 2))'
60
+ 3
61
+ ```
62
+
63
+ Zigで書いたメソッドを呼び出してその戻り値をpで出力
64
+
65
+ # ライブコーディング
66
+
67
+ # やったーできたー
68
+
69
+ - RubyKaigi2025のCFPを出そうとした...が
70
+ - Pawełさんという方が2022-12-25にされてた
71
+
72
+
73
+
74
+ - 新規性がなさすぎる...断念 m(_ _)m
75
+
76
+ # ご静聴ありがとうございました
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rabbit-slide-nishidayuya-2025-04-17-agileware_drinkup_at_rubykaigi2025-ruby_extension_using_zig
3
+ version: !ruby/object:Gem::Version
4
+ version: 2025.4.17.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuya.Nishida.
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rabbit
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 2.0.2
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 2.0.2
26
+ description: 2025-04-17に開催された[Agileware Drinkup at RubyKaigi 2025](https://agileware.connpass.com/event/348923/)のLT枠での発表資料
27
+ email:
28
+ -
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".rabbit"
34
+ - README.md
35
+ - Rakefile
36
+ - config.yaml
37
+ - images/katafrakt_me_2022_12_25.png
38
+ - pdf/2025-04-17-agileware_drinkup_at_rubykaigi2025-ruby_extension_using_zig-ruby_extension_using_zig.pdf
39
+ - ruby_extension_using_zig.md
40
+ - ruby_extension_using_zig.wip.ja.md
41
+ homepage: https://slide.rabbit-shocker.org/authors/nishidayuya/2025-04-17-agileware_drinkup_at_rubykaigi2025-ruby_extension_using_zig/
42
+ licenses:
43
+ - CC-BY-4.0
44
+ metadata: {}
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.6.7
60
+ specification_version: 4
61
+ summary: Write Ruby extension using Zig
62
+ test_files: []