diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index dd95680..2fd444c 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -26,7 +26,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4'] + ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4', 'ruby-head'] steps: - uses: actions/checkout@v5 diff --git a/ext/zstdruby/exports.txt b/ext/zstdruby/ext-export-with-ruby-abi-version.txt similarity index 100% rename from ext/zstdruby/exports.txt rename to ext/zstdruby/ext-export-with-ruby-abi-version.txt diff --git a/ext/zstdruby/ext-export.txt b/ext/zstdruby/ext-export.txt new file mode 100644 index 0000000..6a0b365 --- /dev/null +++ b/ext/zstdruby/ext-export.txt @@ -0,0 +1 @@ +_Init_zstdruby diff --git a/ext/zstdruby/extconf.rb b/ext/zstdruby/extconf.rb index 4ed2b2d..f963367 100644 --- a/ext/zstdruby/extconf.rb +++ b/ext/zstdruby/extconf.rb @@ -2,12 +2,38 @@ have_func('rb_gc_mark_movable') +# Check if ruby_abi_version symbol is required +# Based on grpc's approach: https://github.com/grpc/grpc/blob/master/src/ruby/ext/grpc/extconf.rb +def have_ruby_abi_version? + # Only development/preview versions need the symbol + return false if RUBY_PATCHLEVEL >= 0 + + # Ruby 3.2+ development versions require ruby_abi_version + major, minor = RUBY_VERSION.split('.').map(&:to_i) + if major > 3 || (major == 3 && minor >= 2) + puts "Ruby version #{RUBY_VERSION} >= 3.2. Using ruby_abi_version symbol." + return true + else + puts "Ruby version #{RUBY_VERSION} < 3.2. Not using ruby_abi_version symbol." + return false + end +end + +# Determine which export file to use based on Ruby version +def ext_export_filename + name = 'ext-export' + name += '-with-ruby-abi-version' if have_ruby_abi_version? + name +end + $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")))\'' $CPPFLAGS += " -fdeclspec" if CONFIG['CXX'] =~ /clang/ # macOS specific: Use exported_symbols_list to control symbol visibility if RUBY_PLATFORM =~ /darwin/ - $LDFLAGS += " -exported_symbols_list #{File.expand_path('exports.txt', __dir__)}" + ext_export_file = File.join(__dir__, "#{ext_export_filename}.txt") + $LDFLAGS += " -exported_symbols_list #{ext_export_file}" + puts "Using export file: #{ext_export_file}" end Dir.chdir File.expand_path('..', __FILE__) do