Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/binary-gems.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
rcd_build:
name: Build
runs-on: ubuntu-latest
env:
RCD_IMAGE_VERSION: snapshot
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -142,12 +144,12 @@ jobs:
- run: echo $env:PATH
- name: Run specs
if: ${{ matrix.os != 'windows-latest' }}
run: ruby -rpg -S rspec -fd spec/**/*_spec.rb
run: ruby -rpg -S rspec -fd spec/*_spec.rb spec/**/*_spec.rb
- name: Run specs
if: ${{ matrix.os == 'windows-latest' }}
run: |
ridk enable
ruby -rpg -S rspec -fd spec/**/*_spec.rb
ruby -rpg -S rspec -fd spec/*_spec.rb spec/**/*_spec.rb

- name: Print logs if job failed
if: ${{ failure() && matrix.os == 'windows-latest' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/source-gem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ jobs:
PG_DEBUG: 0
# Temprary fix only for Truffleruby-24.0.0:
TRUFFLERUBYOPT: --experimental-options --keep-handles-alive
run: ruby -rpg -S rspec spec/**/*_spec.rb -cfdoc
run: ruby -rpg -S rspec spec/*_spec.rb spec/**/*_spec.rb -cfdoc

- name: Print db logs if job failed
if: ${{ failure() && matrix.os == 'windows' }}
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ end
group :test do
gem "bundler", ">= 1.16", "< 3.0"
gem "rake-compiler", "~> 1.0"
gem "rake-compiler-dock", "~> 1.9.1"
gem "rake-compiler-dock", "~> 1.9.1", git: "https://github.com/rake-compiler/rake-compiler-dock"
gem "rspec", "~> 3.5"
# "bigdecimal" is a gem on ruby-3.4+ and it's optional for ruby-pg.
# Specs should succeed without it, but 4 examples are then excluded.
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Rake::ExtensionTask.new do |ext|
# Activate current cross compiled platform only.
# This is to work around the issue that `linux` platform is selected in `linux-musl` image.
ext.cross_platform = CrossLibraries.map(&:platform).select do |pl|
m = ENV["RCD_IMAGE"]&.match(/:(?<ruby_ver>[\d\.]+)-mri-(?<platform>[-\w]+)$/)
m = ENV["RCD_IMAGE"]&.match(/:(?<ruby_ver>[\w\.]+)-mri-(?<platform>[-\w]+)$/)
m && m[:platform] == pl
end

Expand Down Expand Up @@ -106,7 +106,7 @@ task 'gem:native:prepare' do
# Copy gem signing key and certs to be accessible from the docker container
mkdir_p 'build/gem'
sh "cp ~/.gem/gem-*.pem build/gem/ || true"
sh "bundle package"
sh "bundle package --all"
begin
OpenSSL::PKey.read(File.read(File.expand_path("~/.gem/gem-private_key.pem")), ENV["GEM_PRIVATE_KEY_PASSPHRASE"] || "")
rescue OpenSSL::PKey::PKeyError
Expand Down
17 changes: 17 additions & 0 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,20 @@ module PG
create_header()
create_makefile( "pg_ext" )

if gem_platform
# exercise the strip command on native binary gems
# This approach borrowed from
# https://github.com/rake-compiler/rake-compiler-dock/blob/38066d479050f4fdb3956469255b35a05e5949ef/test/rcd_test/ext/mri/extconf.rb#L97C1-L110C42
strip_tool = RbConfig::CONFIG['STRIP']
strip_tool += ' -x' if RUBY_PLATFORM =~ /darwin/
File.open('Makefile.new', 'w') do |o|
o.puts 'hijack: all strip'
o.puts
o.write(File.read('Makefile'))
o.puts
o.puts 'strip: $(DLLIB)'
o.puts "\t$(ECHO) Stripping $(DLLIB)"
o.puts "\t$(Q) #{strip_tool} $(DLLIB)"
end
File.rename('Makefile.new', 'Makefile')
end
2 changes: 1 addition & 1 deletion spec/env/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ CMD ruby -v && \
bundle config set --local without 'development' && \
bundle install && \
sudo -u postgres ruby -rpg -e "p RUBY_DESCRIPTION, PG::VERSION, PG::POSTGRESQL_LIB_PATH, PG::IS_BINARY_GEM, PG::BUNDLED_LIBPQ_WITH_UNIXSOCKET; puts PG.connect.exec('SELECT version()').values; p PG.connect.host" && \
sudo -u postgres ruby -rpg -S rspec -fd spec/**/*_spec.rb
sudo -u postgres ruby -rpg -S rspec -fd spec/*_spec.rb spec/**/*_spec.rb
2 changes: 1 addition & 1 deletion spec/env/Dockerfile.centos
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ CMD ruby -v && \
bundle config set --local without 'development' && \
bundle install && \
sudo -u postgres ruby -rpg -e "p RUBY_DESCRIPTION, PG::VERSION, PG::POSTGRESQL_LIB_PATH, PG::IS_BINARY_GEM, PG::BUNDLED_LIBPQ_WITH_UNIXSOCKET; puts PG.connect.exec('SELECT version()').values; p PG.connect.host" && \
sudo -u postgres ruby -rpg -S rspec -fd spec/**/*_spec.rb
sudo -u postgres ruby -rpg -S rspec -fd spec/*_spec.rb spec/**/*_spec.rb
26 changes: 26 additions & 0 deletions spec/pg_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,30 @@
[PG.library_version, PG.version_string, PG.threadsafe?, PG::VERSION, PG::POSTGRESQL_LIB_PATH]
)
end

it "native gem's C-ext file shouldn't contain any rpath or other build-related paths" do
skip "applies to native binary gems only" unless PG::IS_BINARY_GEM
cext_fname = $LOADED_FEATURES.grep(/pg_ext/).first
expect(cext_fname).not_to be_nil
cext_text = File.binread(cext_fname)
expect(cext_text).to match(/Init_pg_ext/) # C-ext shoud contain the init function
expect(cext_text).not_to match(/usr\/local/) # there should be no rpath to /usr/local/rake-compiler/ruby/x86_64-unknown-linux-musl/ruby-3.4.5/lib or so
expect(cext_text).not_to match(/home\//) # there should be no path to /home/ or so
end

it "native gem's libpq file shouldn't contain any rpath or other build-related paths" do
skip "applies to native binary gems only" unless PG::IS_BINARY_GEM

libpq_fname = case RUBY_PLATFORM
when /mingw|mswin/ then "libpq.dll"
when /linux/ then "libpq-ruby-pg.so.1"
when /darwin/ then "libpq-ruby-pg.1.dylib"
end

path = File.join(PG::POSTGRESQL_LIB_PATH, libpq_fname)
text = File.binread(path)
expect(text).to match(/PQconnectdb/) # libpq shoud contain the connect function
expect(text).not_to match(/usr\/local/) # there should be no rpath to build dirs
expect(text).not_to match(/home\//) # there should be no path to /home/.../ports/ or so
end
end
Loading