❏ Former software engineer @
MagmaLabs
❏ Remote work advocate
❏ RubyMe Q2 mentor
❏ I ❤ Open source
@JuanCrg90
Slide 3
Slide 3 text
@JuanCrg90
Heroes' Causeway Arch Leon Guanajuato
Photo By @marianozka
Slide 4
Slide 4 text
@JuanCrg90
Slide 5
Slide 5 text
@JuanCrg90
Slide 6
Slide 6 text
What are the options
that we have to manage
native code on Ruby?
@JuanCrg90
Slide 7
Slide 7 text
MKMF
@JuanCrg90
Slide 8
Slide 8 text
@JuanCrg90
mkmf.rb is used by Ruby C extensions to generate a
Makefile which will correctly compile and link the C
extension to Ruby and a third-party library.
Slide 9
Slide 9 text
library.h
library.c
@JuanCrg90
Slide 10
Slide 10 text
my_ruby_ext.c
@JuanCrg90
Slide 11
Slide 11 text
extconf.rb
@JuanCrg90
Slide 12
Slide 12 text
@JuanCrg90
Slide 13
Slide 13 text
@JuanCrg90
Slide 14
Slide 14 text
Pros:
- We can use C functions in our Ruby Code
- We take advantage of the existing ruby.h library to create the
extension
Cons:
- We need to add extra C code to create the bindings
- This solution only works in MRI
@JuanCrg90
Slide 15
Slide 15 text
FFI
@JuanCrg90
Slide 16
Slide 16 text
A foreign function interface (FFI) is a mechanism
by which a program written in one programming
language can call routines or make use of services
written in another.
@JuanCrg90
Slide 17
Slide 17 text
@JuanCrg90
Slide 18
Slide 18 text
Pros:
- We don’t need to add additional C code
- An FFI extension is multi-platform and multi-implementation
Cons:
- Complex macros are difficult to maintain
- Same for callback functions
@JuanCrg90