Skip to content

Commit 7eb8e47

Browse files
committed
Fix ruby 3.4 compatibility
1 parent 91bb771 commit 7eb8e47

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

.github/workflows/ci.yml

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
ruby: ['2.7', '3.0', '3.1', '3.2', '3.3'] # 3.4+ is not yet supported by google-protobuf
11+
ruby:
12+
- '2.7'
13+
- '3.0'
14+
- '3.1'
15+
- '3.2'
16+
- '3.3'
17+
# Note: 3.4+ is not yet supported by google-protobuf
18+
- '3.4.0-rc1'
1219
os: ['ubuntu-latest', 'windows-latest']
1320
runs-on: ${{ matrix.os }}
1421
steps:
15-
- uses: actions/checkout@v3
22+
- uses: actions/checkout@v4
1623
- uses: ruby/setup-ruby@v1
1724
with:
1825
ruby-version: ${{ matrix.ruby }}
@@ -21,4 +28,4 @@ jobs:
2128
run: bundle exec rake test
2229
- name: RuboCop
2330
run: bundle exec rake lint
24-
if: matrix.ruby != '3.1' && matrix.ruby != '3.2' && matrix.ruby != '3.3'
31+
if: matrix.ruby != '3.1' && matrix.ruby != '3.2' && matrix.ruby != '3.3' && matrix.ruby != '3.4.0-rc1'

ext/pg_query/extconf.rb

+28-4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,36 @@
2121
$INCFLAGS = "-I#{File.join(__dir__, 'include', 'postgres', 'port', 'win32_msvc')} " + $INCFLAGS
2222
end
2323

24-
SYMFILE =
25-
if RUBY_PLATFORM =~ /freebsd/
26-
File.join(__dir__, 'pg_query_ruby_freebsd.sym')
24+
def have_ruby_abi_version()
25+
# ruby_abi_version is only available in development versions: https://github.com/ruby/ruby/pull/6231
26+
return false if RUBY_PATCHLEVEL >= 0
27+
28+
m = /(\d+)\.(\d+)/.match(RUBY_VERSION)
29+
if m.nil?
30+
puts "Failed to parse ruby version: #{RUBY_VERSION}. Assuming ruby_abi_version symbol is NOT present."
31+
return false
32+
end
33+
major = m[1].to_i
34+
minor = m[2].to_i
35+
if major >= 3 and minor >= 2
36+
puts "Ruby version #{RUBY_VERSION} >= 3.2. Assuming ruby_abi_version symbol is present."
37+
return true
38+
end
39+
puts "Ruby version #{RUBY_VERSION} < 3.2. Assuming ruby_abi_version symbol is NOT present."
40+
false
41+
end
42+
43+
def ext_export_filename()
44+
name = if RUBY_PLATFORM =~ /freebsd/
45+
'pg_query_ruby_freebsd'
2746
elsif RUBY_PLATFORM !~ /cygwin|mswin|mingw|bccwin|wince|emx/
28-
File.join(__dir__, 'pg_query_ruby.sym')
47+
'pg_query_ruby'
2948
end
49+
name += '-with-ruby-abi-version' if have_ruby_abi_version()
50+
"#{name}.sym"
51+
end
52+
53+
SYMFILE = File.join(__dir__, ext_export_filename())
3054

3155
if RUBY_PLATFORM =~ /darwin/
3256
$DLDFLAGS << " -Wl,-exported_symbols_list #{SYMFILE}" unless defined?(::Rubinius)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_Init_pg_query
2+
_ruby_abi_version
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Init_pg_query
2+
_ruby_abi_version

0 commit comments

Comments
 (0)