rb_sys/
ruby_abi_version.rs

1//! Helper to define the `ruby_abi_version` function needed for extensions.
2//!
3//! Since Ruby 3.2, gems are required to define a `ruby_abi_version` function.
4//! For C extensions, this is done transparently by including `ruby.h`, but for
5//! Rust we have to define it ourselves. This is enabled automatically by when
6//! compiling a gem.
7
8#[doc(hidden)]
9#[cfg(not(has_ruby_abi_version))]
10pub const __RB_SYS_RUBY_ABI_VERSION: std::os::raw::c_ulonglong = 0;
11
12#[doc(hidden)]
13#[cfg(has_ruby_abi_version)]
14pub const __RB_SYS_RUBY_ABI_VERSION: std::os::raw::c_ulonglong = crate::RUBY_ABI_VERSION as _;
15
16#[doc(hidden)]
17#[no_mangle]
18#[allow(unused)]
19pub extern "C" fn ruby_abi_version() -> std::os::raw::c_ulonglong {
20    __RB_SYS_RUBY_ABI_VERSION
21}
22
23#[doc(hidden)]
24#[no_mangle]
25#[allow(unused)]
26#[cfg(ruby_engine = "truffleruby")]
27pub extern "C" fn rb_tr_abi_version() -> *const std::os::raw::c_char {
28    crate::TRUFFLERUBY_ABI_VERSION.as_ptr() as *const _
29}
30
31#[deprecated(
32    since = "0.9.102",
33    note = "You no longer need to invoke this macro, the `ruby_abi_version` function is defined automatically."
34)]
35#[macro_export]
36macro_rules! ruby_abi_version {
37    () => {};
38}