File: readme.md

package info (click to toggle)
rust-rb-sys 0.9.102-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 284 kB
  • sloc: ansic: 71; sh: 16; makefile: 2
file content (72 lines) | stat: -rw-r--r-- 2,458 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# rb-sys

[![Join the discussion](https://img.shields.io/badge/slack-chat-blue.svg)](https://join.slack.com/t/oxidize-rb/shared_invite/zt-16zv5tqte-Vi7WfzxCesdo2TqF_RYBCw)

Autogenerated Rust bindings for Ruby. Uses the [`rust-bindgen`](https://github.com/rust-lang/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.

```toml
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](./examples/rust_reverse)

### 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:

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

### Static libruby

You can also force static linking of libruby:

```toml
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

- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)

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.