SlideShare a Scribd company logo
1 of 56
Download to read offline
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Ruby bindings 2016
How to create bindings 2016
Kouhei Sutou
ClearCode Inc.
RubyKaigi 2016
2016-09-09
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Acknowledgment
感謝
@SoManyHs and @drbrain
They fixed English
in this slide
@RubyKaigi 2016 Official Party
昨日のパーティーで英語をチェックしてくれた!ありがとう!
Silver sponsorSilver sponsor
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Goal
目標
You become
a new bindings developer
あなたが新しくバインディング開発者になること
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Bindings?
バインディングとは
Glue of (mainly) C and Ruby
主にCとRubyをつなぐもの
You can use features implemented
in C from Ruby
Cで実装された機能をRubyから使える
✓
e.g.: Socket, OpenSSL, YAML, ...
例:ソケット、OpenSSL、YAML…
✓
✓
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Bindings
バインディング
C
Bindings
Ruby require "socket"
socket(2)
Can use socket!
Bindings
require "socket"
socket(2)
Can't use...
Error
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Why should I learn?
なんでバインディング開発者になるの?
To use Ruby in more cases
Rubyをもっといろんな場面で使うため
e.g.: Machine leaning, multimedia, full
text search, cipher and so on
例:機械学習、画像・動画・音声処理、全文検索、暗号
✓
✓
Can use existing features in
Ruby through bindings
バインディングがあると既存のいい機能をRubyで使える
✓
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Incr. bindings developer
バインディング開発者が増えるといいな
Why do I become a bindings
developer?
バインディング開発者になりませんか?
To expand use cases of Ruby!
Rubyを使えるケースを増やすために!
✓
Not just a user for
provided features
提供された機能を使う1ユーザーではなく
✓
✓
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Summary
概要
Ext★ SWIG FFI GI☆
Base
Tech
Ext Ext lib
ffi
lib
ffi
Impl.
by
Hand Gene-
rate
Hand Gene-
rate
★ Extension library(拡張ライブラリー)
☆ GObject Introspection: Recommended(オススメ)
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Demo
デモ
Make powerful
auto generated
bindings
自動生成されたバインディングがいかに強力か
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
What is ext?
拡張ライブラリーってなに?
Ext★ SWIG FFI GI☆
Base
Tech
Ext Ext lib
ffi
lib
ffi
Impl.
by
Hand Gene-
rate
Hand Gene-
rate
★ Extension library(拡張ライブラリー)
☆ GObject Introspection: Recommended(オススメ)
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Extension library
拡張ライブラリーとは
Ruby library written in C
Cで書かれたRuby用ライブラリー
✓
Most bindings are ext lib
多くのバインディングは拡張ライブラリーとして実装
openssl is ext lib and bindings
oepnsslは拡張ライブラリーでバインディング
✓
Exc.: stringio is ext lib but...
例外:stringioは拡張ライブラリーだが…
✓
✓
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Ext lib and bindings
拡張ライブラリーとバインディング
Extension library
Bindings
stringioopenssl
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
What is libffi?
libffiってなに?
Ext★ SWIG FFI GI☆
Base
Tech
Ext Ext lib
ffi
lib
ffi
Impl.
by
Hand Gene-
rate
Hand Gene-
rate
★ Extension library(拡張ライブラリー)
☆ GObject Introspection: Recommended(オススメ)
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
libffi and FFI: 1
libffiとFFIとは:1
libffi: Library to impl. FFI
FFIを実現するためのライブラリー
✓
Foreign Function Interface
Generally:
All APIs to impl. bindings
一般的にはバインディングを実装するためのすべての
API
✓
Ruby doesn't use "FFI" term
Rubyでは「FFI」という単語を使わない
✓
✓
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
libffi and FFI: 2
libffiとFFIとは:2
Ruby FFI
Library based on libffi
libffiを使ったライブラリー
✓
Provides Ruby API
to implement bindings
バインディングを実装するためのRubyのAPIを提供
✓
✓
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
libffi and bindings
libffiとバインディング
C
Ruby
attach_function :rand, [], :int
rand(3)
libffi
libffi based Ruby API
Bindings
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Impl. language
実装言語
Ext★ SWIG FFI GI☆
Base
Tech
Ext Ext lib
ffi
lib
ffi
Impl.
lang
C C+α Ruby Ruby
★ Extension library(拡張ライブラリー)
☆ GObject Introspection: Recommended(オススメ)
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Ext impl. by
拡張ライブラリーの実装方法
Ext★ SWIG FFI GI☆
Base
Tech
Ext Ext lib
ffi
lib
ffi
Impl.
by
Hand Gener
ate
Hand Gene-
rate
★ Extension library(拡張ライブラリー)
☆ GObject Introspection: Recommended(オススメ)
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Ext impl. by: Target
拡張ライブラリーの実装方法:対象
/* hello.h */
#pragma once
typedef struct hello_t Hello;
Hello *hello_new (void);
void hello_free (Hello *hello);
const char *hello_message(Hello *hello);
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Ext impl. by hand
手動での拡張ライブラリーの実装
libhello RubyBindings
Implemented in C by hand
Use C API provided by Ruby
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Ext impl. by hand
手動での拡張ライブラリーの実装
https://github.com/kou/rabbit-slide-kou-rubykaigi-2016/
blob/master/c-api/bindings/hello.c
#include <ruby.h>
#include <hello.h>
static void
rb_hello_free(void *data)
{
Hello *hello = data;
hello_free(hello);
}
static const rb_data_type_t rb_hello_type = {
"Hello",
{
NULL,
rb_hello_free,
NULL,
},
NULL,
NULL,
RUBY_TYPED_FREE_IMMEDIATELY,
};
static VALUE
rb_hello_alloc(VALUE klass)
{
return TypedData_Wrap_Struct(klass, &rb_hello_type, NULL);
}
static VALUE
rb_hello_initialize(VALUE self)
{
Hello *hello;
hello = hello_new();
DATA_PTR(self) = hello;
return Qnil;
}
static VALUE
rb_hello_message(VALUE self)
{
Hello *hello;
const char *message;
TypedData_Get_Struct(self, Hello, &rb_hello_type, hello);
message = hello_message(hello);
return rb_str_new_cstr(message);
}
void
Init_hello(void)
{
VALUE hello;
hello = rb_define_class("Hello", rb_cData);
rb_define_alloc_func(hello, rb_hello_alloc);
rb_define_method(hello, "initialize", rb_hello_initialize, 0);
rb_define_method(hello, "message", rb_hello_message, 0);
}
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Ext impl. by generation
自動生成での拡張ライブラリーの実装
libhello RubyBindings
Generated by SWIG
Use C API provided by Ruby
hello.i
SWIG
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Ext impl. by generation
自動生成での拡張ライブラリーの実装
SWIG can generate impl.
Simplified Wrapper and Interface Generator
SWIGで実装を生成できる
✓
A user
TensorFlow: A library for machine
intelligence
TensorFlow:機械知能のライブラリー
Used to generate Python bindings
Pythonバインディングを生成するために使用
✓
✓
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Ext impl. by SWIG
SWIGでの拡張ライブラリーの実装
// swig -ruby hello.i -> hello_wrap.c
%module hello
%{
#include <hello.h>
%}
%include <hello.h>
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Use ext by SWIG
SWIGで作った拡張ライブラリーを使う
irb(main):001:0> require "hello"
=> true
irb(main):002:0> hello = Hello.hello_new
=> #<SWIG::TYPE_p_hello_t:0x000...>
irb(main):003:0> Hello.hello_message(hello)
=> "Hello"
irb(main):004:0> Hello.hello_free(hello)
=> nil
# Raw C API... :<
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
By SWIG again
SWIGでもう一度
%module hello
%{#include <hello.h>%}
typedef struct hello_t {
%extend {
hello_t() {return hello_new();}
~hello_t() {hello_free($self);}
const char *message() {return hello_message($self);}
}
} Hello;
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Use again
もう一度使う
irb(main):001:0> require "hello"
=> true
irb(main):002:0> hello = Hello::Hello.new
=> #<Hello::Hello:0x000...>
irb(main):003:0> hello.message
=> "Hello"
# Object oriented API!
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Wrap up1: Ext
まとめ1:拡張ライブラリー
By hand: Needs more work
手動:たくさん書かないといけない
✓
By generation: Less work
生成:書くことが少ない
Needs more work for easy use
使いやすいAPIにするにはたくさん書かないといけない
✓
✓
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Wrap up2: Ext
まとめ2:拡張ライブラリー
On maintenance
e.g.: New functions, enums
メンテナンス時:(例:新しい関数・列挙値が追加され
た)
By hand: Needs more work
手動:追加作業あり
✓
By generation: No more work
(But the bindings may not be easy to use)
生成:(使いやすくないけど)追加作業なし
This is a large benefit!
これは大きな利点!
✓
✓
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
libffi impl. by
libffiベースでの実装方法
Ext★ SWIG FFI GI☆
Base
Tech
Ext Ext lib
ffi
lib
ffi
Impl.
by
Hand Gene-
rate
Hand Gener
ate
★ Extension library(拡張ライブラリー)
☆ GObject Introspection: Recommended(オススメ)
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
libffi impl. by hand
手動でのlibffiベースの実装
libhello RubyBindings
Implemented in Ruby by hand
Use Ruby API provided by Ruby FFI
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
libffi impl. by hand
手動でのlibffiベースの実装
require "ffi"
module LibHello
extend FFI::Library
ffi_lib "../../libhello/lib/libhello.so"
attach_function :hello_new, [], :pointer
attach_function :hello_message, [:pointer], :string
attach_function :hello_free, [:pointer], :void
end
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Use libffi impl. by hand
手動でのlibffiベースの実装を使う
irb(main):001:0> require "hello"
=> true
irb(main):002:0> hello = LibHello.hello_new
=> #<FFI::Pointer address=0x00000002b07ef0>
irb(main):003:0> LibHello.hello_message(hello)
=> "Hello"
irb(main):004:0> LibHello.hello_free(hello)
=> nil
# Raw C API... :<
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Wrap FFI impl. 1
FFIでの実装をラップ1
class Hello
def initialize
hello = LibHello.hello_new
hello_free = LibHello.method(:hello_free)
@hello =
FFI::AutoPointer.new(hello, hello_free)
end
end
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Wrap FFI impl. 2
FFIでの実装をラップ2
class Hello
def message
LibHello.hello_message(@hello)
end
end
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Use wrapped impl.
ラップした実装を使う
irb(main):001:0> require "hello"
=> true
irb(main):002:0> hello = Hello.new
=> #<Hello:0x000...>
irb(main):003:0> hello.message
=> "Hello"
# Object oriented API!
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
libffi impl. by gen.
自動生成でのlibffiベースの実装
libghello RubyBindings
Generated by gi(*) gem at runtime
Hello.typelib
Annotation
g-ir-compiler gi gem
(*) gi = gobject-introspection
GObject
wrapper
libhello
gi
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
libffi impl. by gen.
自動生成でのlibffiベースの実装
require "gi"
Hello = GI.load("Hello")
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Use libffi impl. by gen.
自動生成でのlibffiベースの実装を使う
irb(main):001:0> require "hello"
=> true
irb(main):002:0> hello = Hello::Hello.new
=> #<Hello::Hello:0x2a9de98 ptr=0x2ecd540>
irb(main):003:0> hello.message
=> "Hello"
# Object oriented API!
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Wrap up1: libffi
まとめ1:libffi
By hand: Needs more work
手動:たくさん書かないといけない
Needs more work for easy use
使いやすいAPIにするにはさらに書かないといけない
✓
✓
By generation: Less work
生成:書くことが少ない
No more work for easy use
しかも使いやすいAPIになる
✓
✓
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Wrap up2: libffi
まとめ2:libffi
On maintenance
e.g.: New functions, enums
メンテナンス時:(例:新しい関数・列挙値が追加され
た)
By hand: Needs more work
手動:追加作業あり
✓
By generation: No more work
生成:追加作業なし
This is a large benefit!
これは大きな利点!
✓
✓
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Impl. by generation
生成ベースでの実装方法
Ext★ SWIG FFI GI☆
Base
Tech
Ext Ext lib
ffi
lib
ffi
Impl.
by
Hand Gener
ate
Hand Gener
ate
★ Extension library(拡張ライブラリー)
☆ GObject Introspection: Recommended(オススメ)
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
SWIG⇔GI: When
SWIG⇔GI:生成タイミング
When are bindings generated?
バインディングの生成タイミング
On build⇔Runtime
ビルド時⇔実行時
✓
SWIG: Need to build for new ver.
新しいバージョンがでたらリビルドが必要
✓
GI: No more work for new ver.
新しいバージョンがでても追加作業なし
✓
✓
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
SWIG⇔GI: Maintenance
SWIG⇔GI:メンテナンス
SWIG: Maintain .i file for
each language binding
各言語バインディング用に.iファイルをメンテナンス
✓
GI: Maintain annotations for
all language bindings
全言語バインディング用にアノテーションをメンテナンス
We can work together with other
language binding maintainers
✓
✓
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
SWIG: Overview (reprise)
SWIG:概要(再掲)
libhello RubyBindings
Generated by SWIG
Use C API provided by Ruby
hello.i
SWIG
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
SWIG: Maintenance
SWIG:メンテナンス
libhello RubyBindings
Generated by SWIG
Use C API provided by Ruby
SWIG
hello.i
Ruby binding
maintainers maintain
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
GI: Overview (reprise)
GI:概要(再掲)
libghello RubyBindings
Generated by gi(*) gem at runtime
Hello.typelib
Annotation
g-ir-compiler gi gem
(*) gi = gobject-introspection
GObject
wrapper
libhello
gi
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
GI: Maintenance
GI:メンテナンス
RubyBindings
Generated by gi(*) gem at runtime
Hello.typelibg-ir-compiler gi gem
(*) gi = gobject-introspection
libhello
gi
libghello
Annotation
GObject
wrapper
We can maintain with
library maintainers
and other language
binding maintainers
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Wrap up1
まとめ1
Bindings: Glue of C and Ruby
バインディング:主にCとRubyをつなぐもの
You can use features implemented
in C from Ruby
Cで実装された機能をRubyから使える
✓
✓
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Wrap up2
まとめ2
Bindings increase cases that
Ruby can be used
バインディングはRubyを使えるケースを増やす
Because they provide existing
good features to Ruby
バインディングは既存のよい機能をRubyで使えるように
するから
✓
✓
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Wrap up3
まとめ3
Recommend GI based bindings
GIベースのバインディングがオススメ
For easy maintenance
メンテンナンスしやすいから
✓
For easy to use API
使いやすいAPIになるから
✓
✓
GI: GObject Introspection
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Wrap up4
まとめ4
Let's become a
bindings
developer!
バインディング開発者になろう!
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Advertisement
宣伝
OSS Gate
Helps people who want to be an
OSS developer (but not yet)
OSS開発者になりたいけど一歩踏み出せていない人を支
援
✓
✓
ClearCode booth(クリアコードブース)
You can discus about OSS Gate and
more technical details
OSS Gateやもっと技術的な話や雑談をできる
✓
✓
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Wrap up (reprise)
まとめ(再掲)
Let's become a
bindings
developer!
バインディング開発者になろう!
Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0
Things not covered
話さなかったこと
Bindings are difficult to
install on Win. Any idea?
Windowsでインストールが大変。どうすれば?
✓
Performance・Annotation
性能・アノテーション
✓
Details of each binding's
create method
それぞれのバインディング作成方法の詳細
✓

More Related Content

What's hot

RDB経験者に送るMongoDBの勘所(db tech showcase tokyo 2013)
RDB経験者に送るMongoDBの勘所(db tech showcase tokyo 2013)RDB経験者に送るMongoDBの勘所(db tech showcase tokyo 2013)
RDB経験者に送るMongoDBの勘所(db tech showcase tokyo 2013)Ryuji Tamagawa
 
サーバサイドNodeの使い道
サーバサイドNodeの使い道サーバサイドNodeの使い道
サーバサイドNodeの使い道pospome
 
Case study to use MongoDB in middle-class SIer / (中規模) SIerだってMongoDBできたよ!
Case study to use MongoDB in middle-class SIer / (中規模) SIerだってMongoDBできたよ!Case study to use MongoDB in middle-class SIer / (中規模) SIerだってMongoDBできたよ!
Case study to use MongoDB in middle-class SIer / (中規模) SIerだってMongoDBできたよ!Naruhiko Ogasawara
 
Mongo db勉強会の補足
Mongo db勉強会の補足Mongo db勉強会の補足
Mongo db勉強会の補足CROOZ, inc.
 
AWS SDK for Smalltalk
AWS SDK for SmalltalkAWS SDK for Smalltalk
AWS SDK for SmalltalkSho Yoshida
 
minneで学ぶクラウド脳
minneで学ぶクラウド脳minneで学ぶクラウド脳
minneで学ぶクラウド脳Uchio Kondo
 
Web socket and gRPC
Web socket and gRPCWeb socket and gRPC
Web socket and gRPCTIS Inc
 
なかったらINSERTしたいし、あるならロック取りたいやん?
なかったらINSERTしたいし、あるならロック取りたいやん?なかったらINSERTしたいし、あるならロック取りたいやん?
なかったらINSERTしたいし、あるならロック取りたいやん?ichirin2501
 
MongoDBざっくり解説
MongoDBざっくり解説MongoDBざっくり解説
MongoDBざっくり解説知教 本間
 
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めた
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めたJJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めた
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めたKoichi Sakata
 
JSX 速さの秘密 - 高速なJavaScriptを書く方法
JSX 速さの秘密 - 高速なJavaScriptを書く方法JSX 速さの秘密 - 高速なJavaScriptを書く方法
JSX 速さの秘密 - 高速なJavaScriptを書く方法Kazuho Oku
 

What's hot (15)

RDB経験者に送るMongoDBの勘所(db tech showcase tokyo 2013)
RDB経験者に送るMongoDBの勘所(db tech showcase tokyo 2013)RDB経験者に送るMongoDBの勘所(db tech showcase tokyo 2013)
RDB経験者に送るMongoDBの勘所(db tech showcase tokyo 2013)
 
サーバサイドNodeの使い道
サーバサイドNodeの使い道サーバサイドNodeの使い道
サーバサイドNodeの使い道
 
Case study to use MongoDB in middle-class SIer / (中規模) SIerだってMongoDBできたよ!
Case study to use MongoDB in middle-class SIer / (中規模) SIerだってMongoDBできたよ!Case study to use MongoDB in middle-class SIer / (中規模) SIerだってMongoDBできたよ!
Case study to use MongoDB in middle-class SIer / (中規模) SIerだってMongoDBできたよ!
 
Mongo db勉強会の補足
Mongo db勉強会の補足Mongo db勉強会の補足
Mongo db勉強会の補足
 
Ruby24
Ruby24Ruby24
Ruby24
 
AWS SDK for Smalltalk
AWS SDK for SmalltalkAWS SDK for Smalltalk
AWS SDK for Smalltalk
 
minneで学ぶクラウド脳
minneで学ぶクラウド脳minneで学ぶクラウド脳
minneで学ぶクラウド脳
 
Web socket and gRPC
Web socket and gRPCWeb socket and gRPC
Web socket and gRPC
 
なかったらINSERTしたいし、あるならロック取りたいやん?
なかったらINSERTしたいし、あるならロック取りたいやん?なかったらINSERTしたいし、あるならロック取りたいやん?
なかったらINSERTしたいし、あるならロック取りたいやん?
 
MongoDBざっくり解説
MongoDBざっくり解説MongoDBざっくり解説
MongoDBざっくり解説
 
初めてのMongo db
初めてのMongo db初めてのMongo db
初めてのMongo db
 
Elasticsearch 5.2とJava Clientで戯れる #elasticsearchjp
Elasticsearch 5.2とJava Clientで戯れる #elasticsearchjpElasticsearch 5.2とJava Clientで戯れる #elasticsearchjp
Elasticsearch 5.2とJava Clientで戯れる #elasticsearchjp
 
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めた
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めたJJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めた
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めた
 
JSX 速さの秘密 - 高速なJavaScriptを書く方法
JSX 速さの秘密 - 高速なJavaScriptを書く方法JSX 速さの秘密 - 高速なJavaScriptを書く方法
JSX 速さの秘密 - 高速なJavaScriptを書く方法
 
mrubyのすすめ
mrubyのすすめmrubyのすすめ
mrubyのすすめ
 

Similar to How to create bindings 2016

Ruby on Rails を用いたWEBアプリケーションの開発
Ruby on Rails を用いたWEBアプリケーションの開発Ruby on Rails を用いたWEBアプリケーションの開発
Ruby on Rails を用いたWEBアプリケーションの開発Koichi Shimozono
 
ゲームのインフラをAwsで実戦tips全て見せます
ゲームのインフラをAwsで実戦tips全て見せますゲームのインフラをAwsで実戦tips全て見せます
ゲームのインフラをAwsで実戦tips全て見せますinfinite_loop
 
HTML5 アプリ開発
HTML5 アプリ開発HTML5 アプリ開発
HTML5 アプリ開発tomo_masakura
 
Java scriptの進化
Java scriptの進化Java scriptの進化
Java scriptの進化maruyama097
 
Railsの開発環境作るぞ
Railsの開発環境作るぞRailsの開発環境作るぞ
Railsの開発環境作るぞYoichi Toyota
 
Ruby向け帳票ソリューション「ThinReports」の開発で知るOSSの威力
Ruby向け帳票ソリューション「ThinReports」の開発で知るOSSの威力Ruby向け帳票ソリューション「ThinReports」の開発で知るOSSの威力
Ruby向け帳票ソリューション「ThinReports」の開発で知るOSSの威力ThinReports
 
Ruby Extended Library
Ruby Extended LibraryRuby Extended Library
Ruby Extended LibraryAkio Tajima
 
Go言語ハンズオン資料flagパッケージを使ってみる
Go言語ハンズオン資料flagパッケージを使ってみるGo言語ハンズオン資料flagパッケージを使ってみる
Go言語ハンズオン資料flagパッケージを使ってみるyoshito funayose
 
OpenStack + KVM + IPv6 = oname.com; Next Folsom/Grizzly Service development s...
OpenStack + KVM + IPv6 = oname.com; Next Folsom/Grizzly Service development s...OpenStack + KVM + IPv6 = oname.com; Next Folsom/Grizzly Service development s...
OpenStack + KVM + IPv6 = oname.com; Next Folsom/Grizzly Service development s...Naoto Gohko
 
【テックリンク】平日の夜1時間で学ぶ!RubyonRails初心者ハンズオン
【テックリンク】平日の夜1時間で学ぶ!RubyonRails初心者ハンズオン 【テックリンク】平日の夜1時間で学ぶ!RubyonRails初心者ハンズオン
【テックリンク】平日の夜1時間で学ぶ!RubyonRails初心者ハンズオン linkbal
 
プログラマー
プログラマープログラマー
プログラマーKouhei Sutou
 
Couch DB in 15minutes
Couch DB in 15minutesCouch DB in 15minutes
Couch DB in 15minutesYohei Sasaki
 
AmazonElasticBeanstalk
AmazonElasticBeanstalkAmazonElasticBeanstalk
AmazonElasticBeanstalkTaisuke Oe
 
密着! nibohsiデプロイ 13:00-13:05 - railsアプリのデプロイ事例 -
密着! nibohsiデプロイ 13:00-13:05 - railsアプリのデプロイ事例 -密着! nibohsiデプロイ 13:00-13:05 - railsアプリのデプロイ事例 -
密着! nibohsiデプロイ 13:00-13:05 - railsアプリのデプロイ事例 -Yukihiko SAWANOBORI
 
Rubyの仕事で食べていくために僕らは!
Rubyの仕事で食べていくために僕らは!Rubyの仕事で食べていくために僕らは!
Rubyの仕事で食べていくために僕らは!Ouka Yuka
 
20170809 AWS code series
20170809 AWS code series20170809 AWS code series
20170809 AWS code seriesAtsushi Fukui
 
aws chaliceで作るslack翻訳bot
aws chaliceで作るslack翻訳botaws chaliceで作るslack翻訳bot
aws chaliceで作るslack翻訳botuchimanajet7
 
GoによるWebアプリ開発のキホン
GoによるWebアプリ開発のキホンGoによるWebアプリ開発のキホン
GoによるWebアプリ開発のキホンAkihiko Horiuchi
 

Similar to How to create bindings 2016 (20)

Ruby on Rails を用いたWEBアプリケーションの開発
Ruby on Rails を用いたWEBアプリケーションの開発Ruby on Rails を用いたWEBアプリケーションの開発
Ruby on Rails を用いたWEBアプリケーションの開発
 
Ruby In Wheezy
Ruby In WheezyRuby In Wheezy
Ruby In Wheezy
 
ゲームのインフラをAwsで実戦tips全て見せます
ゲームのインフラをAwsで実戦tips全て見せますゲームのインフラをAwsで実戦tips全て見せます
ゲームのインフラをAwsで実戦tips全て見せます
 
HTML5 アプリ開発
HTML5 アプリ開発HTML5 アプリ開発
HTML5 アプリ開発
 
Java scriptの進化
Java scriptの進化Java scriptの進化
Java scriptの進化
 
Railsの開発環境作るぞ
Railsの開発環境作るぞRailsの開発環境作るぞ
Railsの開発環境作るぞ
 
Ruby向け帳票ソリューション「ThinReports」の開発で知るOSSの威力
Ruby向け帳票ソリューション「ThinReports」の開発で知るOSSの威力Ruby向け帳票ソリューション「ThinReports」の開発で知るOSSの威力
Ruby向け帳票ソリューション「ThinReports」の開発で知るOSSの威力
 
Ruby Extended Library
Ruby Extended LibraryRuby Extended Library
Ruby Extended Library
 
Go言語ハンズオン資料flagパッケージを使ってみる
Go言語ハンズオン資料flagパッケージを使ってみるGo言語ハンズオン資料flagパッケージを使ってみる
Go言語ハンズオン資料flagパッケージを使ってみる
 
OpenStack + KVM + IPv6 = oname.com; Next Folsom/Grizzly Service development s...
OpenStack + KVM + IPv6 = oname.com; Next Folsom/Grizzly Service development s...OpenStack + KVM + IPv6 = oname.com; Next Folsom/Grizzly Service development s...
OpenStack + KVM + IPv6 = oname.com; Next Folsom/Grizzly Service development s...
 
【テックリンク】平日の夜1時間で学ぶ!RubyonRails初心者ハンズオン
【テックリンク】平日の夜1時間で学ぶ!RubyonRails初心者ハンズオン 【テックリンク】平日の夜1時間で学ぶ!RubyonRails初心者ハンズオン
【テックリンク】平日の夜1時間で学ぶ!RubyonRails初心者ハンズオン
 
プログラマー
プログラマープログラマー
プログラマー
 
Couch DB in 15minutes
Couch DB in 15minutesCouch DB in 15minutes
Couch DB in 15minutes
 
AmazonElasticBeanstalk
AmazonElasticBeanstalkAmazonElasticBeanstalk
AmazonElasticBeanstalk
 
密着! nibohsiデプロイ 13:00-13:05 - railsアプリのデプロイ事例 -
密着! nibohsiデプロイ 13:00-13:05 - railsアプリのデプロイ事例 -密着! nibohsiデプロイ 13:00-13:05 - railsアプリのデプロイ事例 -
密着! nibohsiデプロイ 13:00-13:05 - railsアプリのデプロイ事例 -
 
Rubyの仕事で食べていくために僕らは!
Rubyの仕事で食べていくために僕らは!Rubyの仕事で食べていくために僕らは!
Rubyの仕事で食べていくために僕らは!
 
Openshift 20191121
Openshift 20191121Openshift 20191121
Openshift 20191121
 
20170809 AWS code series
20170809 AWS code series20170809 AWS code series
20170809 AWS code series
 
aws chaliceで作るslack翻訳bot
aws chaliceで作るslack翻訳botaws chaliceで作るslack翻訳bot
aws chaliceで作るslack翻訳bot
 
GoによるWebアプリ開発のキホン
GoによるWebアプリ開発のキホンGoによるWebアプリ開発のキホン
GoによるWebアプリ開発のキホン
 

More from Kouhei Sutou

RubyKaigi 2022 - Fast data processing with Ruby and Apache Arrow
RubyKaigi 2022 - Fast data processing with Ruby and Apache ArrowRubyKaigi 2022 - Fast data processing with Ruby and Apache Arrow
RubyKaigi 2022 - Fast data processing with Ruby and Apache ArrowKouhei Sutou
 
Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021
Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021
Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021Kouhei Sutou
 
RubyKaigi Takeout 2021 - Red Arrow - Ruby and Apache Arrow
RubyKaigi Takeout 2021 - Red Arrow - Ruby and Apache ArrowRubyKaigi Takeout 2021 - Red Arrow - Ruby and Apache Arrow
RubyKaigi Takeout 2021 - Red Arrow - Ruby and Apache ArrowKouhei Sutou
 
Rubyと仕事と自由なソフトウェア
Rubyと仕事と自由なソフトウェアRubyと仕事と自由なソフトウェア
Rubyと仕事と自由なソフトウェアKouhei Sutou
 
Apache Arrowフォーマットはなぜ速いのか
Apache Arrowフォーマットはなぜ速いのかApache Arrowフォーマットはなぜ速いのか
Apache Arrowフォーマットはなぜ速いのかKouhei Sutou
 
Apache Arrow 1.0 - A cross-language development platform for in-memory data
Apache Arrow 1.0 - A cross-language development platform for in-memory dataApache Arrow 1.0 - A cross-language development platform for in-memory data
Apache Arrow 1.0 - A cross-language development platform for in-memory dataKouhei Sutou
 
Redmine検索の未来像
Redmine検索の未来像Redmine検索の未来像
Redmine検索の未来像Kouhei Sutou
 
Apache Arrow - A cross-language development platform for in-memory data
Apache Arrow - A cross-language development platform for in-memory dataApache Arrow - A cross-language development platform for in-memory data
Apache Arrow - A cross-language development platform for in-memory dataKouhei Sutou
 
Better CSV processing with Ruby 2.6
Better CSV processing with Ruby 2.6Better CSV processing with Ruby 2.6
Better CSV processing with Ruby 2.6Kouhei Sutou
 
Apache Arrow - データ処理ツールの次世代プラットフォーム
Apache Arrow - データ処理ツールの次世代プラットフォームApache Arrow - データ処理ツールの次世代プラットフォーム
Apache Arrow - データ処理ツールの次世代プラットフォームKouhei Sutou
 
MySQL・PostgreSQLだけで作る高速あいまい全文検索システム
MySQL・PostgreSQLだけで作る高速あいまい全文検索システムMySQL・PostgreSQLだけで作る高速あいまい全文検索システム
MySQL・PostgreSQLだけで作る高速あいまい全文検索システムKouhei Sutou
 
MySQL 8.0でMroonga
MySQL 8.0でMroongaMySQL 8.0でMroonga
MySQL 8.0でMroongaKouhei Sutou
 
Mroongaの高速全文検索機能でWordPress内のコンテンツを有効活用!
Mroongaの高速全文検索機能でWordPress内のコンテンツを有効活用!Mroongaの高速全文検索機能でWordPress内のコンテンツを有効活用!
Mroongaの高速全文検索機能でWordPress内のコンテンツを有効活用!Kouhei Sutou
 
MariaDBとMroongaで作る全言語対応超高速全文検索システム
MariaDBとMroongaで作る全言語対応超高速全文検索システムMariaDBとMroongaで作る全言語対応超高速全文検索システム
MariaDBとMroongaで作る全言語対応超高速全文検索システムKouhei Sutou
 
PGroonga 2 – Make PostgreSQL rich full text search system backend!
PGroonga 2 – Make PostgreSQL rich full text search system backend!PGroonga 2 – Make PostgreSQL rich full text search system backend!
PGroonga 2 – Make PostgreSQL rich full text search system backend!Kouhei Sutou
 

More from Kouhei Sutou (20)

RubyKaigi 2022 - Fast data processing with Ruby and Apache Arrow
RubyKaigi 2022 - Fast data processing with Ruby and Apache ArrowRubyKaigi 2022 - Fast data processing with Ruby and Apache Arrow
RubyKaigi 2022 - Fast data processing with Ruby and Apache Arrow
 
Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021
Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021
Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021
 
RubyKaigi Takeout 2021 - Red Arrow - Ruby and Apache Arrow
RubyKaigi Takeout 2021 - Red Arrow - Ruby and Apache ArrowRubyKaigi Takeout 2021 - Red Arrow - Ruby and Apache Arrow
RubyKaigi Takeout 2021 - Red Arrow - Ruby and Apache Arrow
 
Rubyと仕事と自由なソフトウェア
Rubyと仕事と自由なソフトウェアRubyと仕事と自由なソフトウェア
Rubyと仕事と自由なソフトウェア
 
Apache Arrowフォーマットはなぜ速いのか
Apache Arrowフォーマットはなぜ速いのかApache Arrowフォーマットはなぜ速いのか
Apache Arrowフォーマットはなぜ速いのか
 
Apache Arrow 1.0 - A cross-language development platform for in-memory data
Apache Arrow 1.0 - A cross-language development platform for in-memory dataApache Arrow 1.0 - A cross-language development platform for in-memory data
Apache Arrow 1.0 - A cross-language development platform for in-memory data
 
Apache Arrow 2019
Apache Arrow 2019Apache Arrow 2019
Apache Arrow 2019
 
Redmine検索の未来像
Redmine検索の未来像Redmine検索の未来像
Redmine検索の未来像
 
Apache Arrow - A cross-language development platform for in-memory data
Apache Arrow - A cross-language development platform for in-memory dataApache Arrow - A cross-language development platform for in-memory data
Apache Arrow - A cross-language development platform for in-memory data
 
Better CSV processing with Ruby 2.6
Better CSV processing with Ruby 2.6Better CSV processing with Ruby 2.6
Better CSV processing with Ruby 2.6
 
Apache Arrow
Apache ArrowApache Arrow
Apache Arrow
 
Apache Arrow - データ処理ツールの次世代プラットフォーム
Apache Arrow - データ処理ツールの次世代プラットフォームApache Arrow - データ処理ツールの次世代プラットフォーム
Apache Arrow - データ処理ツールの次世代プラットフォーム
 
Apache Arrow
Apache ArrowApache Arrow
Apache Arrow
 
MySQL・PostgreSQLだけで作る高速あいまい全文検索システム
MySQL・PostgreSQLだけで作る高速あいまい全文検索システムMySQL・PostgreSQLだけで作る高速あいまい全文検索システム
MySQL・PostgreSQLだけで作る高速あいまい全文検索システム
 
MySQL 8.0でMroonga
MySQL 8.0でMroongaMySQL 8.0でMroonga
MySQL 8.0でMroonga
 
My way with Ruby
My way with RubyMy way with Ruby
My way with Ruby
 
Red Data Tools
Red Data ToolsRed Data Tools
Red Data Tools
 
Mroongaの高速全文検索機能でWordPress内のコンテンツを有効活用!
Mroongaの高速全文検索機能でWordPress内のコンテンツを有効活用!Mroongaの高速全文検索機能でWordPress内のコンテンツを有効活用!
Mroongaの高速全文検索機能でWordPress内のコンテンツを有効活用!
 
MariaDBとMroongaで作る全言語対応超高速全文検索システム
MariaDBとMroongaで作る全言語対応超高速全文検索システムMariaDBとMroongaで作る全言語対応超高速全文検索システム
MariaDBとMroongaで作る全言語対応超高速全文検索システム
 
PGroonga 2 – Make PostgreSQL rich full text search system backend!
PGroonga 2 – Make PostgreSQL rich full text search system backend!PGroonga 2 – Make PostgreSQL rich full text search system backend!
PGroonga 2 – Make PostgreSQL rich full text search system backend!
 

How to create bindings 2016

  • 1. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Ruby bindings 2016 How to create bindings 2016 Kouhei Sutou ClearCode Inc. RubyKaigi 2016 2016-09-09
  • 2. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Acknowledgment 感謝 @SoManyHs and @drbrain They fixed English in this slide @RubyKaigi 2016 Official Party 昨日のパーティーで英語をチェックしてくれた!ありがとう!
  • 4. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Goal 目標 You become a new bindings developer あなたが新しくバインディング開発者になること
  • 5. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Bindings? バインディングとは Glue of (mainly) C and Ruby 主にCとRubyをつなぐもの You can use features implemented in C from Ruby Cで実装された機能をRubyから使える ✓ e.g.: Socket, OpenSSL, YAML, ... 例:ソケット、OpenSSL、YAML… ✓ ✓
  • 6. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Bindings バインディング C Bindings Ruby require "socket" socket(2) Can use socket! Bindings require "socket" socket(2) Can't use... Error
  • 7. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Why should I learn? なんでバインディング開発者になるの? To use Ruby in more cases Rubyをもっといろんな場面で使うため e.g.: Machine leaning, multimedia, full text search, cipher and so on 例:機械学習、画像・動画・音声処理、全文検索、暗号 ✓ ✓ Can use existing features in Ruby through bindings バインディングがあると既存のいい機能をRubyで使える ✓
  • 8. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Incr. bindings developer バインディング開発者が増えるといいな Why do I become a bindings developer? バインディング開発者になりませんか? To expand use cases of Ruby! Rubyを使えるケースを増やすために! ✓ Not just a user for provided features 提供された機能を使う1ユーザーではなく ✓ ✓
  • 9. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Summary 概要 Ext★ SWIG FFI GI☆ Base Tech Ext Ext lib ffi lib ffi Impl. by Hand Gene- rate Hand Gene- rate ★ Extension library(拡張ライブラリー) ☆ GObject Introspection: Recommended(オススメ)
  • 10. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Demo デモ Make powerful auto generated bindings 自動生成されたバインディングがいかに強力か
  • 11. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 What is ext? 拡張ライブラリーってなに? Ext★ SWIG FFI GI☆ Base Tech Ext Ext lib ffi lib ffi Impl. by Hand Gene- rate Hand Gene- rate ★ Extension library(拡張ライブラリー) ☆ GObject Introspection: Recommended(オススメ)
  • 12. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Extension library 拡張ライブラリーとは Ruby library written in C Cで書かれたRuby用ライブラリー ✓ Most bindings are ext lib 多くのバインディングは拡張ライブラリーとして実装 openssl is ext lib and bindings oepnsslは拡張ライブラリーでバインディング ✓ Exc.: stringio is ext lib but... 例外:stringioは拡張ライブラリーだが… ✓ ✓
  • 13. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Ext lib and bindings 拡張ライブラリーとバインディング Extension library Bindings stringioopenssl
  • 14. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 What is libffi? libffiってなに? Ext★ SWIG FFI GI☆ Base Tech Ext Ext lib ffi lib ffi Impl. by Hand Gene- rate Hand Gene- rate ★ Extension library(拡張ライブラリー) ☆ GObject Introspection: Recommended(オススメ)
  • 15. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 libffi and FFI: 1 libffiとFFIとは:1 libffi: Library to impl. FFI FFIを実現するためのライブラリー ✓ Foreign Function Interface Generally: All APIs to impl. bindings 一般的にはバインディングを実装するためのすべての API ✓ Ruby doesn't use "FFI" term Rubyでは「FFI」という単語を使わない ✓ ✓
  • 16. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 libffi and FFI: 2 libffiとFFIとは:2 Ruby FFI Library based on libffi libffiを使ったライブラリー ✓ Provides Ruby API to implement bindings バインディングを実装するためのRubyのAPIを提供 ✓ ✓
  • 17. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 libffi and bindings libffiとバインディング C Ruby attach_function :rand, [], :int rand(3) libffi libffi based Ruby API Bindings
  • 18. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Impl. language 実装言語 Ext★ SWIG FFI GI☆ Base Tech Ext Ext lib ffi lib ffi Impl. lang C C+α Ruby Ruby ★ Extension library(拡張ライブラリー) ☆ GObject Introspection: Recommended(オススメ)
  • 19. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Ext impl. by 拡張ライブラリーの実装方法 Ext★ SWIG FFI GI☆ Base Tech Ext Ext lib ffi lib ffi Impl. by Hand Gener ate Hand Gene- rate ★ Extension library(拡張ライブラリー) ☆ GObject Introspection: Recommended(オススメ)
  • 20. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Ext impl. by: Target 拡張ライブラリーの実装方法:対象 /* hello.h */ #pragma once typedef struct hello_t Hello; Hello *hello_new (void); void hello_free (Hello *hello); const char *hello_message(Hello *hello);
  • 21. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Ext impl. by hand 手動での拡張ライブラリーの実装 libhello RubyBindings Implemented in C by hand Use C API provided by Ruby
  • 22. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Ext impl. by hand 手動での拡張ライブラリーの実装 https://github.com/kou/rabbit-slide-kou-rubykaigi-2016/ blob/master/c-api/bindings/hello.c #include <ruby.h> #include <hello.h> static void rb_hello_free(void *data) { Hello *hello = data; hello_free(hello); } static const rb_data_type_t rb_hello_type = { "Hello", { NULL, rb_hello_free, NULL, }, NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY, }; static VALUE rb_hello_alloc(VALUE klass) { return TypedData_Wrap_Struct(klass, &rb_hello_type, NULL); } static VALUE rb_hello_initialize(VALUE self) { Hello *hello; hello = hello_new(); DATA_PTR(self) = hello; return Qnil; } static VALUE rb_hello_message(VALUE self) { Hello *hello; const char *message; TypedData_Get_Struct(self, Hello, &rb_hello_type, hello); message = hello_message(hello); return rb_str_new_cstr(message); } void Init_hello(void) { VALUE hello; hello = rb_define_class("Hello", rb_cData); rb_define_alloc_func(hello, rb_hello_alloc); rb_define_method(hello, "initialize", rb_hello_initialize, 0); rb_define_method(hello, "message", rb_hello_message, 0); }
  • 23. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Ext impl. by generation 自動生成での拡張ライブラリーの実装 libhello RubyBindings Generated by SWIG Use C API provided by Ruby hello.i SWIG
  • 24. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Ext impl. by generation 自動生成での拡張ライブラリーの実装 SWIG can generate impl. Simplified Wrapper and Interface Generator SWIGで実装を生成できる ✓ A user TensorFlow: A library for machine intelligence TensorFlow:機械知能のライブラリー Used to generate Python bindings Pythonバインディングを生成するために使用 ✓ ✓
  • 25. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Ext impl. by SWIG SWIGでの拡張ライブラリーの実装 // swig -ruby hello.i -> hello_wrap.c %module hello %{ #include <hello.h> %} %include <hello.h>
  • 26. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Use ext by SWIG SWIGで作った拡張ライブラリーを使う irb(main):001:0> require "hello" => true irb(main):002:0> hello = Hello.hello_new => #<SWIG::TYPE_p_hello_t:0x000...> irb(main):003:0> Hello.hello_message(hello) => "Hello" irb(main):004:0> Hello.hello_free(hello) => nil # Raw C API... :<
  • 27. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 By SWIG again SWIGでもう一度 %module hello %{#include <hello.h>%} typedef struct hello_t { %extend { hello_t() {return hello_new();} ~hello_t() {hello_free($self);} const char *message() {return hello_message($self);} } } Hello;
  • 28. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Use again もう一度使う irb(main):001:0> require "hello" => true irb(main):002:0> hello = Hello::Hello.new => #<Hello::Hello:0x000...> irb(main):003:0> hello.message => "Hello" # Object oriented API!
  • 29. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Wrap up1: Ext まとめ1:拡張ライブラリー By hand: Needs more work 手動:たくさん書かないといけない ✓ By generation: Less work 生成:書くことが少ない Needs more work for easy use 使いやすいAPIにするにはたくさん書かないといけない ✓ ✓
  • 30. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Wrap up2: Ext まとめ2:拡張ライブラリー On maintenance e.g.: New functions, enums メンテナンス時:(例:新しい関数・列挙値が追加され た) By hand: Needs more work 手動:追加作業あり ✓ By generation: No more work (But the bindings may not be easy to use) 生成:(使いやすくないけど)追加作業なし This is a large benefit! これは大きな利点! ✓ ✓
  • 31. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 libffi impl. by libffiベースでの実装方法 Ext★ SWIG FFI GI☆ Base Tech Ext Ext lib ffi lib ffi Impl. by Hand Gene- rate Hand Gener ate ★ Extension library(拡張ライブラリー) ☆ GObject Introspection: Recommended(オススメ)
  • 32. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 libffi impl. by hand 手動でのlibffiベースの実装 libhello RubyBindings Implemented in Ruby by hand Use Ruby API provided by Ruby FFI
  • 33. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 libffi impl. by hand 手動でのlibffiベースの実装 require "ffi" module LibHello extend FFI::Library ffi_lib "../../libhello/lib/libhello.so" attach_function :hello_new, [], :pointer attach_function :hello_message, [:pointer], :string attach_function :hello_free, [:pointer], :void end
  • 34. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Use libffi impl. by hand 手動でのlibffiベースの実装を使う irb(main):001:0> require "hello" => true irb(main):002:0> hello = LibHello.hello_new => #<FFI::Pointer address=0x00000002b07ef0> irb(main):003:0> LibHello.hello_message(hello) => "Hello" irb(main):004:0> LibHello.hello_free(hello) => nil # Raw C API... :<
  • 35. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Wrap FFI impl. 1 FFIでの実装をラップ1 class Hello def initialize hello = LibHello.hello_new hello_free = LibHello.method(:hello_free) @hello = FFI::AutoPointer.new(hello, hello_free) end end
  • 36. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Wrap FFI impl. 2 FFIでの実装をラップ2 class Hello def message LibHello.hello_message(@hello) end end
  • 37. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Use wrapped impl. ラップした実装を使う irb(main):001:0> require "hello" => true irb(main):002:0> hello = Hello.new => #<Hello:0x000...> irb(main):003:0> hello.message => "Hello" # Object oriented API!
  • 38. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 libffi impl. by gen. 自動生成でのlibffiベースの実装 libghello RubyBindings Generated by gi(*) gem at runtime Hello.typelib Annotation g-ir-compiler gi gem (*) gi = gobject-introspection GObject wrapper libhello gi
  • 39. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 libffi impl. by gen. 自動生成でのlibffiベースの実装 require "gi" Hello = GI.load("Hello")
  • 40. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Use libffi impl. by gen. 自動生成でのlibffiベースの実装を使う irb(main):001:0> require "hello" => true irb(main):002:0> hello = Hello::Hello.new => #<Hello::Hello:0x2a9de98 ptr=0x2ecd540> irb(main):003:0> hello.message => "Hello" # Object oriented API!
  • 41. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Wrap up1: libffi まとめ1:libffi By hand: Needs more work 手動:たくさん書かないといけない Needs more work for easy use 使いやすいAPIにするにはさらに書かないといけない ✓ ✓ By generation: Less work 生成:書くことが少ない No more work for easy use しかも使いやすいAPIになる ✓ ✓
  • 42. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Wrap up2: libffi まとめ2:libffi On maintenance e.g.: New functions, enums メンテナンス時:(例:新しい関数・列挙値が追加され た) By hand: Needs more work 手動:追加作業あり ✓ By generation: No more work 生成:追加作業なし This is a large benefit! これは大きな利点! ✓ ✓
  • 43. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Impl. by generation 生成ベースでの実装方法 Ext★ SWIG FFI GI☆ Base Tech Ext Ext lib ffi lib ffi Impl. by Hand Gener ate Hand Gener ate ★ Extension library(拡張ライブラリー) ☆ GObject Introspection: Recommended(オススメ)
  • 44. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 SWIG⇔GI: When SWIG⇔GI:生成タイミング When are bindings generated? バインディングの生成タイミング On build⇔Runtime ビルド時⇔実行時 ✓ SWIG: Need to build for new ver. 新しいバージョンがでたらリビルドが必要 ✓ GI: No more work for new ver. 新しいバージョンがでても追加作業なし ✓ ✓
  • 45. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 SWIG⇔GI: Maintenance SWIG⇔GI:メンテナンス SWIG: Maintain .i file for each language binding 各言語バインディング用に.iファイルをメンテナンス ✓ GI: Maintain annotations for all language bindings 全言語バインディング用にアノテーションをメンテナンス We can work together with other language binding maintainers ✓ ✓
  • 46. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 SWIG: Overview (reprise) SWIG:概要(再掲) libhello RubyBindings Generated by SWIG Use C API provided by Ruby hello.i SWIG
  • 47. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 SWIG: Maintenance SWIG:メンテナンス libhello RubyBindings Generated by SWIG Use C API provided by Ruby SWIG hello.i Ruby binding maintainers maintain
  • 48. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 GI: Overview (reprise) GI:概要(再掲) libghello RubyBindings Generated by gi(*) gem at runtime Hello.typelib Annotation g-ir-compiler gi gem (*) gi = gobject-introspection GObject wrapper libhello gi
  • 49. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 GI: Maintenance GI:メンテナンス RubyBindings Generated by gi(*) gem at runtime Hello.typelibg-ir-compiler gi gem (*) gi = gobject-introspection libhello gi libghello Annotation GObject wrapper We can maintain with library maintainers and other language binding maintainers
  • 50. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Wrap up1 まとめ1 Bindings: Glue of C and Ruby バインディング:主にCとRubyをつなぐもの You can use features implemented in C from Ruby Cで実装された機能をRubyから使える ✓ ✓
  • 51. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Wrap up2 まとめ2 Bindings increase cases that Ruby can be used バインディングはRubyを使えるケースを増やす Because they provide existing good features to Ruby バインディングは既存のよい機能をRubyで使えるように するから ✓ ✓
  • 52. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Wrap up3 まとめ3 Recommend GI based bindings GIベースのバインディングがオススメ For easy maintenance メンテンナンスしやすいから ✓ For easy to use API 使いやすいAPIになるから ✓ ✓ GI: GObject Introspection
  • 53. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Wrap up4 まとめ4 Let's become a bindings developer! バインディング開発者になろう!
  • 54. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Advertisement 宣伝 OSS Gate Helps people who want to be an OSS developer (but not yet) OSS開発者になりたいけど一歩踏み出せていない人を支 援 ✓ ✓ ClearCode booth(クリアコードブース) You can discus about OSS Gate and more technical details OSS Gateやもっと技術的な話や雑談をできる ✓ ✓
  • 55. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Wrap up (reprise) まとめ(再掲) Let's become a bindings developer! バインディング開発者になろう!
  • 56. Ruby bindings 2016 - How to create bindings 2016 Powered by Rabbit 2.2.0 Things not covered 話さなかったこと Bindings are difficult to install on Win. Any idea? Windowsでインストールが大変。どうすれば? ✓ Performance・Annotation 性能・アノテーション ✓ Details of each binding's create method それぞれのバインディング作成方法の詳細 ✓