Skip to content

Commit f4b0117

Browse files
authored
Merge pull request #120 from SpringMT/fix-ruby-abi-version-symbol-error
Fix ruby_abi_version symbol error on macOS
2 parents cb4b3f7 + 7b6c6ee commit f4b0117

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

.github/workflows/ruby.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
runs-on: ubuntu-latest
2727
strategy:
2828
matrix:
29-
ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4']
29+
ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4', 'ruby-head']
3030

3131
steps:
3232
- uses: actions/checkout@v5
File renamed without changes.

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)