Skip to content

Commit

Permalink
Add fat binary gem for x86_64-linux
Browse files Browse the repository at this point in the history
- Rename rake task 'gem:windows' to 'gem:native'
- Add `rake gem:native:x86_64-linux`
- Replace own PostgreSQL and OpenSSL build tasks by MiniPortile
  This is a more standard way and allows easier extensions.
- Add krb5 library for Linux target to support GSSAPI/Kerberos
- Change loading of pg_ext
  Try lib/pg_ext in addition to lib/3.2/pg_ext to support `rake spec` in the build directory
- Fat binary linux gem: Try different UnixSocket paths of different distros.
- CI: Adjust binary tests for new cross build target
- Change patch directory to ports/patches/<package>/<version>/*.patch
  • Loading branch information
larskanis committed Nov 24, 2023
1 parent 2218ebf commit 49e89b9
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 330 deletions.
32 changes: 19 additions & 13 deletions .github/workflows/binary-gems.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- platform: "x64-mingw-ucrt"
- platform: "x64-mingw32"
- platform: "x86-mingw32"
- platform: "x86_64-linux"
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
Expand All @@ -34,7 +35,7 @@ jobs:
cp gem-public_cert.pem ~/.gem/gem-public_cert.pem
- name: Build binary gem
run: bundle exec rake gem:windows:${{ matrix.platform }}
run: bundle exec rake gem:native:${{ matrix.platform }}

- name: Upload binary gem
uses: actions/upload-artifact@v3
Expand All @@ -61,6 +62,9 @@ jobs:
ruby: "2.5"
platform: "x64-mingw32"
PGVERSION: 10.20-1-windows
- os: ubuntu-latest
ruby: "3.2"
platform: "x86_64-linux"

runs-on: ${{ matrix.os }}
env:
Expand All @@ -69,9 +73,12 @@ jobs:
- uses: actions/checkout@v3
- name: Set up Ruby
if: matrix.platform != 'x86-mingw32'
uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby-pkgs@v1
with:
ruby-version: ${{ matrix.ruby }}
apt-get: "postgresql" # Ubuntu
brew: "postgresql" # macOS
mingw: "postgresql" # Windows mingw / mswin /ucrt

- name: Set up 32 bit x86 Ruby
if: matrix.platform == 'x86-mingw32'
Expand All @@ -81,25 +88,17 @@ jobs:
echo "c:/ruby-${{ matrix.ruby }}/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
c:/ruby-${{ matrix.ruby }}/bin/ridk enable
c:/msys64/usr/bin/bash -lc "pacman -S --noconfirm --needed make `${MINGW_PACKAGE_PREFIX}-pkgconf `${MINGW_PACKAGE_PREFIX}-libyaml `${MINGW_PACKAGE_PREFIX}-gcc `${MINGW_PACKAGE_PREFIX}-make"
c:/msys64/usr/bin/bash -lc "pacman -S --noconfirm --needed make `${MINGW_PACKAGE_PREFIX}-pkgconf `${MINGW_PACKAGE_PREFIX}-libyaml `${MINGW_PACKAGE_PREFIX}-gcc `${MINGW_PACKAGE_PREFIX}-make `${MINGW_PACKAGE_PREFIX}-postgresql"
echo "C:/msys64/$env:MSYSTEM_PREFIX/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Download gem from build job
uses: actions/download-artifact@v3
with:
name: binary-gem

- name: Download PostgreSQL
- name: set PGUSER
if: ${{ matrix.os == 'windows-latest' }}
run: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip {
param([string]$zipfile, [string]$outpath)
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}
$(new-object net.webclient).DownloadFile("http://get.enterprisedb.com/postgresql/postgresql-$env:PGVERSION-binaries.zip", "postgresql-binaries.zip")
Unzip "postgresql-binaries.zip" "."
echo "$pwd/pgsql/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "PGUSER=$env:USERNAME" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "PGPASSWORD=" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Expand All @@ -108,10 +107,17 @@ jobs:
- run: bundle install
- run: gem install --local pg-*${{ matrix.platform }}.gem --verbose
- name: Run specs
if: ${{ matrix.os != 'windows-latest' }}
run: ruby -rpg -S rspec -fd spec/**/*_spec.rb
- name: Run specs
if: ${{ matrix.os == 'windows-latest' }}
run: |
ridk enable
ruby -rpg -S rspec -fd spec/**/*_spec.rb
- name: Print logs if job failed
if: ${{ failure() && matrix.os == 'windows-latest' }}
run: |
ridk enable
find "$(ruby -e"puts RbConfig::CONFIG[%q[libdir]]")" -name mkmf.log -print0 | xargs -0 cat
find -name setup.log -print0 | xargs -0 cat
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ group :development, :test do
gem "rake-compiler-dock", "~> 1.0"
gem "rdoc", "~> 6.4"
gem "rspec", "~> 3.5"
gem "mini_portile2", "~> 2.1"
end
2 changes: 1 addition & 1 deletion README-Windows.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ sure it is started. A native Docker installation is best on Linux.

Then run:

rake gem:windows
rake gem:native

This will download a docker image suited for building windows gems, and it
will download and build OpenSSL and PostgreSQL. Finally the gem is built
Expand Down
60 changes: 50 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ CLEAN.include( PKGDIR.to_s, TMPDIR.to_s )
CLEAN.include "lib/*/libpq.dll"
CLEAN.include "lib/pg_ext.*"
CLEAN.include "lib/pg/postgresql_lib_path.rb"

load 'Rakefile.cross'
CLEAN.include "ports/*.installed"
CLEAN.include "ports/*mingw*", "ports/*linux*"

Bundler::GemHelper.install_tasks
$gem_spec = Bundler.load_gemspec(GEMSPEC)
Expand All @@ -42,6 +42,16 @@ task :maint do
ENV['MAINTAINER_MODE'] = 'yes'
end

CrossLibrary = Struct.new :platform, :openssl_config, :toolchain
CrossLibraries = [
['x64-mingw-ucrt', 'mingw64', 'x86_64-w64-mingw32'],
['x86-mingw32', 'mingw', 'i686-w64-mingw32'],
['x64-mingw32', 'mingw64', 'x86_64-w64-mingw32'],
['x86_64-linux', 'linux-x86_64', 'x86_64-redhat-linux'],
].map do |platform, openssl_config, toolchain|
CrossLibrary.new platform, openssl_config, toolchain
end

# Rake-compiler task
Rake::ExtensionTask.new do |ext|
ext.name = 'pg_ext'
Expand All @@ -50,24 +60,54 @@ Rake::ExtensionTask.new do |ext|
ext.lib_dir = 'lib'
ext.source_pattern = "*.{c,h}"
ext.cross_compile = true
ext.cross_platform = CrossLibraries.map(&:for_platform)
ext.cross_platform = CrossLibraries.map(&:platform)

ext.cross_config_options += CrossLibraries.map do |lib|
ext.cross_config_options += CrossLibraries.map do |xlib|
{
lib.for_platform => [
xlib.platform => [
"--enable-windows-cross",
"--with-pg-include=#{lib.static_postgresql_incdir}",
"--with-pg-lib=#{lib.static_postgresql_libdir}",
# libpq-fe.h resides in src/interfaces/libpq/ before make install
"--with-opt-include=#{lib.static_postgresql_libdir}",
"--with-openssl-platform=#{xlib.openssl_config}",
"--with-toolchain=#{xlib.toolchain}",
]
}
end

# Add libpq.dll to windows binary gemspec
ext.cross_compiling do |spec|
spec.files << "lib/#{spec.platform}/libpq.dll"
spec.files << "ports/#{spec.platform.to_s}/lib/libpq.so.5" if spec.platform.to_s =~ /linux/
spec.files << "ports/#{spec.platform.to_s}/lib/libpq.dll" if spec.platform.to_s =~ /mingw|mswin/
end
end

task 'gem:native:prepare' do
require 'io/console'
require 'rake_compiler_dock'

# 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"
begin
OpenSSL::PKey.read(File.read(File.expand_path("~/.gem/gem-private_key.pem")), ENV["GEM_PRIVATE_KEY_PASSPHRASE"] || "")
rescue OpenSSL::PKey::PKeyError
ENV["GEM_PRIVATE_KEY_PASSPHRASE"] = STDIN.getpass("Enter passphrase of gem signature key: ")
retry
end
end

CrossLibraries.each do |xlib|
platform = xlib.platform
desc "Build fat binary gem for platform #{platform}"
task "gem:native:#{platform}" => ['gem:native:prepare'] do
RakeCompilerDock.sh <<-EOT, platform: platform
#{ "sudo yum install -y perl-IPC-Cmd &&" if platform =~ /linux/ }
(cp build/gem/gem-*.pem ~/.gem/ || true) &&
bundle install --local &&
rake native:#{platform} pkg/#{$gem_spec.full_name}-#{platform}.gem MAKE="make -j`nproc`" RUBY_CC_VERSION=3.2.0:3.1.0:3.0.0:2.7.0:2.6.0:2.5.0
EOT
end
desc "Build the native binary gems"
multitask 'gem:native' => "gem:native:#{platform}"
end

RSpec::Core::RakeTask.new(:spec).rspec_opts = "--profile -cfdoc"
Expand Down
Loading

0 comments on commit 49e89b9

Please sign in to comment.