From 7eb8e4791333fa1cca8e36c4d3cf5a6fdf713364 Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Thu, 19 Dec 2024 09:44:01 +0800 Subject: [PATCH 1/5] Fix ruby 3.4 compatibility --- .github/workflows/ci.yml | 13 ++++++-- ext/pg_query/extconf.rb | 32 ++++++++++++++++--- .../pg_query_ruby-with-ruby-abi-version.sym | 2 ++ ...ery_ruby_freebsd-with-ruby-abi-version.sym | 2 ++ 4 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 ext/pg_query/pg_query_ruby-with-ruby-abi-version.sym create mode 100644 ext/pg_query/pg_query_ruby_freebsd-with-ruby-abi-version.sym diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1d901df..01fecdee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,11 +8,18 @@ jobs: strategy: fail-fast: false matrix: - ruby: ['2.7', '3.0', '3.1', '3.2', '3.3'] # 3.4+ is not yet supported by google-protobuf + ruby: + - '2.7' + - '3.0' + - '3.1' + - '3.2' + - '3.3' + # Note: 3.4+ is not yet supported by google-protobuf + - '3.4.0-rc1' os: ['ubuntu-latest', 'windows-latest'] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} @@ -21,4 +28,4 @@ jobs: run: bundle exec rake test - name: RuboCop run: bundle exec rake lint - if: matrix.ruby != '3.1' && matrix.ruby != '3.2' && matrix.ruby != '3.3' + if: matrix.ruby != '3.1' && matrix.ruby != '3.2' && matrix.ruby != '3.3' && matrix.ruby != '3.4.0-rc1' diff --git a/ext/pg_query/extconf.rb b/ext/pg_query/extconf.rb index cf7feb51..9739f27c 100644 --- a/ext/pg_query/extconf.rb +++ b/ext/pg_query/extconf.rb @@ -21,12 +21,36 @@ $INCFLAGS = "-I#{File.join(__dir__, 'include', 'postgres', 'port', 'win32_msvc')} " + $INCFLAGS end -SYMFILE = - if RUBY_PLATFORM =~ /freebsd/ - File.join(__dir__, 'pg_query_ruby_freebsd.sym') +def have_ruby_abi_version() + # ruby_abi_version is only available in development versions: https://github.com/ruby/ruby/pull/6231 + return false if RUBY_PATCHLEVEL >= 0 + + m = /(\d+)\.(\d+)/.match(RUBY_VERSION) + if m.nil? + puts "Failed to parse ruby version: #{RUBY_VERSION}. Assuming ruby_abi_version symbol is NOT present." + return false + end + major = m[1].to_i + minor = m[2].to_i + if major >= 3 and minor >= 2 + puts "Ruby version #{RUBY_VERSION} >= 3.2. Assuming ruby_abi_version symbol is present." + return true + end + puts "Ruby version #{RUBY_VERSION} < 3.2. Assuming ruby_abi_version symbol is NOT present." + false +end + +def ext_export_filename() + name = if RUBY_PLATFORM =~ /freebsd/ + 'pg_query_ruby_freebsd' elsif RUBY_PLATFORM !~ /cygwin|mswin|mingw|bccwin|wince|emx/ - File.join(__dir__, 'pg_query_ruby.sym') + 'pg_query_ruby' end + name += '-with-ruby-abi-version' if have_ruby_abi_version() + "#{name}.sym" +end + +SYMFILE = File.join(__dir__, ext_export_filename()) if RUBY_PLATFORM =~ /darwin/ $DLDFLAGS << " -Wl,-exported_symbols_list #{SYMFILE}" unless defined?(::Rubinius) diff --git a/ext/pg_query/pg_query_ruby-with-ruby-abi-version.sym b/ext/pg_query/pg_query_ruby-with-ruby-abi-version.sym new file mode 100644 index 00000000..05fcbdf4 --- /dev/null +++ b/ext/pg_query/pg_query_ruby-with-ruby-abi-version.sym @@ -0,0 +1,2 @@ +_Init_pg_query +_ruby_abi_version diff --git a/ext/pg_query/pg_query_ruby_freebsd-with-ruby-abi-version.sym b/ext/pg_query/pg_query_ruby_freebsd-with-ruby-abi-version.sym new file mode 100644 index 00000000..ba6b96f8 --- /dev/null +++ b/ext/pg_query/pg_query_ruby_freebsd-with-ruby-abi-version.sym @@ -0,0 +1,2 @@ +Init_pg_query +_ruby_abi_version From 81256a2e99d62c4530b6b364a3eaabb623d79399 Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Sat, 21 Dec 2024 05:39:09 +0800 Subject: [PATCH 2/5] * Use ruby-head not 3.4 rc which is unavailble on windows-latest --- .github/workflows/ci.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01fecdee..340edb3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,9 +14,11 @@ jobs: - '3.1' - '3.2' - '3.3' - # Note: 3.4+ is not yet supported by google-protobuf - - '3.4.0-rc1' - os: ['ubuntu-latest', 'windows-latest'] + # When 3.4 is released, replace `ruby-head` with `3.4`, `3.4.0-rc1` can't be used on `windows-latest` + - 'ruby-head' + os: + - 'ubuntu-latest' + - 'windows-latest' runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -28,4 +30,4 @@ jobs: run: bundle exec rake test - name: RuboCop run: bundle exec rake lint - if: matrix.ruby != '3.1' && matrix.ruby != '3.2' && matrix.ruby != '3.3' && matrix.ruby != '3.4.0-rc1' + if: matrix.ruby != '3.1' && matrix.ruby != '3.2' && matrix.ruby != '3.3' && matrix.ruby != 'ruby-head' From 2a8137f7451d01182b67878dce58a5a715871521 Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Sat, 21 Dec 2024 06:39:11 +0800 Subject: [PATCH 3/5] ^ bundle update --- Gemfile.lock | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 891b3df2..9ccf6c33 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,32 +7,35 @@ PATH GEM remote: https://rubygems.org/ specs: - ast (2.4.1) - diff-lcs (1.5.0) - docile (1.4.0) - google-protobuf (3.25.5) - parallel (1.20.1) + ast (2.4.2) + bigdecimal (3.1.8) + diff-lcs (1.5.1) + docile (1.4.1) + google-protobuf (4.29.2) + bigdecimal + rake (>= 13) + parallel (1.26.3) parser (2.7.2.0) ast (~> 2.4.1) powerpack (0.1.3) rainbow (2.2.2) rake - rake (13.0.3) + rake (13.2.1) rake-compiler (0.9.9) rake - rspec (3.12.0) - rspec-core (~> 3.12.0) - rspec-expectations (~> 3.12.0) - rspec-mocks (~> 3.12.0) - rspec-core (3.12.2) - rspec-support (~> 3.12.0) - rspec-expectations (3.12.3) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.2) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.3) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-mocks (3.12.6) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-support (3.12.1) + rspec-support (~> 3.13.0) + rspec-support (3.13.2) rubocop (0.49.1) parallel (~> 1.10) parser (>= 2.3.3.1, < 3.0) @@ -42,14 +45,14 @@ GEM unicode-display_width (~> 1.0, >= 1.0.1) rubocop-rspec (1.15.1) rubocop (>= 0.42.0) - ruby-progressbar (1.10.1) + ruby-progressbar (1.13.0) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) - simplecov-html (0.12.3) + simplecov-html (0.13.1) simplecov_json_formatter (0.1.4) - unicode-display_width (1.7.0) + unicode-display_width (1.8.0) PLATFORMS ruby From 5d507af12c03dc6eb384baf57d158eb87734158a Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Thu, 9 Jan 2025 09:47:20 +0800 Subject: [PATCH 4/5] ^ bundle update --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9ccf6c33..b92019ce 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,10 +8,10 @@ GEM remote: https://rubygems.org/ specs: ast (2.4.2) - bigdecimal (3.1.8) + bigdecimal (3.1.9) diff-lcs (1.5.1) docile (1.4.1) - google-protobuf (4.29.2) + google-protobuf (4.29.3) bigdecimal rake (>= 13) parallel (1.26.3) From a5fa7585a316dd3773e84921e66681573dbff48b Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Thu, 9 Jan 2025 09:47:55 +0800 Subject: [PATCH 5/5] * Update CI to use 3.4 instead of head & remove 2.7, gemspec to require ruby >=3.0 --- .github/workflows/ci.yml | 6 ++---- pg_query.gemspec | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 340edb3f..103d7a4a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,13 +9,11 @@ jobs: fail-fast: false matrix: ruby: - - '2.7' - '3.0' - '3.1' - '3.2' - '3.3' - # When 3.4 is released, replace `ruby-head` with `3.4`, `3.4.0-rc1` can't be used on `windows-latest` - - 'ruby-head' + - '3.4' os: - 'ubuntu-latest' - 'windows-latest' @@ -30,4 +28,4 @@ jobs: run: bundle exec rake test - name: RuboCop run: bundle exec rake lint - if: matrix.ruby != '3.1' && matrix.ruby != '3.2' && matrix.ruby != '3.3' && matrix.ruby != 'ruby-head' + if: matrix.ruby == '3.0' diff --git a/pg_query.gemspec b/pg_query.gemspec index 4330650a..1ae7b5ad 100644 --- a/pg_query.gemspec +++ b/pg_query.gemspec @@ -12,6 +12,8 @@ Gem::Specification.new do |s| s.license = 'BSD-3-Clause' s.homepage = 'https://github.com/pganalyze/pg_query' + s.required_ruby_version = '>= 3.0' + s.extensions = %w[ext/pg_query/extconf.rb] s.files = Dir['CHANGELOG.md', 'LICENSE', 'README.md', 'Rakefile', 'lib/**/*.rb',