92 releases

new 0.9.88 Feb 14, 2024
0.9.85 Dec 27, 2023
0.9.83 Nov 17, 2023
0.9.79 Jun 13, 2023
0.9.28 Jul 28, 2022

#297 in Rust patterns

Download history 25537/week @ 2023-10-30 24980/week @ 2023-11-06 21752/week @ 2023-11-13 20798/week @ 2023-11-20 19496/week @ 2023-11-27 26593/week @ 2023-12-04 34403/week @ 2023-12-11 25355/week @ 2023-12-18 10773/week @ 2023-12-25 26504/week @ 2024-01-01 20306/week @ 2024-01-08 18097/week @ 2024-01-15 21687/week @ 2024-01-22 22089/week @ 2024-01-29 20781/week @ 2024-02-05 15807/week @ 2024-02-12

81,557 downloads per month
Used in 7 crates (5 directly)

MIT/Apache

105KB
2.5K SLoC

rb-sys

Join the discussion

Autogenerated Rust bindings for Ruby. Uses the rust-bindgen crate to generate bindings from the ruby.h header.https://github.com/rust-lang/rust-bindgen

⚠️ Notice

This is a very low-level library. If you are looking to write a gem in Rust, you should probably use https://github.com/matsadler/magnus crate, with the rb-sys-interop feature.

If you actually need raw/unsafe bindings to libruby, then this crate if for you!

Usage

Writing a Ruby gem

Ruby gems require a bit of boilerplate to be defined to be usable from Ruby. rb-sys makes this process painless by doing the work for you, by simply enabling the gem feature.

rb-sys = "0.9"

Under the hood this ensures we do not link libruby (unless on Windows), and defines a ruby_abi_version function for Ruby 3.2+.

See this example of creating a Ruby gem in Rust

Embedding libruby in your Rust app

IMPORTANT: If you are authoring a Ruby gem, you do not need to enable this feature.

If you need to link libruby (i.e. you are initializing a Ruby VM in your Rust code), use can enable the link-ruby feature:

rb-sys = { version = "0.9",  features = ["link-ruby"] }

Static libruby

You can also force static linking of libruby:

rb-sys = { version = "0.9", features = ["ruby-static"] }

Alternatively, you can set the RUBY_STATIC=true environment variable.

Other features

  • global-allocator: Report Rust memory allocations to the Ruby GC (recommended).
  • ruby-static: Link the static version of libruby.
  • link-ruby: Link libruby.
  • bindgen-rbimpls: Include the Ruby impl types in bindings.
  • bindgen-deprecated-types: Include deprecated Ruby methods in bindings.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0–2.7MB
~41K SLoC