rb-sys 0.9.12

Rust bindings for the CRuby API
Documentation

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, the this crate if for you!

Usage

  1. Add the following to your Cargo.toml:

    [dependencies]
    rb-sys = "0.9"
    
  2. See this example of creating a Ruby gem in Rust

Linking libruby

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"] }

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

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

  • gem: Setup boilerplate for a Ruby gem (enabled by default).
  • ruby-abi-version: Set the Ruby ABI version. (enabled by default).
  • ruby-macros: Generate Rust functions for Ruby macros like RSTRING_PTR (enabled by default).
  • 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.