1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
# -*- rake -*-
# Enable english error messages, as some specs depend on them
ENV["LANG"] = "C"
require 'rbconfig'
require 'pathname'
require 'tmpdir'
require 'rake/extensiontask'
require 'rake/clean'
require 'rspec/core/rake_task'
require 'bundler'
require 'bundler/gem_helper'
require_relative "rakelib/pg_gem_helper"
# Build directory constants
BASEDIR = Pathname( __FILE__ ).dirname
SPECDIR = BASEDIR + 'spec'
LIBDIR = BASEDIR + 'lib'
EXTDIR = BASEDIR + 'ext'
PKGDIR = BASEDIR + 'pkg'
TMPDIR = BASEDIR + 'tmp'
TESTDIR = BASEDIR + "tmp_test_*"
DLEXT = RbConfig::CONFIG['DLEXT']
EXT = LIBDIR + "pg_ext.#{DLEXT}"
GEMSPEC = 'pg.gemspec'
CLEAN.include( TESTDIR.to_s )
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"
CLEAN.include "ports/*.installed"
CLEAN.include "ports/*mingw*", "ports/*linux*", "ports/*darwin*"
PgGemHelper.install_tasks
$gem_spec = Bundler.load_gemspec(GEMSPEC)
desc "Turn on warnings and debugging in the build."
task :maint do
ENV['MAINTAINER_MODE'] = 'yes'
end
CrossLibrary = Struct.new :platform, :openssl_config, :toolchain
CrossLibraries = [
['aarch64-mingw-ucrt', 'mingwarm64', 'aarch64-w64-mingw32'],
['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-linux-gnu'],
['x86_64-linux-musl', 'linux-x86_64', 'x86_64-unknown-linux-musl'],
['aarch64-linux', 'linux-aarch64', 'aarch64-linux-gnu'],
['aarch64-linux-musl', 'linux-aarch64', 'aarch64-linux-musl'],
['x86_64-darwin', 'darwin64-x86_64', 'x86_64-apple-darwin'],
['arm64-darwin', 'darwin64-arm64', 'arm64-apple-darwin'],
].map do |platform, openssl_config, toolchain|
CrossLibrary.new platform, openssl_config, toolchain
end
# Register binary gems to be pushed to rubygems.org
Bundler::GemHelper.instance.cross_platforms = CrossLibraries.map(&:platform)
# Rake-compiler task
Rake::ExtensionTask.new do |ext|
ext.name = 'pg_ext'
ext.gem_spec = $gem_spec
ext.ext_dir = 'ext'
ext.lib_dir = 'lib'
ext.source_pattern = "*.{c,h}"
ext.cross_compile = true
# 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>[\w\.]+)-mri-(?<platform>[-\w]+)$/)
m && m[:platform] == pl
end
ext.cross_config_options += CrossLibraries.map do |xlib|
{
xlib.platform => [
"--with-cross-build=#{xlib.platform}",
"--with-openssl-platform=#{xlib.openssl_config}",
"--with-toolchain=#{xlib.toolchain}",
]
}
end
# Add libpq.dll/.so to fat binary gemspecs
ext.cross_compiling do |spec|
spec.files << "ports/#{spec.platform.to_s}/lib/libpq-ruby-pg.so.1" if spec.platform.to_s =~ /linux/
spec.files << "ports/#{spec.platform.to_s}/lib/libpq-ruby-pg.1.dylib" if spec.platform.to_s =~ /darwin/
spec.files << "ports/#{spec.platform.to_s}/lib/libpq.dll" if spec.platform.to_s =~ /mingw|mswin/
# Binary gems don't postgresql header+lib files
spec.metadata.delete("msys2_mingw_dependencies")
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 --all"
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
task 'install_darwin_mig', [:arch] do |t, args|
sh <<~EOT
rm -rf bootstrap_cmds &&
git clone --branch=cross_platform https://github.com/markmentovai/bootstrap_cmds &&
cd bootstrap_cmds &&
autoreconf --install &&
sh configure &&
make &&
sed -E -i 's/^cppflags=(.*)/cppflags=(\\1 "-D#{args[:arch]}" "-I\\/opt\\/osxcross\\/target\\/SDK\\/MacOSX11.1.sdk\\/usr\\/include")/' migcom.tproj/mig.sh &&
sudo make install
EOT
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 apt-get update && sudo apt-get install -y bison flex &&" if platform =~ /darwin/ }
#{ # remove nm on Linux to suppress PostgreSQL's check for exit which raises thread_exit as a false positive:
"sudo mv `which nm` `which nm`.bak &&" if platform =~ /linux/ }
sudo apt-get update && sudo apt-get install -y bison flex &&
(cp build/gem/gem-*.pem ~/.gem/ || true) &&
bundle install --local &&
#{ "rake install_darwin_mig[__arm64__]" if platform =~ /arm64-darwin/ }
#{ "rake install_darwin_mig[__x86_64__]" if platform =~ /x86_64-darwin/ }
rake native:#{platform} pkg/#{$gem_spec.full_name}-#{platform}.gem MAKEFLAGS="-j`nproc` V=1" RUBY_CC_VERSION=#{RakeCompilerDock.ruby_cc_version("~>2.7", "~>3.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"
task :test => :spec
# Use the fivefish formatter for docs generated from development checkout
require 'rdoc/task'
RDoc::Task.new( 'docs' ) do |rdoc|
rdoc.options = $gem_spec.rdoc_options
rdoc.rdoc_files = $gem_spec.extra_rdoc_files
rdoc.generator = :fivefish
rdoc.rdoc_dir = 'doc'
end
desc "Build the source gem #{$gem_spec.full_name}.gem into the pkg directory"
task :gem => :build
task :clobber do
puts "Stop any Postmaster instances that remain after testing."
require_relative 'spec/helpers'
PG::TestingHelpers.stop_existing_postmasters()
end
desc "Update list of server error codes"
task :update_error_codes do
URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=refs/tags/REL_17_0"
ERRORCODES_TXT = "ext/errorcodes.txt"
sh "wget #{URL_ERRORCODES_TXT.inspect} -O #{ERRORCODES_TXT.inspect} || curl #{URL_ERRORCODES_TXT.inspect} -o #{ERRORCODES_TXT.inspect}"
ruby 'ext/errorcodes.rb', 'ext/errorcodes.txt', 'ext/errorcodes.def'
end
file 'ext/pg_errors.c' => ['ext/errorcodes.def'] do
# trigger compilation of changed errorcodes.def
touch 'ext/pg_errors.c'
end
desc "Translate readme"
task :translate do
cd "translation" do
# po4a's lexer might change, so record its version for reference
sh "LANG=C po4a --version > .po4a-version"
sh "po4a po4a.cfg"
end
end
|