Skip to content

Commit

Permalink
Always define ruby_abi_version (#418)
Browse files Browse the repository at this point in the history
* Always define ruby_abi_version

* Remove abi version test
  • Loading branch information
ianks committed Aug 20, 2024
1 parent 24ff7be commit 76bd797
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 40 deletions.
2 changes: 1 addition & 1 deletion crates/rb-sys-test-helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bench = false
doctest = true

[dependencies]
rb-sys = { path = "../rb-sys", version = "~0.9.80", features = [
rb-sys = { path = "../rb-sys", version = "0.9.101", features = [
"link-ruby",
"stable-api-compiled-testing",
] }
Expand Down
3 changes: 0 additions & 3 deletions crates/rb-sys-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ extern crate rb_sys;
#[cfg(test)]
mod basic_smoke_test;

#[cfg(test)]
mod ruby_abi_version_test;

#[cfg(test)]
mod ruby_macros_test;

Expand Down
13 changes: 0 additions & 13 deletions crates/rb-sys-tests/src/ruby_abi_version_test.rs

This file was deleted.

14 changes: 7 additions & 7 deletions crates/rb-sys/build/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rb_sys_build::{utils::is_mswin_or_mingw, RbConfig};

use crate::version::Version;

pub fn is_global_allocator_enabled(rb_config: &RbConfig) -> bool {
pub(crate) fn is_global_allocator_enabled(rb_config: &RbConfig) -> bool {
let (major, minor) = rb_config.major_minor();
let current_version = Version::new(major, minor);
let two_four = Version::new(2, 4);
Expand All @@ -18,15 +18,15 @@ pub fn is_global_allocator_enabled(rb_config: &RbConfig) -> bool {
}
}

pub fn is_gem_enabled() -> bool {
pub(crate) fn is_gem_enabled() -> bool {
cfg!(rb_sys_gem)
}

pub fn is_no_link_ruby_enabled() -> bool {
pub(crate) fn is_no_link_ruby_enabled() -> bool {
is_env_variable_defined("CARGO_FEATURE_NO_LINK_RUBY")
}

pub fn is_debug_build_enabled() -> bool {
pub(crate) fn is_debug_build_enabled() -> bool {
if is_linting() {
return false;
}
Expand All @@ -36,7 +36,7 @@ pub fn is_debug_build_enabled() -> bool {
is_env_variable_defined("RB_SYS_DEBUG_BUILD")
}

pub fn is_ruby_static_enabled(rbconfig: &RbConfig) -> bool {
pub(crate) fn is_ruby_static_enabled(rbconfig: &RbConfig) -> bool {
println!("cargo:rerun-if-env-changed=RUBY_STATIC");

match std::env::var("RUBY_STATIC") {
Expand All @@ -48,7 +48,7 @@ pub fn is_ruby_static_enabled(rbconfig: &RbConfig) -> bool {
}
}

pub fn is_link_ruby_enabled() -> bool {
pub(crate) fn is_link_ruby_enabled() -> bool {
if is_linting() {
return false;
}
Expand Down Expand Up @@ -85,7 +85,7 @@ pub fn is_link_ruby_enabled() -> bool {
}
}

pub fn is_env_variable_defined(name: &str) -> bool {
pub(crate) fn is_env_variable_defined(name: &str) -> bool {
std::env::var(name).is_ok()
}

Expand Down
5 changes: 0 additions & 5 deletions crates/rb-sys/build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ fn export_cargo_cfg(rbconfig: &mut RbConfig, cap: &mut File) {
println!("cargo:rustc-cfg=use_global_allocator");
}

println!("cargo:rustc-check-cfg=cfg(use_ruby_abi_version)");
if is_gem_enabled() {
println!("cargo:rustc-cfg=use_ruby_abi_version");
}

println!("cargo:rustc-check-cfg=cfg(has_ruby_abi_version)");
if rbconfig.has_ruby_dln_check_abi() {
println!("cargo:rustc-cfg=has_ruby_abi_version");
Expand Down
3 changes: 0 additions & 3 deletions crates/rb-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,3 @@ pub type RubyValue = VALUE;

#[cfg(use_global_allocator)]
set_global_tracking_allocator!();

#[cfg(use_ruby_abi_version)]
ruby_abi_version!();
20 changes: 12 additions & 8 deletions crates/rb-sys/src/ruby_abi_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ pub const __RB_SYS_RUBY_ABI_VERSION: std::os::raw::c_ulonglong = 0;
#[cfg(has_ruby_abi_version)]
pub const __RB_SYS_RUBY_ABI_VERSION: std::os::raw::c_ulonglong = crate::RUBY_ABI_VERSION as _;

#[doc(hidden)]
#[no_mangle]
#[allow(unused)]
pub extern "C" fn ruby_abi_version() -> std::os::raw::c_ulonglong {
__RB_SYS_RUBY_ABI_VERSION
}

#[deprecated(
since = "0.9.102",
note = "You no longer need to invoke this macro, the `ruby_abi_version` function is defined automatically."
)]
#[macro_export]
macro_rules! ruby_abi_version {
() => {
/// Defines the `ruby_abi_version` function needed for Ruby extensions.
#[no_mangle]
#[allow(unused)]
pub extern "C" fn ruby_abi_version() -> std::os::raw::c_ulonglong {
$crate::__RB_SYS_RUBY_ABI_VERSION
}
};
() => {};
}

0 comments on commit 76bd797

Please sign in to comment.