[Feature #18249] Implement ABI checking

Header file include/ruby/internal/abi.h contains RUBY_ABI_VERSION which
is the ABI version. This value should be bumped whenever an ABI
incompatible change is introduced.

When loading dynamic libraries, Ruby will compare its own
`ruby_abi_version` and the `ruby_abi_version` of the loaded library. If
these two values don't match it will raise a `LoadError`. This feature
can also be turned off by setting the environment variable
`RUBY_RUBY_ABI_CHECK=0`.

This feature will prevent cases where previously installed native gems
fail in unexpected ways due to incompatibility of changes in header
files. This will force the developer to recompile their gems to use the
same header files as the built Ruby.

In Ruby, the ABI version is exposed through
`RbConfig::CONFIG["ruby_abi_version"]`.
This commit is contained in:
Peter Zhu 2022-02-18 10:59:45 -05:00
parent 37d5890e49
commit 3df16924b4
Notes: git 2022-02-22 23:55:57 +09:00
8 changed files with 130 additions and 0 deletions

11
ext/-test-/abi/abi.c Normal file
View file

@ -0,0 +1,11 @@
#include <limits.h>
unsigned long long
ruby_abi_version(void)
{
return ULONG_MAX;
}
void
Init_abi(void)
{}

View file

@ -0,0 +1,3 @@
# frozen_string_literal: false
require_relative "../auto_ext.rb"
auto_ext(inc: true)