Skip to content

Commit 85c1395

Browse files
committed
Fix ruby_abi_version symbol error on macOS
Replace static exports.txt with dynamic export file selection based on Ruby version, following grpc's approach. Changes: - Remove exports.txt - Add ext-export.txt (for release versions) - Add ext-export-with-ruby-abi-version.txt (for dev versions) - Update extconf.rb to dynamically select export file based on Ruby version This fixes the 'Undefined symbols: _ruby_abi_version' linker error that occurs when building the gem. Related: - https://bugs.ruby-lang.org/issues/19289 - grpc/grpc#31970 - #117
1 parent cb4b3f7 commit 85c1395

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

ext/zstdruby/exports.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_Init_zstdruby

ext/zstdruby/ext-export.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_Init_zstdruby

ext/zstdruby/extconf.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,38 @@
22

33
have_func('rb_gc_mark_movable')
44

5+
# Check if ruby_abi_version symbol is required
6+
# Based on grpc's approach: https://github.com/grpc/grpc/blob/master/src/ruby/ext/grpc/extconf.rb
7+
def have_ruby_abi_version?
8+
# Only development/preview versions need the symbol
9+
return false if RUBY_PATCHLEVEL >= 0
10+
11+
# Ruby 3.2+ development versions require ruby_abi_version
12+
major, minor = RUBY_VERSION.split('.').map(&:to_i)
13+
if major > 3 || (major == 3 && minor >= 2)
14+
puts "Ruby version #{RUBY_VERSION} >= 3.2. Using ruby_abi_version symbol."
15+
return true
16+
else
17+
puts "Ruby version #{RUBY_VERSION} < 3.2. Not using ruby_abi_version symbol."
18+
return false
19+
end
20+
end
21+
22+
# Determine which export file to use based on Ruby version
23+
def ext_export_filename
24+
name = 'ext-export'
25+
name += '-with-ruby-abi-version' if have_ruby_abi_version?
26+
name
27+
end
28+
529
$CFLAGS = '-I. -O3 -std=c99 -DZSTD_STATIC_LINKING_ONLY -DZSTD_MULTITHREAD -pthread -DDEBUGLEVEL=0 -fvisibility=hidden -DZSTDLIB_VISIBLE=\'__attribute__((visibility("hidden")))\' -DZSTDLIB_HIDDEN=\'__attribute__((visibility("hidden")))\''
630
$CPPFLAGS += " -fdeclspec" if CONFIG['CXX'] =~ /clang/
731

832
# macOS specific: Use exported_symbols_list to control symbol visibility
933
if RUBY_PLATFORM =~ /darwin/
10-
$LDFLAGS += " -exported_symbols_list #{File.expand_path('exports.txt', __dir__)}"
34+
ext_export_file = File.join(__dir__, "#{ext_export_filename}.txt")
35+
$LDFLAGS += " -exported_symbols_list #{ext_export_file}"
36+
puts "Using export file: #{ext_export_file}"
1137
end
1238

1339
Dir.chdir File.expand_path('..', __FILE__) do

0 commit comments

Comments
 (0)