pg 1.5.9 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/{History.md → CHANGELOG.md} +54 -0
- data/Gemfile +7 -4
- data/README-Windows.rdoc +1 -1
- data/README.ja.md +4 -4
- data/README.md +58 -17
- data/Rakefile +91 -13
- data/ext/extconf.rb +158 -14
- data/ext/gvl_wrappers.c +13 -2
- data/ext/gvl_wrappers.h +33 -0
- data/ext/pg.c +16 -5
- data/ext/pg.h +9 -9
- data/ext/pg_binary_decoder.c +150 -0
- data/ext/pg_binary_encoder.c +210 -7
- data/ext/pg_cancel_connection.c +360 -0
- data/ext/pg_coder.c +54 -5
- data/ext/pg_connection.c +368 -158
- data/ext/pg_copy_coder.c +2 -2
- data/ext/pg_record_coder.c +1 -1
- data/ext/pg_result.c +9 -11
- data/ext/pg_text_encoder.c +20 -7
- data/ext/pg_tuple.c +2 -2
- data/ext/pg_type_map.c +1 -1
- data/ext/pg_type_map_all_strings.c +1 -1
- data/ext/pg_type_map_by_class.c +1 -1
- data/ext/pg_type_map_by_column.c +2 -1
- data/ext/pg_type_map_by_mri_type.c +1 -1
- data/ext/pg_type_map_by_oid.c +3 -1
- data/ext/pg_type_map_in_ruby.c +1 -1
- data/lib/pg/basic_type_map_for_queries.rb +7 -3
- data/lib/pg/basic_type_registry.rb +2 -2
- data/lib/pg/cancel_connection.rb +53 -0
- data/lib/pg/coder.rb +4 -2
- data/lib/pg/connection.rb +254 -131
- data/lib/pg/version.rb +1 -1
- data/lib/pg.rb +13 -8
- data/misc/yugabyte/Dockerfile +9 -0
- data/misc/yugabyte/docker-compose.yml +28 -0
- data/misc/yugabyte/pg-test.rb +45 -0
- data/pg.gemspec +5 -3
- data/ports/patches/krb5/1.21.3/0001-Allow-static-linking-krb5-library.patch +30 -0
- data/ports/patches/openssl/3.5.1/0001-aarch64-mingw.patch +21 -0
- data/ports/patches/postgresql/17.5/0001-Use-workaround-of-__builtin_setjmp-only-on-MINGW-on-.patch +42 -0
- data/ports/patches/postgresql/17.5/0001-libpq-Process-buffered-SSL-read-bytes-to-support-rec.patch +52 -0
- data/rakelib/pg_gem_helper.rb +64 -0
- data.tar.gz.sig +0 -0
- metadata +32 -21
- metadata.gz.sig +0 -0
- data/Manifest.txt +0 -72
- data/Rakefile.cross +0 -303
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c220f1cc5cfd8e07690949fcf30a96abd8f710bc64f0c358eb6452288966a5b4
|
4
|
+
data.tar.gz: cd5f28d3098e2537e04dc218c8809b83308cb541e6b17891220559d33e2ada82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5de3fb30c6da95937d6c8913c9e172a348fa376edc6f06cc9333669c908a25cb2af85853aafbdc6839407f6b4aea93ca97e3b5b53f7182732664ecd6cd81e33
|
7
|
+
data.tar.gz: 00f5c6e8c359e81bf7c9145b7322583e511d440f681d32192430d9ce96772f1d71f8abce35e12ccf126d96a552205e799efee2533c54a84c623fa0aeee5c1c3c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/{History.md → CHANGELOG.md}
RENAMED
@@ -1,3 +1,57 @@
|
|
1
|
+
## v1.6.1 [2025-08-03] Lars Kanis <lars@greiz-reinsdorf.de>
|
2
|
+
|
3
|
+
- Add binary gems for platforms `aarch64-linux-musl` and `x86_64-linux-musl` without the need to install package `gcompat`. [#657](https://github.com/ged/ruby-pg/pull/657).
|
4
|
+
- Serialize CompositeCoder#dimensions only when set. [#652](https://github.com/ged/ruby-pg/pull/652)
|
5
|
+
This fixes the compatibility to pg-1.5.9, when deserializing Marshal data from pg-1.6, as long as the new attribute isn't used.
|
6
|
+
- Remove dependency to MSYS2 package "postgresql" from binary Windows gem [#654](https://github.com/ged/ruby-pg/pull/654)
|
7
|
+
|
8
|
+
|
9
|
+
## v1.6.0 [2025-07-27] Lars Kanis <lars@greiz-reinsdorf.de>
|
10
|
+
|
11
|
+
Added:
|
12
|
+
|
13
|
+
- Add binary gems for Ruby 3.4.
|
14
|
+
- Add fat binary gem for platform `aarch64-mingw-ucrt` aka Windows on ARM [#626](https://github.com/ged/ruby-pg/pull/626), for platform Macos on Intel and ARM [#643](https://github.com/ged/ruby-pg/pull/643), for platform `aarch64-linux` [#646](https://github.com/ged/ruby-pg/pull/646) and for platform `x86_64-linux` [#551](https://github.com/ged/ruby-pg/pull/551#issuecomment-2504715762).
|
15
|
+
- Update fat binary gem to OpenSSL-3.5.1 and PostgreSQL-17.5.
|
16
|
+
- Add a patch to libpq to avoid starvation on bigger SSL records, which some database engines other than vanilla PostgreSQL use.
|
17
|
+
This patch applies to platform specific binary gems only.
|
18
|
+
[#616](https://github.com/ged/ruby-pg/pull/616)
|
19
|
+
- Add support for new query cancel functions of PostgreSQL-17.
|
20
|
+
This adds the new class `PG::CancelConnection` which provides the ability to cancel a query per blocking or per non-blocking functions.
|
21
|
+
If the new functions are available they are used and the older are no longer compiled in.
|
22
|
+
This way we can get rid of reading out the internal `PGcancel` struct by `Connection#backend_key`.
|
23
|
+
[#614](https://github.com/ged/ruby-pg/pull/614)
|
24
|
+
- Add PG::BinaryDecoder::Array and PG::BinaryEncoder::Array to parse and encode PostgreSQL arrays in binary format.
|
25
|
+
[#603](https://github.com/ged/ruby-pg/pull/603)
|
26
|
+
- Add possibility to define the number of array dimensions to be encoded.
|
27
|
+
Setting dimensions is especially useful, when a Record shall be encoded into an Array, since the Array encoder can not distinguish if the array shall be encoded as a higher dimension or as a record otherwise.
|
28
|
+
[#622](https://github.com/ged/ruby-pg/pull/622)
|
29
|
+
- Add Connection#set_chunked_rows_mode [#610](https://github.com/ged/ruby-pg/pull/610)
|
30
|
+
- Add PG::Connection#close_prepared, PG::Connection#close_portal, PG::Connection#send_close_prepared and PG::Connection#send_close_portal which are new in PostgreSQL-17.
|
31
|
+
[#611](https://github.com/ged/ruby-pg/pull/611)
|
32
|
+
- Add Connection#send_pipeline_sync, async_pipeline_sync and release GVL at PQ(sendP|P)ipelineSync.
|
33
|
+
[#612](https://github.com/ged/ruby-pg/pull/612)
|
34
|
+
- Add MINGW package dependency which is resolved by RubyInstaller.
|
35
|
+
[#617](https://github.com/ged/ruby-pg/pull/617)
|
36
|
+
- Change `conn.server_version` and `conn.protocol_version` to raise instead of return 0 on error.
|
37
|
+
[#632](https://github.com/ged/ruby-pg/pull/632)
|
38
|
+
- Fix connecting to multiple hosts after `connnect_timeout`.
|
39
|
+
[#637](https://github.com/ged/ruby-pg/pull/637)
|
40
|
+
- Fix making PG::BasicTypeMapForQueries shareable for Ractor in ruby-3.5.
|
41
|
+
[#636](https://github.com/ged/ruby-pg/pull/636)
|
42
|
+
- Fix missing array input verification in PG::TypeMapByColumn.
|
43
|
+
This could cause a segfault.
|
44
|
+
[#620](https://github.com/ged/ruby-pg/pull/620)
|
45
|
+
- Rename `History.md` to `CHANGELOG.md`, which is more common.
|
46
|
+
[#642](https://github.com/ged/ruby-pg/pull/642)
|
47
|
+
|
48
|
+
Removed:
|
49
|
+
|
50
|
+
- Drop support of Ruby < 2.7 [#606](https://github.com/ged/ruby-pg/pull/606)
|
51
|
+
- Drop support of PostgreSQL < 10 [#606](https://github.com/ged/ruby-pg/pull/606)
|
52
|
+
- Remove workaround for Truffleruby < 21.3.0 [#613](https://github.com/ged/ruby-pg/pull/613)
|
53
|
+
|
54
|
+
|
1
55
|
## v1.5.9 [2024-10-24] Lars Kanis <lars@greiz-reinsdorf.de>
|
2
56
|
|
3
57
|
- Enable thread safety in static OpenSSL build for Windows. [#595](https://github.com/ged/ruby-pg/pull/595)
|
data/Gemfile
CHANGED
@@ -5,13 +5,16 @@ gemspec
|
|
5
5
|
|
6
6
|
source "https://rubygems.org/"
|
7
7
|
|
8
|
-
group :development
|
8
|
+
group :development do
|
9
|
+
gem "rdoc", "~> 6.4"
|
10
|
+
gem "mini_portile2", "~> 2.1"
|
11
|
+
end
|
12
|
+
|
13
|
+
group :test do
|
9
14
|
gem "bundler", ">= 1.16", "< 3.0"
|
10
15
|
gem "rake-compiler", "~> 1.0"
|
11
|
-
gem "rake-compiler-dock", "~> 1.
|
12
|
-
gem "rdoc", "~> 6.4"
|
16
|
+
gem "rake-compiler-dock", "~> 1.9.1"
|
13
17
|
gem "rspec", "~> 3.5"
|
14
|
-
gem "ostruct", "~> 0.5" # for Rakefile.cross
|
15
18
|
# "bigdecimal" is a gem on ruby-3.4+ and it's optional for ruby-pg.
|
16
19
|
# Specs should succeed without it, but 4 examples are then excluded.
|
17
20
|
# With bigdecimal commented out here, corresponding tests are omitted on ruby-3.4+ but are executed on ruby < 3.4.
|
data/README-Windows.rdoc
CHANGED
@@ -41,7 +41,7 @@ sure it is started. A native Docker installation is best on Linux.
|
|
41
41
|
|
42
42
|
Then run:
|
43
43
|
|
44
|
-
rake gem:
|
44
|
+
rake gem:native
|
45
45
|
|
46
46
|
This will download a docker image suited for building windows gems, and it
|
47
47
|
will download and build OpenSSL and PostgreSQL. Finally the gem is built
|
data/README.ja.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
* ホーム :: https://github.com/ged/ruby-pg
|
4
4
|
* ドキュメント :: http://deveiate.org/code/pg (英語)、 https://deveiate.org/code/pg/README_ja_md.html (日本語)
|
5
|
-
* 変更履歴 :: link:/
|
5
|
+
* 変更履歴 :: link:/CHANGELOG.md
|
6
6
|
|
7
7
|
[](https://gitter.im/ged/ruby-pg?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
Pgは[PostgreSQL
|
14
14
|
RDBMS](http://www.postgresql.org/)へのRubyのインターフェースです。[PostgreSQL
|
15
|
-
|
15
|
+
10以降](http://www.postgresql.org/support/versioning/)で動作します。
|
16
16
|
|
17
17
|
簡単な使用例は次の通りです。
|
18
18
|
```ruby
|
@@ -41,8 +41,8 @@ Actionsのビルド状況](https://github.com/ged/ruby-pg/actions/workflows/sour
|
|
41
41
|
|
42
42
|
## 要件
|
43
43
|
|
44
|
-
* Ruby 2.
|
45
|
-
* PostgreSQL
|
44
|
+
* Ruby 2.7かそれより新しいバージョン
|
45
|
+
* PostgreSQL 10.xかそれ以降のバージョン(ヘッダー付属のもの、例えば-devの名前のパッケージ)。
|
46
46
|
|
47
47
|
それより前のバージョンのRubyやPostgreSQLでも通常は同様に動作しますが、定期的なテストはされていません。
|
48
48
|
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
* home :: https://github.com/ged/ruby-pg
|
4
4
|
* docs :: http://deveiate.org/code/pg (English) ,
|
5
5
|
https://deveiate.org/code/pg/README_ja_md.html (Japanese)
|
6
|
-
* clog :: link:/
|
6
|
+
* clog :: link:/CHANGELOG.md
|
7
7
|
|
8
8
|
[](https://gitter.im/ged/ruby-pg?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
9
9
|
|
@@ -11,7 +11,7 @@
|
|
11
11
|
## Description
|
12
12
|
|
13
13
|
Pg is the Ruby interface to the [PostgreSQL RDBMS](http://www.postgresql.org/).
|
14
|
-
It works with [PostgreSQL
|
14
|
+
It works with [PostgreSQL 10 and later](http://www.postgresql.org/support/versioning/).
|
15
15
|
|
16
16
|
A small example usage:
|
17
17
|
```ruby
|
@@ -39,30 +39,35 @@ A small example usage:
|
|
39
39
|
|
40
40
|
## Requirements
|
41
41
|
|
42
|
-
* Ruby 2.
|
43
|
-
* PostgreSQL
|
42
|
+
* Ruby 2.7 or newer
|
43
|
+
* PostgreSQL 10.x or later
|
44
|
+
* When installing the source gem: libpq with headers, -dev packages, etc.
|
44
45
|
|
45
|
-
It usually works with earlier versions of Ruby/PostgreSQL as well, but those are
|
46
|
-
not regularly tested.
|
47
46
|
|
47
|
+
## How To Install
|
48
48
|
|
49
|
-
|
49
|
+
Install via RubyGems:
|
50
50
|
|
51
|
-
|
51
|
+
gem install pg
|
52
52
|
|
53
|
-
|
53
|
+
This installs the binary gem, specific to the running platform by default.
|
54
54
|
|
55
|
-
|
55
|
+
### Binary gem
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
```
|
57
|
+
The binary gems don't depend on the libpq package on the running system.
|
58
|
+
They have libpq builtin.
|
60
59
|
|
61
|
-
|
60
|
+
The gems for platform `x86_64-linux` and `aarch64-linux` run on Alpine Linux, but require the package `gcompat` there as long as we don't provide a native gem for platform `x86_64-linux-musl`. Install this package like so:
|
62
61
|
|
63
|
-
|
62
|
+
apk add gcompat
|
64
63
|
|
65
|
-
|
64
|
+
There is one use case the binary gems don't support: Retrieval of connection [options from LDAP](https://www.postgresql.org/docs/current/libpq-ldap.html). To support this `libldap` would be necessary, but it has a lot of dependencies. It doesn't seem to be a widely used feature and that it's worth to support it. If it's necessary, the source gem can be forced.
|
65
|
+
|
66
|
+
### Source gem
|
67
|
+
|
68
|
+
The source gem can be forced by:
|
69
|
+
|
70
|
+
gem install pg --platform ruby
|
66
71
|
|
67
72
|
You may need to specify the path to the 'pg_config' program installed with
|
68
73
|
Postgres:
|
@@ -73,6 +78,28 @@ If you're installing via Bundler, you can provide compile hints like so:
|
|
73
78
|
|
74
79
|
bundle config build.pg --with-pg-config=<path to pg_config>
|
75
80
|
|
81
|
+
### Bundler
|
82
|
+
|
83
|
+
To make sure, the necessary platforms and the source gem are fetched by bundler, they can be added like so
|
84
|
+
|
85
|
+
```
|
86
|
+
bundle lock --add-platform x86_64-linux
|
87
|
+
bundle lock --add-platform arm64-darwin
|
88
|
+
bundle lock --add-platform x64-mingw-ucrt
|
89
|
+
bundle lock --add-platform ruby
|
90
|
+
bundle package --all-platforms
|
91
|
+
```
|
92
|
+
|
93
|
+
A re-run of `bundle package` is also necessary after `bundle update`, in order to retrieve the new specific gems of all platforms.
|
94
|
+
|
95
|
+
If the binary gems don't work for some reason, it's easy to force the usage of the source gem in the Gemfile:
|
96
|
+
|
97
|
+
```
|
98
|
+
gem "pg", force_ruby_platform: true
|
99
|
+
```
|
100
|
+
|
101
|
+
### More
|
102
|
+
|
76
103
|
See README-OS_X.rdoc for more information about installing under MacOS X, and
|
77
104
|
README-Windows.rdoc for Windows build/installation instructions.
|
78
105
|
|
@@ -85,6 +112,19 @@ can be found in [the `certs` directory](https://github.com/ged/ruby-pg/tree/mast
|
|
85
112
|
of the repository.
|
86
113
|
|
87
114
|
|
115
|
+
## Versioning
|
116
|
+
|
117
|
+
We tag and release gems according to the [Semantic Versioning](http://semver.org/) principle.
|
118
|
+
|
119
|
+
As a result of this policy, you can (and should) specify a dependency on this gem using the [Pessimistic Version Constraint](http://guides.rubygems.org/patterns/#pessimistic-version-constraint) with two digits of precision.
|
120
|
+
|
121
|
+
For example:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
spec.add_dependency 'pg', '~> 1.0'
|
125
|
+
```
|
126
|
+
|
127
|
+
|
88
128
|
## Type Casts
|
89
129
|
|
90
130
|
Pg can optionally type cast result values and query parameters in Ruby or
|
@@ -141,7 +181,7 @@ The following PostgreSQL column types are supported by ruby-pg (TE = Text Encode
|
|
141
181
|
* Date: [TE](rdoc-ref:PG::TextEncoder::Date), [TD](rdoc-ref:PG::TextDecoder::Date), [BE](rdoc-ref:PG::BinaryEncoder::Date), [BD](rdoc-ref:PG::BinaryDecoder::Date)
|
142
182
|
* JSON and JSONB: [TE](rdoc-ref:PG::TextEncoder::JSON), [TD](rdoc-ref:PG::TextDecoder::JSON)
|
143
183
|
* Inet: [TE](rdoc-ref:PG::TextEncoder::Inet), [TD](rdoc-ref:PG::TextDecoder::Inet)
|
144
|
-
* Array: [TE](rdoc-ref:PG::TextEncoder::Array), [TD](rdoc-ref:PG::TextDecoder::Array)
|
184
|
+
* Array: [TE](rdoc-ref:PG::TextEncoder::Array), [TD](rdoc-ref:PG::TextDecoder::Array), [BE](rdoc-ref:PG::BinaryEncoder::Array), [BD](rdoc-ref:PG::BinaryDecoder::Array)
|
145
185
|
* Composite Type (also called "Row" or "Record"): [TE](rdoc-ref:PG::TextEncoder::Record), [TD](rdoc-ref:PG::TextDecoder::Record)
|
146
186
|
|
147
187
|
The following text and binary formats can also be encoded although they are not used as column type:
|
@@ -175,6 +215,7 @@ The following type maps are prefilled with type mappings from the PG::BasicTypeR
|
|
175
215
|
* PG::BasicTypeMapBasedOnResult - a PG::TypeMapByOid prefilled with encoders for common PostgreSQL column types
|
176
216
|
* PG::BasicTypeMapForQueries - a PG::TypeMapByClass prefilled with encoders for common Ruby value classes
|
177
217
|
|
218
|
+
Several type maps can be chained by setting PG::TypeMap::DefaultTypeMappable#default_type_map .
|
178
219
|
|
179
220
|
## Thread support
|
180
221
|
|
data/Rakefile
CHANGED
@@ -11,6 +11,7 @@ require 'rake/clean'
|
|
11
11
|
require 'rspec/core/rake_task'
|
12
12
|
require 'bundler'
|
13
13
|
require 'bundler/gem_helper'
|
14
|
+
require_relative "rakelib/pg_gem_helper"
|
14
15
|
|
15
16
|
# Build directory constants
|
16
17
|
BASEDIR = Pathname( __FILE__ ).dirname
|
@@ -31,10 +32,10 @@ CLEAN.include( PKGDIR.to_s, TMPDIR.to_s )
|
|
31
32
|
CLEAN.include "lib/*/libpq.dll"
|
32
33
|
CLEAN.include "lib/pg_ext.*"
|
33
34
|
CLEAN.include "lib/pg/postgresql_lib_path.rb"
|
35
|
+
CLEAN.include "ports/*.installed"
|
36
|
+
CLEAN.include "ports/*mingw*", "ports/*linux*", "ports/*darwin*"
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
Bundler::GemHelper.install_tasks
|
38
|
+
PgGemHelper.install_tasks
|
38
39
|
$gem_spec = Bundler.load_gemspec(GEMSPEC)
|
39
40
|
|
40
41
|
desc "Turn on warnings and debugging in the build."
|
@@ -42,6 +43,25 @@ task :maint do
|
|
42
43
|
ENV['MAINTAINER_MODE'] = 'yes'
|
43
44
|
end
|
44
45
|
|
46
|
+
CrossLibrary = Struct.new :platform, :openssl_config, :toolchain
|
47
|
+
CrossLibraries = [
|
48
|
+
['aarch64-mingw-ucrt', 'mingwarm64', 'aarch64-w64-mingw32'],
|
49
|
+
['x64-mingw-ucrt', 'mingw64', 'x86_64-w64-mingw32'],
|
50
|
+
['x86-mingw32', 'mingw', 'i686-w64-mingw32'],
|
51
|
+
['x64-mingw32', 'mingw64', 'x86_64-w64-mingw32'],
|
52
|
+
['x86_64-linux', 'linux-x86_64', 'x86_64-linux-gnu'],
|
53
|
+
['x86_64-linux-musl', 'linux-x86_64', 'x86_64-unknown-linux-musl'],
|
54
|
+
['aarch64-linux', 'linux-aarch64', 'aarch64-linux-gnu'],
|
55
|
+
['aarch64-linux-musl', 'linux-aarch64', 'aarch64-linux-musl'],
|
56
|
+
['x86_64-darwin', 'darwin64-x86_64', 'x86_64-apple-darwin'],
|
57
|
+
['arm64-darwin', 'darwin64-arm64', 'arm64-apple-darwin'],
|
58
|
+
].map do |platform, openssl_config, toolchain|
|
59
|
+
CrossLibrary.new platform, openssl_config, toolchain
|
60
|
+
end
|
61
|
+
|
62
|
+
# Register binary gems to be pushed to rubygems.org
|
63
|
+
Bundler::GemHelper.instance.cross_platforms = CrossLibraries.map(&:platform)
|
64
|
+
|
45
65
|
# Rake-compiler task
|
46
66
|
Rake::ExtensionTask.new do |ext|
|
47
67
|
ext.name = 'pg_ext'
|
@@ -50,24 +70,82 @@ Rake::ExtensionTask.new do |ext|
|
|
50
70
|
ext.lib_dir = 'lib'
|
51
71
|
ext.source_pattern = "*.{c,h}"
|
52
72
|
ext.cross_compile = true
|
53
|
-
ext.cross_platform = CrossLibraries.map(&:for_platform)
|
54
73
|
|
55
|
-
|
74
|
+
# Activate current cross compiled platform only.
|
75
|
+
# This is to work around the issue that `linux` platform is selected in `linux-musl` image.
|
76
|
+
ext.cross_platform = CrossLibraries.map(&:platform).select do |pl|
|
77
|
+
m = ENV["RCD_IMAGE"]&.match(/:(?<ruby_ver>[\d\.]+)-mri-(?<platform>[-\w]+)$/)
|
78
|
+
m && m[:platform] == pl
|
79
|
+
end
|
80
|
+
|
81
|
+
ext.cross_config_options += CrossLibraries.map do |xlib|
|
56
82
|
{
|
57
|
-
|
58
|
-
"--
|
59
|
-
"--with-
|
60
|
-
"--with-
|
61
|
-
# libpq-fe.h resides in src/interfaces/libpq/ before make install
|
62
|
-
"--with-opt-include=#{lib.static_postgresql_libdir}",
|
83
|
+
xlib.platform => [
|
84
|
+
"--with-cross-build=#{xlib.platform}",
|
85
|
+
"--with-openssl-platform=#{xlib.openssl_config}",
|
86
|
+
"--with-toolchain=#{xlib.toolchain}",
|
63
87
|
]
|
64
88
|
}
|
65
89
|
end
|
66
90
|
|
67
|
-
# Add libpq.dll to
|
91
|
+
# Add libpq.dll/.so to fat binary gemspecs
|
68
92
|
ext.cross_compiling do |spec|
|
69
|
-
spec.files << "
|
93
|
+
spec.files << "ports/#{spec.platform.to_s}/lib/libpq-ruby-pg.so.1" if spec.platform.to_s =~ /linux/
|
94
|
+
spec.files << "ports/#{spec.platform.to_s}/lib/libpq-ruby-pg.1.dylib" if spec.platform.to_s =~ /darwin/
|
95
|
+
spec.files << "ports/#{spec.platform.to_s}/lib/libpq.dll" if spec.platform.to_s =~ /mingw|mswin/
|
96
|
+
|
97
|
+
# Binary gems don't postgresql header+lib files
|
98
|
+
spec.metadata.delete("msys2_mingw_dependencies")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
task 'gem:native:prepare' do
|
103
|
+
require 'io/console'
|
104
|
+
require 'rake_compiler_dock'
|
105
|
+
|
106
|
+
# Copy gem signing key and certs to be accessible from the docker container
|
107
|
+
mkdir_p 'build/gem'
|
108
|
+
sh "cp ~/.gem/gem-*.pem build/gem/ || true"
|
109
|
+
sh "bundle package"
|
110
|
+
begin
|
111
|
+
OpenSSL::PKey.read(File.read(File.expand_path("~/.gem/gem-private_key.pem")), ENV["GEM_PRIVATE_KEY_PASSPHRASE"] || "")
|
112
|
+
rescue OpenSSL::PKey::PKeyError
|
113
|
+
ENV["GEM_PRIVATE_KEY_PASSPHRASE"] = STDIN.getpass("Enter passphrase of gem signature key: ")
|
114
|
+
retry
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
task 'install_darwin_mig', [:arch] do |t, args|
|
119
|
+
sh <<~EOT
|
120
|
+
rm -rf bootstrap_cmds &&
|
121
|
+
git clone --branch=cross_platform https://github.com/markmentovai/bootstrap_cmds &&
|
122
|
+
cd bootstrap_cmds &&
|
123
|
+
autoreconf --install &&
|
124
|
+
sh configure &&
|
125
|
+
make &&
|
126
|
+
sed -E -i 's/^cppflags=(.*)/cppflags=(\\1 "-D#{args[:arch]}" "-I\\/opt\\/osxcross\\/target\\/SDK\\/MacOSX11.1.sdk\\/usr\\/include")/' migcom.tproj/mig.sh &&
|
127
|
+
sudo make install
|
128
|
+
EOT
|
129
|
+
end
|
130
|
+
|
131
|
+
CrossLibraries.each do |xlib|
|
132
|
+
platform = xlib.platform
|
133
|
+
desc "Build fat binary gem for platform #{platform}"
|
134
|
+
task "gem:native:#{platform}" => ['gem:native:prepare'] do
|
135
|
+
RakeCompilerDock.sh <<-EOT, platform: platform
|
136
|
+
#{ "sudo apt-get update && sudo apt-get install -y bison flex &&" if platform =~ /darwin/ }
|
137
|
+
#{ # remove nm on Linux to suppress PostgreSQL's check for exit which raises thread_exit as a false positive:
|
138
|
+
"sudo mv `which nm` `which nm`.bak &&" if platform =~ /linux/ }
|
139
|
+
sudo apt-get update && sudo apt-get install -y bison flex &&
|
140
|
+
(cp build/gem/gem-*.pem ~/.gem/ || true) &&
|
141
|
+
bundle install --local &&
|
142
|
+
#{ "rake install_darwin_mig[__arm64__]" if platform =~ /arm64-darwin/ }
|
143
|
+
#{ "rake install_darwin_mig[__x86_64__]" if platform =~ /x86_64-darwin/ }
|
144
|
+
rake native:#{platform} pkg/#{$gem_spec.full_name}-#{platform}.gem MAKEOPTS=-j`nproc` RUBY_CC_VERSION=#{RakeCompilerDock.ruby_cc_version("~>2.7", "~>3.0")}
|
145
|
+
EOT
|
70
146
|
end
|
147
|
+
desc "Build the native binary gems"
|
148
|
+
multitask 'gem:native' => "gem:native:#{platform}"
|
71
149
|
end
|
72
150
|
|
73
151
|
RSpec::Core::RakeTask.new(:spec).rspec_opts = "--profile -cfdoc"
|
data/ext/extconf.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'pp'
|
2
2
|
require 'mkmf'
|
3
3
|
|
4
|
-
|
5
4
|
if ENV['MAINTAINER_MODE']
|
6
5
|
$stderr.puts "Maintainer mode enabled."
|
7
6
|
$CFLAGS <<
|
@@ -24,12 +23,163 @@ else
|
|
24
23
|
$stderr.puts "Calling libpq with GVL locked"
|
25
24
|
end
|
26
25
|
|
27
|
-
if
|
26
|
+
if gem_platform=with_config("cross-build")
|
27
|
+
gem 'mini_portile2', '~>2.1'
|
28
|
+
require 'mini_portile2'
|
29
|
+
|
30
|
+
OPENSSL_VERSION = ENV['OPENSSL_VERSION'] || '3.5.1'
|
31
|
+
OPENSSL_SOURCE_URI = "http://www.openssl.org/source/openssl-#{OPENSSL_VERSION}.tar.gz"
|
32
|
+
|
33
|
+
KRB5_VERSION = ENV['KRB5_VERSION'] || '1.21.3'
|
34
|
+
KRB5_SOURCE_URI = "http://kerberos.org/dist/krb5/#{KRB5_VERSION[/^(\d+\.\d+)/]}/krb5-#{KRB5_VERSION}.tar.gz"
|
35
|
+
|
36
|
+
POSTGRESQL_VERSION = ENV['POSTGRESQL_VERSION'] || '17.5'
|
37
|
+
POSTGRESQL_SOURCE_URI = "http://ftp.postgresql.org/pub/source/v#{POSTGRESQL_VERSION}/postgresql-#{POSTGRESQL_VERSION}.tar.bz2"
|
38
|
+
|
39
|
+
class BuildRecipe < MiniPortile
|
40
|
+
def initialize(name, version, files)
|
41
|
+
super(name, version)
|
42
|
+
self.files = files
|
43
|
+
rootdir = File.expand_path('../..', __FILE__)
|
44
|
+
self.target = File.join(rootdir, "ports")
|
45
|
+
self.patch_files = Dir[File.join(target, "patches", self.name, self.version, "*.patch")].sort
|
46
|
+
end
|
47
|
+
|
48
|
+
def port_path
|
49
|
+
"#{target}/#{RUBY_PLATFORM}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def cook_and_activate
|
53
|
+
checkpoint = File.join(self.target, "#{self.name}-#{self.version}-#{RUBY_PLATFORM}.installed")
|
54
|
+
unless File.exist?(checkpoint)
|
55
|
+
self.cook
|
56
|
+
FileUtils.touch checkpoint
|
57
|
+
end
|
58
|
+
self.activate
|
59
|
+
self
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
openssl_platform = with_config("openssl-platform")
|
64
|
+
toolchain = with_config("toolchain")
|
65
|
+
|
66
|
+
openssl_recipe = BuildRecipe.new("openssl", OPENSSL_VERSION, [OPENSSL_SOURCE_URI]).tap do |recipe|
|
67
|
+
class << recipe
|
68
|
+
attr_accessor :openssl_platform
|
69
|
+
def configure
|
70
|
+
envs = []
|
71
|
+
envs << "CFLAGS=-DDSO_WIN32 -DOPENSSL_THREADS" if RUBY_PLATFORM =~ /mingw|mswin/
|
72
|
+
envs << "CFLAGS=-fPIC -DOPENSSL_THREADS" if RUBY_PLATFORM =~ /linux|darwin/
|
73
|
+
execute('configure', ['env', *envs, "./Configure", openssl_platform, "threads", "-static", "CROSS_COMPILE=#{host}-", configure_prefix], altlog: "config.log")
|
74
|
+
end
|
75
|
+
def compile
|
76
|
+
execute('compile', "#{make_cmd} build_libs")
|
77
|
+
end
|
78
|
+
def install
|
79
|
+
execute('install', "#{make_cmd} install_dev")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
recipe.openssl_platform = openssl_platform
|
84
|
+
recipe.host = toolchain
|
85
|
+
recipe.cook_and_activate
|
86
|
+
end
|
87
|
+
|
88
|
+
if RUBY_PLATFORM =~ /linux|darwin/
|
89
|
+
krb5_recipe = BuildRecipe.new("krb5", KRB5_VERSION, [KRB5_SOURCE_URI]).tap do |recipe|
|
90
|
+
class << recipe
|
91
|
+
def work_path
|
92
|
+
File.join(super, "src")
|
93
|
+
end
|
94
|
+
def configure
|
95
|
+
if RUBY_PLATFORM=~/darwin/
|
96
|
+
ENV["CC"] = host[/^.*[^\.\d]/] + "-clang"
|
97
|
+
ENV["CXX"] = host[/^.*[^\.\d]/] + "-c++"
|
98
|
+
|
99
|
+
# Manually set the correct values for configure checks that libkrb5 won't be
|
100
|
+
# able to perform because we're cross-compiling.
|
101
|
+
ENV["krb5_cv_attr_constructor_destructor"] = "yes"
|
102
|
+
ENV["ac_cv_func_regcomp"] = "yes"
|
103
|
+
ENV["ac_cv_printf_positional"] = "yes"
|
104
|
+
end
|
105
|
+
super
|
106
|
+
end
|
107
|
+
end
|
108
|
+
# We specify -fcommon to get around duplicate definition errors in recent gcc.
|
109
|
+
# See https://github.com/cockroachdb/cockroach/issues/49734
|
110
|
+
recipe.configure_options << "CFLAGS=-fcommon#{" -fPIC" if RUBY_PLATFORM =~ /linux/}"
|
111
|
+
recipe.configure_options << "LDFLAGS=-framework Kerberos" if RUBY_PLATFORM =~ /darwin/
|
112
|
+
recipe.configure_options << "--without-keyutils"
|
113
|
+
recipe.configure_options << "--disable-nls"
|
114
|
+
recipe.configure_options << "--disable-silent-rules"
|
115
|
+
recipe.configure_options << "--without-system-verto"
|
116
|
+
recipe.configure_options << "krb5_cv_attr_constructor_destructor=yes"
|
117
|
+
recipe.configure_options << "ac_cv_func_regcomp=yes"
|
118
|
+
recipe.configure_options << "ac_cv_printf_positional=yes"
|
119
|
+
recipe.host = toolchain
|
120
|
+
recipe.cook_and_activate
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# We build a libpq library file which static links OpenSSL and krb5.
|
125
|
+
# Our builtin libpq is referenced in different ways depending on the OS:
|
126
|
+
# - Window: Add the ports directory at runtime per RubyInstaller::Runtime.add_dll_directory
|
127
|
+
# The file is called "libpq.dll"
|
128
|
+
# - Linux: Add a rpath to pg_ext.so which references the ports directory.
|
129
|
+
# The file is called "libpq-ruby-pg.so.1" to avoid loading of system libpq by accident.
|
130
|
+
# - Macos: Add a reference with relative path in pg_ext.so to the ports directory.
|
131
|
+
# The file is called "libpq-ruby-pg.1.dylib" to avoid loading of other libpq by accident.
|
132
|
+
libpq_orig, libpq_rubypg = case RUBY_PLATFORM
|
133
|
+
when /linux/ then ["libpq.so.5", "libpq-ruby-pg.so.1"]
|
134
|
+
when /darwin/ then ["libpq.5.dylib", "libpq-ruby-pg.1.dylib"]
|
135
|
+
# when /mingw/ then ["libpq.dll", "libpq.dll"] # renaming not needed
|
136
|
+
end
|
137
|
+
|
138
|
+
postgresql_recipe = BuildRecipe.new("postgresql", POSTGRESQL_VERSION, [POSTGRESQL_SOURCE_URI]).tap do |recipe|
|
139
|
+
class << recipe
|
140
|
+
def configure_defaults
|
141
|
+
[
|
142
|
+
"--target=#{host}",
|
143
|
+
"--host=#{host}",
|
144
|
+
'--with-openssl',
|
145
|
+
*(RUBY_PLATFORM=~/linux|darwin/ ? ['--with-gssapi'] : []),
|
146
|
+
'--without-zlib',
|
147
|
+
'--without-icu',
|
148
|
+
'--without-readline',
|
149
|
+
'ac_cv_search_gss_store_cred_into=',
|
150
|
+
]
|
151
|
+
end
|
152
|
+
def compile
|
153
|
+
execute 'compile include', "#{make_cmd} -C src/include install"
|
154
|
+
execute 'compile interfaces', "#{make_cmd} -C src/interfaces install"
|
155
|
+
end
|
156
|
+
def install
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
recipe.host = toolchain
|
161
|
+
recipe.configure_options << "CFLAGS=#{" -fPIC" if RUBY_PLATFORM =~ /linux|darwin/}"
|
162
|
+
recipe.configure_options << "LDFLAGS=-L#{openssl_recipe.path}/lib -L#{openssl_recipe.path}/lib64 -L#{openssl_recipe.path}/lib-arm64 #{"-Wl,-soname,#{libpq_rubypg} -lgssapi_krb5 -lkrb5 -lk5crypto -lkrb5support -ldl" if RUBY_PLATFORM =~ /linux/} #{"-Wl,-install_name,@loader_path/../../ports/#{gem_platform}/lib/#{libpq_rubypg} -lgssapi_krb5 -lkrb5 -lk5crypto -lkrb5support -lresolv -framework Kerberos" if RUBY_PLATFORM =~ /darwin/}"
|
163
|
+
recipe.configure_options << "LIBS=-lkrb5 -lcom_err -lk5crypto -lkrb5support -lresolv" if RUBY_PLATFORM =~ /linux/
|
164
|
+
recipe.configure_options << "LIBS=-lssl -lwsock32 -lgdi32 -lws2_32 -lcrypt32" if RUBY_PLATFORM =~ /mingw|mswin/
|
165
|
+
recipe.configure_options << "CPPFLAGS=-I#{openssl_recipe.path}/include"
|
166
|
+
recipe.cook_and_activate
|
167
|
+
end
|
168
|
+
|
169
|
+
# Use our own library name for libpq to avoid loading of system libpq by accident.
|
170
|
+
FileUtils.ln_sf File.join(postgresql_recipe.port_path, "lib/#{libpq_orig}"),
|
171
|
+
File.join(postgresql_recipe.port_path, "lib/#{libpq_rubypg}")
|
28
172
|
# Avoid dependency to external libgcc.dll on x86-mingw32
|
29
|
-
$LDFLAGS << " -static-libgcc"
|
173
|
+
$LDFLAGS << " -static-libgcc" if RUBY_PLATFORM =~ /mingw|mswin/
|
174
|
+
# Avoid: "libpq.so: undefined reference to `dlopen'" in cross-ruby-2.7.8
|
175
|
+
$LDFLAGS << " -Wl,--no-as-needed" if RUBY_PLATFORM !~ /aarch64|arm64|darwin/
|
176
|
+
# Find libpq in the ports directory coming from lib/3.x
|
177
|
+
# It is shared between all compiled ruby versions.
|
178
|
+
$LDFLAGS << " '-Wl,-rpath=$$ORIGIN/../../ports/#{gem_platform}/lib'" if RUBY_PLATFORM =~ /linux/
|
30
179
|
# Don't use pg_config for cross build, but --with-pg-* path options
|
31
|
-
dir_config
|
180
|
+
dir_config('pg', "#{postgresql_recipe.path}/include", "#{postgresql_recipe.path}/lib")
|
32
181
|
|
182
|
+
$defs.push( "-DPG_IS_BINARY_GEM")
|
33
183
|
else
|
34
184
|
# Native build
|
35
185
|
|
@@ -79,7 +229,7 @@ $INSTALLFILES = {
|
|
79
229
|
"./postgresql_lib_path.rb" => "$(RUBYLIBDIR)/pg/"
|
80
230
|
}
|
81
231
|
|
82
|
-
if
|
232
|
+
if /solaris/ =~ RUBY_PLATFORM
|
83
233
|
append_cppflags( '-D__EXTENSIONS__' )
|
84
234
|
end
|
85
235
|
|
@@ -144,26 +294,20 @@ if /mingw/ =~ RUBY_PLATFORM && RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc/
|
|
144
294
|
end
|
145
295
|
end
|
146
296
|
|
147
|
-
have_func '
|
297
|
+
have_func 'PQencryptPasswordConn', 'libpq-fe.h' or # since PostgreSQL-10
|
148
298
|
abort "Your PostgreSQL is too old. Either install an older version " +
|
149
|
-
"of this gem or upgrade your database to at least PostgreSQL-
|
299
|
+
"of this gem or upgrade your database to at least PostgreSQL-10."
|
150
300
|
# optional headers/functions
|
151
|
-
have_func 'PQsslAttribute', 'libpq-fe.h' # since PostgreSQL-9.5
|
152
|
-
have_func 'PQresultVerboseErrorMessage', 'libpq-fe.h' # since PostgreSQL-9.6
|
153
|
-
have_func 'PQencryptPasswordConn', 'libpq-fe.h' # since PostgreSQL-10
|
154
301
|
have_func 'PQresultMemorySize', 'libpq-fe.h' # since PostgreSQL-12
|
155
302
|
have_func 'PQenterPipelineMode', 'libpq-fe.h' do |src| # since PostgreSQL-14
|
156
303
|
# Ensure header files fit as well
|
157
304
|
src + " int con(){ return PGRES_PIPELINE_SYNC; }"
|
158
305
|
end
|
306
|
+
have_func 'PQsetChunkedRowsMode', 'libpq-fe.h' # since PostgreSQL-17
|
159
307
|
have_func 'timegm'
|
160
|
-
have_func 'rb_gc_adjust_memory_usage' # since ruby-2.4
|
161
|
-
have_func 'rb_gc_mark_movable' # since ruby-2.7
|
162
308
|
have_func 'rb_io_wait' # since ruby-3.0
|
163
309
|
have_func 'rb_io_descriptor' # since ruby-3.1
|
164
310
|
|
165
|
-
# unistd.h confilicts with ruby/win32.h when cross compiling for win32 and ruby 1.9.1
|
166
|
-
have_header 'unistd.h'
|
167
311
|
have_header 'inttypes.h'
|
168
312
|
have_header('ruby/fiber/scheduler.h') if RUBY_PLATFORM=~/mingw|mswin/
|
169
313
|
|
data/ext/gvl_wrappers.c
CHANGED
@@ -5,8 +5,19 @@
|
|
5
5
|
|
6
6
|
#include "pg.h"
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
|
9
|
+
#ifndef HAVE_PQSETCHUNKEDROWSMODE
|
10
|
+
PGresult *PQclosePrepared(PGconn *conn, const char *stmtName){return NULL;}
|
11
|
+
PGresult *PQclosePortal(PGconn *conn, const char *portalName){return NULL;}
|
12
|
+
int PQsendClosePrepared(PGconn *conn, const char *stmtName){return 0;}
|
13
|
+
int PQsendClosePortal(PGconn *conn, const char *portalName){return 0;}
|
14
|
+
int PQsendPipelineSync(PGconn *conn){return 0;}
|
15
|
+
int PQcancelBlocking(PGcancelConn *cancelConn){return 0;}
|
16
|
+
int PQcancelStart(PGcancelConn *cancelConn){return 0;}
|
17
|
+
PostgresPollingStatusType PQcancelPoll(PGcancelConn *cancelConn){return PGRES_POLLING_FAILED;}
|
18
|
+
#endif
|
19
|
+
#ifndef HAVE_PQENTERPIPELINEMODE
|
20
|
+
int PQpipelineSync(PGconn *conn){return 0;}
|
10
21
|
#endif
|
11
22
|
|
12
23
|
#ifdef ENABLE_GVL_UNLOCK
|