cipherstash-pg 1.0.0.beta.4-x86_64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.appveyor.yml +42 -0
- data/.gems +6 -0
- data/.gemtest +0 -0
- data/.github/workflows/binary-gems.yml +117 -0
- data/.github/workflows/source-gem.yml +137 -0
- data/.gitignore +19 -0
- data/.hgsigs +34 -0
- data/.hgtags +41 -0
- data/.irbrc +23 -0
- data/.pryrc +23 -0
- data/.tm_properties +21 -0
- data/.travis.yml +49 -0
- data/BSDL +22 -0
- data/Contributors.rdoc +46 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +45 -0
- data/History.md +804 -0
- data/LICENSE +56 -0
- data/Manifest.txt +72 -0
- data/POSTGRES +23 -0
- data/README-OS_X.rdoc +68 -0
- data/README-Windows.rdoc +56 -0
- data/README.ja.md +266 -0
- data/README.md +272 -0
- data/Rakefile +76 -0
- data/Rakefile.cross +298 -0
- data/certs/ged.pem +24 -0
- data/certs/larskanis-2022.pem +26 -0
- data/certs/larskanis-2023.pem +24 -0
- data/cipherstash-pg.gemspec +0 -0
- data/lib/2.7/pg_ext.bundle +0 -0
- data/lib/3.0/pg_ext.bundle +0 -0
- data/lib/3.1/pg_ext.bundle +0 -0
- data/lib/3.2/pg_ext.bundle +0 -0
- data/lib/cipherstash-pg/basic_type_map_based_on_result.rb +11 -0
- data/lib/cipherstash-pg/basic_type_map_for_queries.rb +113 -0
- data/lib/cipherstash-pg/basic_type_map_for_results.rb +30 -0
- data/lib/cipherstash-pg/basic_type_registry.rb +206 -0
- data/lib/cipherstash-pg/binary_decoder.rb +21 -0
- data/lib/cipherstash-pg/coder.rb +82 -0
- data/lib/cipherstash-pg/connection.rb +467 -0
- data/lib/cipherstash-pg/constants.rb +3 -0
- data/lib/cipherstash-pg/exceptions.rb +19 -0
- data/lib/cipherstash-pg/result.rb +22 -0
- data/lib/cipherstash-pg/text_decoder.rb +43 -0
- data/lib/cipherstash-pg/text_encoder.rb +67 -0
- data/lib/cipherstash-pg/tuple.rb +24 -0
- data/lib/cipherstash-pg/type_map_by_column.rb +11 -0
- data/lib/cipherstash-pg/version.rb +3 -0
- data/lib/cipherstash-pg.rb +60 -0
- data/lib/libpq.5.dylib +0 -0
- data/misc/openssl-pg-segfault.rb +21 -0
- data/misc/postgres/History.txt +9 -0
- data/misc/postgres/Manifest.txt +5 -0
- data/misc/postgres/README.txt +21 -0
- data/misc/postgres/Rakefile +14 -0
- data/misc/postgres/lib/postgres.rb +12 -0
- data/misc/ruby-pg/History.txt +9 -0
- data/misc/ruby-pg/Manifest.txt +5 -0
- data/misc/ruby-pg/README.txt +21 -0
- data/misc/ruby-pg/Rakefile +14 -0
- data/misc/ruby-pg/lib/ruby/pg.rb +12 -0
- data/rakelib/task_extension.rb +32 -0
- data/sample/array_insert.rb +7 -0
- data/sample/async_api.rb +60 -0
- data/sample/async_copyto.rb +24 -0
- data/sample/async_mixed.rb +28 -0
- data/sample/check_conn.rb +9 -0
- data/sample/copydata.rb +21 -0
- data/sample/copyfrom.rb +29 -0
- data/sample/copyto.rb +13 -0
- data/sample/cursor.rb +11 -0
- data/sample/disk_usage_report.rb +92 -0
- data/sample/issue-119.rb +46 -0
- data/sample/losample.rb +51 -0
- data/sample/minimal-testcase.rb +6 -0
- data/sample/notify_wait.rb +26 -0
- data/sample/pg_statistics.rb +104 -0
- data/sample/replication_monitor.rb +123 -0
- data/sample/test_binary_values.rb +17 -0
- data/sample/wal_shipper.rb +202 -0
- data/sample/warehouse_partitions.rb +161 -0
- data/translation/.po4a-version +7 -0
- data/translation/po/all.pot +875 -0
- data/translation/po/ja.po +868 -0
- data/translation/po4a.cfg +9 -0
- data/vendor/database-extensions/install.sql +317 -0
- data/vendor/database-extensions/uninstall.sql +20 -0
- metadata +140 -0
data/README.md
ADDED
@@ -0,0 +1,272 @@
|
|
1
|
+
# pg
|
2
|
+
|
3
|
+
* home :: https://github.com/ged/ruby-pg
|
4
|
+
* docs :: http://deveiate.org/code/pg
|
5
|
+
* clog :: link:/History.md
|
6
|
+
|
7
|
+
[![Join the chat at https://gitter.im/ged/ruby-pg](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ged/ruby-pg?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
8
|
+
|
9
|
+
|
10
|
+
## Description
|
11
|
+
|
12
|
+
Pg is the Ruby interface to the [PostgreSQL RDBMS](http://www.postgresql.org/).
|
13
|
+
It works with [PostgreSQL 9.3 and later](http://www.postgresql.org/support/versioning/).
|
14
|
+
|
15
|
+
A small example usage:
|
16
|
+
```ruby
|
17
|
+
#!/usr/bin/env ruby
|
18
|
+
|
19
|
+
require 'pg'
|
20
|
+
|
21
|
+
# Output a table of current connections to the DB
|
22
|
+
conn = PG.connect( dbname: 'sales' )
|
23
|
+
conn.exec( "SELECT * FROM pg_stat_activity" ) do |result|
|
24
|
+
puts " PID | User | Query"
|
25
|
+
result.each do |row|
|
26
|
+
puts " %7d | %-16s | %s " %
|
27
|
+
row.values_at('pid', 'usename', 'query')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
## Build Status
|
33
|
+
|
34
|
+
[![Build Status Github Actions](https://github.com/ged/ruby-pg/actions/workflows/source-gem.yml/badge.svg?branch=master)](https://github.com/ged/ruby-pg/actions/workflows/source-gem.yml)
|
35
|
+
[![Binary gems](https://github.com/ged/ruby-pg/actions/workflows/binary-gems.yml/badge.svg?branch=master)](https://github.com/ged/ruby-pg/actions/workflows/binary-gems.yml)
|
36
|
+
[![Build Status Appveyor](https://ci.appveyor.com/api/projects/status/gjx5axouf3b1wicp?svg=true)](https://ci.appveyor.com/project/ged/ruby-pg-9j8l3)
|
37
|
+
|
38
|
+
|
39
|
+
## Requirements
|
40
|
+
|
41
|
+
* Ruby 2.4 or newer
|
42
|
+
* PostgreSQL 9.3.x or later (with headers, -dev packages, etc).
|
43
|
+
|
44
|
+
It usually works with earlier versions of Ruby/PostgreSQL as well, but those are
|
45
|
+
not regularly tested.
|
46
|
+
|
47
|
+
|
48
|
+
## Versioning
|
49
|
+
|
50
|
+
We tag and release gems according to the [Semantic Versioning](http://semver.org/) principle.
|
51
|
+
|
52
|
+
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.
|
53
|
+
|
54
|
+
For example:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
spec.add_dependency 'pg', '~> 1.0'
|
58
|
+
```
|
59
|
+
|
60
|
+
## How To Install
|
61
|
+
|
62
|
+
Install via RubyGems:
|
63
|
+
|
64
|
+
gem install pg
|
65
|
+
|
66
|
+
You may need to specify the path to the 'pg_config' program installed with
|
67
|
+
Postgres:
|
68
|
+
|
69
|
+
gem install pg -- --with-pg-config=<path to pg_config>
|
70
|
+
|
71
|
+
If you're installing via Bundler, you can provide compile hints like so:
|
72
|
+
|
73
|
+
bundle config build.pg --with-pg-config=<path to pg_config>
|
74
|
+
|
75
|
+
See README-OS_X.rdoc for more information about installing under MacOS X, and
|
76
|
+
README-Windows.rdoc for Windows build/installation instructions.
|
77
|
+
|
78
|
+
There's also [a Google+ group](http://goo.gl/TFy1U) and a
|
79
|
+
[mailing list](http://groups.google.com/group/ruby-pg) if you get stuck, or just
|
80
|
+
want to chat about something.
|
81
|
+
|
82
|
+
If you want to install as a signed gem, the public certs of the gem signers
|
83
|
+
can be found in [the `certs` directory](https://github.com/ged/ruby-pg/tree/master/certs)
|
84
|
+
of the repository.
|
85
|
+
|
86
|
+
|
87
|
+
## Type Casts
|
88
|
+
|
89
|
+
Pg can optionally type cast result values and query parameters in Ruby or
|
90
|
+
native C code. This can speed up data transfers to and from the database,
|
91
|
+
because String allocations are reduced and conversions in (slower) Ruby code
|
92
|
+
can be omitted.
|
93
|
+
|
94
|
+
Very basic type casting can be enabled by:
|
95
|
+
```ruby
|
96
|
+
conn.type_map_for_results = PG::BasicTypeMapForResults.new conn
|
97
|
+
# ... this works for result value mapping:
|
98
|
+
conn.exec("select 1, now(), '{2,3}'::int[]").values
|
99
|
+
# => [[1, 2014-09-21 20:51:56 +0200, [2, 3]]]
|
100
|
+
|
101
|
+
conn.type_map_for_queries = PG::BasicTypeMapForQueries.new conn
|
102
|
+
# ... and this for param value mapping:
|
103
|
+
conn.exec_params("SELECT $1::text, $2::text, $3::text", [1, 1.23, [2,3]]).values
|
104
|
+
# => [["1", "1.2300000000000000E+00", "{2,3}"]]
|
105
|
+
```
|
106
|
+
|
107
|
+
But Pg's type casting is highly customizable. That's why it's divided into
|
108
|
+
2 layers:
|
109
|
+
|
110
|
+
### Encoders / Decoders (ext/pg_*coder.c, lib/pg/*coder.rb)
|
111
|
+
|
112
|
+
This is the lower layer, containing encoding classes that convert Ruby
|
113
|
+
objects for transmission to the DBMS and decoding classes to convert
|
114
|
+
received data back to Ruby objects. The classes are namespaced according
|
115
|
+
to their format and direction in PG::TextEncoder, PG::TextDecoder,
|
116
|
+
PG::BinaryEncoder and PG::BinaryDecoder.
|
117
|
+
|
118
|
+
It is possible to assign a type OID, format code (text or binary) and
|
119
|
+
optionally a name to an encoder or decoder object. It's also possible
|
120
|
+
to build composite types by assigning an element encoder/decoder.
|
121
|
+
PG::Coder objects can be used to set up a PG::TypeMap or alternatively
|
122
|
+
to convert single values to/from their string representation.
|
123
|
+
|
124
|
+
The following PostgreSQL column types are supported by ruby-pg (TE = Text Encoder, TD = Text Decoder, BE = Binary Encoder, BD = Binary Decoder):
|
125
|
+
|
126
|
+
* Integer: [TE](rdoc-ref:PG::TextEncoder::Integer), [TD](rdoc-ref:PG::TextDecoder::Integer), [BD](rdoc-ref:PG::BinaryDecoder::Integer) 💡 No links? Switch to [here](https://deveiate.org/code/pg/README_md.html#label-Type+Casts) 💡
|
127
|
+
* BE: [Int2](rdoc-ref:PG::BinaryEncoder::Int2), [Int4](rdoc-ref:PG::BinaryEncoder::Int4), [Int8](rdoc-ref:PG::BinaryEncoder::Int8)
|
128
|
+
* Float: [TE](rdoc-ref:PG::TextEncoder::Float), [TD](rdoc-ref:PG::TextDecoder::Float), [BD](rdoc-ref:PG::BinaryDecoder::Float)
|
129
|
+
* Numeric: [TE](rdoc-ref:PG::TextEncoder::Numeric), [TD](rdoc-ref:PG::TextDecoder::Numeric)
|
130
|
+
* Boolean: [TE](rdoc-ref:PG::TextEncoder::Boolean), [TD](rdoc-ref:PG::TextDecoder::Boolean), [BE](rdoc-ref:PG::BinaryEncoder::Boolean), [BD](rdoc-ref:PG::BinaryDecoder::Boolean)
|
131
|
+
* String: [TE](rdoc-ref:PG::TextEncoder::String), [TD](rdoc-ref:PG::TextDecoder::String), [BE](rdoc-ref:PG::BinaryEncoder::String), [BD](rdoc-ref:PG::BinaryDecoder::String)
|
132
|
+
* Bytea: [TE](rdoc-ref:PG::TextEncoder::Bytea), [TD](rdoc-ref:PG::TextDecoder::Bytea), [BE](rdoc-ref:PG::BinaryEncoder::Bytea), [BD](rdoc-ref:PG::BinaryDecoder::Bytea)
|
133
|
+
* Base64: [TE](rdoc-ref:PG::TextEncoder::ToBase64), [TD](rdoc-ref:PG::TextDecoder::FromBase64), [BE](rdoc-ref:PG::BinaryEncoder::FromBase64), [BD](rdoc-ref:PG::BinaryDecoder::ToBase64)
|
134
|
+
* Timestamp:
|
135
|
+
* TE: [local](rdoc-ref:PG::TextEncoder::TimestampWithoutTimeZone), [UTC](rdoc-ref:PG::TextEncoder::TimestampUtc), [with-TZ](rdoc-ref:PG::TextEncoder::TimestampWithTimeZone)
|
136
|
+
* TD: [local](rdoc-ref:PG::TextDecoder::TimestampLocal), [UTC](rdoc-ref:PG::TextDecoder::TimestampUtc), [UTC-to-local](rdoc-ref:PG::TextDecoder::TimestampUtcToLocal)
|
137
|
+
* BD: [local](rdoc-ref:PG::BinaryDecoder::TimestampLocal), [UTC](rdoc-ref:PG::BinaryDecoder::TimestampUtc), [UTC-to-local](rdoc-ref:PG::BinaryDecoder::TimestampUtcToLocal)
|
138
|
+
* Date: [TE](rdoc-ref:PG::TextEncoder::Date), [TD](rdoc-ref:PG::TextDecoder::Date)
|
139
|
+
* JSON and JSONB: [TE](rdoc-ref:PG::TextEncoder::JSON), [TD](rdoc-ref:PG::TextDecoder::JSON)
|
140
|
+
* Inet: [TE](rdoc-ref:PG::TextEncoder::Inet), [TD](rdoc-ref:PG::TextDecoder::Inet)
|
141
|
+
* Array: [TE](rdoc-ref:PG::TextEncoder::Array), [TD](rdoc-ref:PG::TextDecoder::Array)
|
142
|
+
* Composite Type (also called "Row" or "Record"): [TE](rdoc-ref:PG::TextEncoder::Record), [TD](rdoc-ref:PG::TextDecoder::Record)
|
143
|
+
|
144
|
+
The following text formats can also be encoded although they are not used as column type:
|
145
|
+
|
146
|
+
* COPY input and output data: [TE](rdoc-ref:PG::TextEncoder::CopyRow), [TD](rdoc-ref:PG::TextDecoder::CopyRow)
|
147
|
+
* Literal for insertion into SQL string: [TE](rdoc-ref:PG::TextEncoder::QuotedLiteral)
|
148
|
+
* SQL-Identifier: [TE](rdoc-ref:PG::TextEncoder::Identifier), [TD](rdoc-ref:PG::TextDecoder::Identifier)
|
149
|
+
|
150
|
+
### PG::TypeMap and derivations (ext/pg_type_map*.c, lib/pg/type_map*.rb)
|
151
|
+
|
152
|
+
A TypeMap defines which value will be converted by which encoder/decoder.
|
153
|
+
There are different type map strategies, implemented by several derivations
|
154
|
+
of this class. They can be chosen and configured according to the particular
|
155
|
+
needs for type casting. The default type map is PG::TypeMapAllStrings.
|
156
|
+
|
157
|
+
A type map can be assigned per connection or per query respectively per
|
158
|
+
result set. Type maps can also be used for COPY in and out data streaming.
|
159
|
+
See PG::Connection#copy_data .
|
160
|
+
|
161
|
+
The following base type maps are available:
|
162
|
+
|
163
|
+
* PG::TypeMapAllStrings - encodes and decodes all values to and from strings (default)
|
164
|
+
* PG::TypeMapByClass - selects encoder based on the class of the value to be sent
|
165
|
+
* PG::TypeMapByColumn - selects encoder and decoder by column order
|
166
|
+
* PG::TypeMapByOid - selects decoder by PostgreSQL type OID
|
167
|
+
* PG::TypeMapInRuby - define a custom type map in ruby
|
168
|
+
|
169
|
+
The following type maps are prefilled with type mappings from the PG::BasicTypeRegistry :
|
170
|
+
|
171
|
+
* PG::BasicTypeMapForResults - a PG::TypeMapByOid prefilled with decoders for common PostgreSQL column types
|
172
|
+
* PG::BasicTypeMapBasedOnResult - a PG::TypeMapByOid prefilled with encoders for common PostgreSQL column types
|
173
|
+
* PG::BasicTypeMapForQueries - a PG::TypeMapByClass prefilled with encoders for common Ruby value classes
|
174
|
+
|
175
|
+
|
176
|
+
## Thread support
|
177
|
+
|
178
|
+
PG is thread safe in such a way that different threads can use different PG::Connection objects concurrently.
|
179
|
+
However it is not safe to access any Pg objects simultaneously from more than one thread.
|
180
|
+
So make sure to open a new database server connection for every new thread or use a wrapper library like ActiveRecord that manages connections in a thread safe way.
|
181
|
+
|
182
|
+
If messages like the following are printed to stderr, you're probably using one connection from several threads:
|
183
|
+
|
184
|
+
message type 0x31 arrived from server while idle
|
185
|
+
message type 0x32 arrived from server while idle
|
186
|
+
message type 0x54 arrived from server while idle
|
187
|
+
message type 0x43 arrived from server while idle
|
188
|
+
message type 0x5a arrived from server while idle
|
189
|
+
|
190
|
+
|
191
|
+
## Fiber IO scheduler support
|
192
|
+
|
193
|
+
Pg is fully compatible with `Fiber.scheduler` introduced in Ruby-3.0.
|
194
|
+
On Windows support for `Fiber.scheduler` is available on Ruby-3.1 or newer.
|
195
|
+
All possibly blocking IO operations are routed through the `Fiber.scheduler` if one is registered for the running thread.
|
196
|
+
That is why pg internally uses the asynchronous libpq interface even for synchronous/blocking method calls.
|
197
|
+
It also uses Ruby's DNS resolution instead of libpq's builtin functions.
|
198
|
+
|
199
|
+
Internally Pg always uses the nonblocking connection mode of libpq.
|
200
|
+
It then behaves like running in blocking mode but ensures, that all blocking IO is handled in Ruby through a possibly registered `Fiber.scheduler`.
|
201
|
+
When `PG::Connection.setnonblocking(true)` is called then the nonblocking state stays enabled, but the additional handling of blocking states is disabled, so that the calling program has to handle blocking states on its own.
|
202
|
+
|
203
|
+
An exception to this rule are the methods for large objects like `PG::Connection#lo_create` and authentication methods using external libraries (like GSSAPI authentication).
|
204
|
+
They are not compatible with `Fiber.scheduler`, so that blocking states are not passed to the registered IO scheduler.
|
205
|
+
That means the operation will work properly, but IO waiting states can not be used to switch to another Fiber doing IO.
|
206
|
+
|
207
|
+
|
208
|
+
## Contributing
|
209
|
+
|
210
|
+
To report bugs, suggest features, or check out the source with Git,
|
211
|
+
[check out the project page](https://github.com/ged/ruby-pg).
|
212
|
+
|
213
|
+
After checking out the source, install all dependencies:
|
214
|
+
|
215
|
+
$ bundle install
|
216
|
+
|
217
|
+
Cleanup extension files, packaging files, test databases:
|
218
|
+
|
219
|
+
$ rake clean
|
220
|
+
|
221
|
+
Compile extension:
|
222
|
+
|
223
|
+
$ rake compile
|
224
|
+
|
225
|
+
Run tests/specs with PostgreSQL tools like `initdb` in the path:
|
226
|
+
|
227
|
+
$ PATH=$PATH:/usr/lib/postgresql/14/bin rake test
|
228
|
+
|
229
|
+
Or run a specific test with the line number:
|
230
|
+
|
231
|
+
$ PATH=$PATH:/usr/lib/postgresql/14/bin rspec -Ilib -fd spec/pg/connection_spec.rb:455
|
232
|
+
|
233
|
+
Generate the API documentation:
|
234
|
+
|
235
|
+
$ rake docs
|
236
|
+
|
237
|
+
Make sure, that all bugs and new features are verified by tests.
|
238
|
+
|
239
|
+
The current maintainers are Michael Granger <ged@FaerieMUD.org> and
|
240
|
+
Lars Kanis <lars@greiz-reinsdorf.de>.
|
241
|
+
|
242
|
+
|
243
|
+
## Copying
|
244
|
+
|
245
|
+
Copyright (c) 1997-2022 by the authors.
|
246
|
+
|
247
|
+
* Jeff Davis <ruby-pg@j-davis.com>
|
248
|
+
* Guy Decoux (ts) <decoux@moulon.inra.fr>
|
249
|
+
* Michael Granger <ged@FaerieMUD.org>
|
250
|
+
* Lars Kanis <lars@greiz-reinsdorf.de>
|
251
|
+
* Dave Lee
|
252
|
+
* Eiji Matsumoto <usagi@ruby.club.or.jp>
|
253
|
+
* Yukihiro Matsumoto <matz@ruby-lang.org>
|
254
|
+
* Noboru Saitou <noborus@netlab.jp>
|
255
|
+
|
256
|
+
You may redistribute this software under the same terms as Ruby itself; see
|
257
|
+
https://www.ruby-lang.org/en/about/license.txt or the BSDL file in the source
|
258
|
+
for details.
|
259
|
+
|
260
|
+
Portions of the code are from the PostgreSQL project, and are distributed
|
261
|
+
under the terms of the PostgreSQL license, included in the file POSTGRES.
|
262
|
+
|
263
|
+
Portions copyright LAIKA, Inc.
|
264
|
+
|
265
|
+
|
266
|
+
## Acknowledgments
|
267
|
+
|
268
|
+
See Contributors.rdoc for the many additional fine people that have contributed
|
269
|
+
to this library over the years.
|
270
|
+
|
271
|
+
We are thankful to the people at the ruby-list and ruby-dev mailing lists.
|
272
|
+
And to the people who developed PostgreSQL.
|
data/Rakefile
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require("rbconfig")
|
2
|
+
require("pathname")
|
3
|
+
require("tmpdir")
|
4
|
+
require("rake/extensiontask")
|
5
|
+
require("rake/clean")
|
6
|
+
require("rspec/core/rake_task")
|
7
|
+
require("bundler")
|
8
|
+
require("bundler/gem_helper")
|
9
|
+
BASEDIR = Pathname("(string)").dirname
|
10
|
+
SPECDIR = (BASEDIR + "spec")
|
11
|
+
LIBDIR = (BASEDIR + "lib")
|
12
|
+
EXTDIR = (BASEDIR + "ext")
|
13
|
+
PKGDIR = (BASEDIR + "pkg")
|
14
|
+
TMPDIR = (BASEDIR + "tmp")
|
15
|
+
TESTDIR = (BASEDIR + "tmp_test_*")
|
16
|
+
DLEXT = RbConfig::CONFIG["DLEXT"]
|
17
|
+
EXT = (LIBDIR + "pg_ext.#{DLEXT}")
|
18
|
+
GEMSPEC = "cipherstash-pg.gemspec"
|
19
|
+
CLEAN.include(TESTDIR.to_s)
|
20
|
+
CLEAN.include(PKGDIR.to_s, TMPDIR.to_s)
|
21
|
+
CLEAN.include("lib/*/libpq.dll")
|
22
|
+
CLEAN.include("lib/pg_ext.*")
|
23
|
+
CLEAN.include("lib/pg/postgresql_lib_path.rb")
|
24
|
+
load("Rakefile.cross")
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
$gem_spec = Bundler.load_gemspec(GEMSPEC)
|
27
|
+
desc("Turn on warnings and debugging in the build.")
|
28
|
+
task(:maint) { ENV["MAINTAINER_MODE"] = "yes" }
|
29
|
+
Rake::ExtensionTask.new do |ext|
|
30
|
+
ext.name = "pg_ext"
|
31
|
+
ext.gem_spec = $gem_spec
|
32
|
+
ext.ext_dir = "ext"
|
33
|
+
ext.lib_dir = "lib"
|
34
|
+
ext.source_pattern = "*.{c,h}"
|
35
|
+
ext.cross_compile = true
|
36
|
+
ext.cross_platform = CrossLibraries.map(&:for_platform)
|
37
|
+
ext.cross_config_options += CrossLibraries.map do |lib|
|
38
|
+
{ lib.for_platform => (["--enable-windows-cross", "--with-pg-include=#{lib.static_postgresql_incdir}", "--with-pg-lib=#{lib.static_postgresql_libdir}", "--with-opt-include=#{lib.static_postgresql_libdir}"]) }
|
39
|
+
end
|
40
|
+
ext.cross_compiling do |spec|
|
41
|
+
(spec.files << "lib/#{spec.platform}/libpq.dll")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
RSpec::Core::RakeTask.new(:spec).rspec_opts = "--profile -cfdoc"
|
45
|
+
task(:test => :spec)
|
46
|
+
require("rdoc/task")
|
47
|
+
RDoc::Task.new("docs") do |rdoc|
|
48
|
+
rdoc.options = $gem_spec.rdoc_options
|
49
|
+
rdoc.rdoc_files = $gem_spec.extra_rdoc_files
|
50
|
+
rdoc.generator = :fivefish
|
51
|
+
rdoc.rdoc_dir = "doc"
|
52
|
+
end
|
53
|
+
desc("Build the source gem #{$gem_spec.full_name}.gem into the pkg directory")
|
54
|
+
task(:gem => :build)
|
55
|
+
task(:clobber) do
|
56
|
+
puts("Stop any Postmaster instances that remain after testing.")
|
57
|
+
require_relative("spec/helpers")
|
58
|
+
CipherStashPG::TestingHelpers.stop_existing_postmasters
|
59
|
+
end
|
60
|
+
desc("Update list of server error codes")
|
61
|
+
task(:update_error_codes) do
|
62
|
+
URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=refs/tags/REL_15_0"
|
63
|
+
ERRORCODES_TXT = "ext/errorcodes.txt"
|
64
|
+
sh("wget #{URL_ERRORCODES_TXT.inspect} -O #{ERRORCODES_TXT.inspect} || curl #{URL_ERRORCODES_TXT.inspect} -o #{ERRORCODES_TXT.inspect}")
|
65
|
+
ruby("ext/errorcodes.rb", "ext/errorcodes.txt", "ext/errorcodes.def")
|
66
|
+
end
|
67
|
+
file("ext/pg_errors.c" => (["ext/errorcodes.def"])) do
|
68
|
+
touch("ext/pg_errors.c")
|
69
|
+
end
|
70
|
+
desc("Translate readme")
|
71
|
+
task(:translate) do
|
72
|
+
cd("translation") do
|
73
|
+
sh("LANG=C po4a --version > .po4a-version")
|
74
|
+
sh("po4a po4a.cfg")
|
75
|
+
end
|
76
|
+
end
|
data/Rakefile.cross
ADDED
@@ -0,0 +1,298 @@
|
|
1
|
+
# -*- rake -*-
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'rbconfig'
|
6
|
+
require 'rake/clean'
|
7
|
+
require 'rake/extensiontask'
|
8
|
+
require 'rake/extensioncompiler'
|
9
|
+
require 'ostruct'
|
10
|
+
require_relative 'rakelib/task_extension'
|
11
|
+
|
12
|
+
MISCDIR = BASEDIR + 'misc'
|
13
|
+
|
14
|
+
NUM_CPUS = if File.exist?('/proc/cpuinfo')
|
15
|
+
File.read('/proc/cpuinfo').scan('processor').length
|
16
|
+
elsif RUBY_PLATFORM.include?( 'darwin' )
|
17
|
+
`system_profiler SPHardwareDataType | grep 'Cores' | awk '{print $5}'`.chomp
|
18
|
+
else
|
19
|
+
1
|
20
|
+
end
|
21
|
+
|
22
|
+
class CrossLibrary < OpenStruct
|
23
|
+
include Rake::DSL
|
24
|
+
prepend TaskExtension
|
25
|
+
|
26
|
+
def initialize(for_platform, openssl_config, toolchain)
|
27
|
+
super()
|
28
|
+
|
29
|
+
self.for_platform = for_platform
|
30
|
+
self.openssl_config = openssl_config
|
31
|
+
self.host_platform = toolchain
|
32
|
+
|
33
|
+
# Cross-compilation constants
|
34
|
+
self.openssl_version = ENV['OPENSSL_VERSION'] || '3.0.8'
|
35
|
+
self.postgresql_version = ENV['POSTGRESQL_VERSION'] || '15.2'
|
36
|
+
|
37
|
+
# Check if symlinks work in the current working directory.
|
38
|
+
# This fails, if rake-compiler-dock is running on a Windows box.
|
39
|
+
begin
|
40
|
+
FileUtils.rm_f '.test_symlink'
|
41
|
+
FileUtils.ln_s '/', '.test_symlink'
|
42
|
+
rescue NotImplementedError, SystemCallError
|
43
|
+
# Symlinks don't work -> use home directory instead
|
44
|
+
self.compile_home = Pathname( "~/.ruby-pg-build" ).expand_path
|
45
|
+
else
|
46
|
+
self.compile_home = Pathname( "./build" ).expand_path
|
47
|
+
end
|
48
|
+
self.static_sourcesdir = compile_home + 'sources'
|
49
|
+
self.static_builddir = compile_home + 'builds' + for_platform
|
50
|
+
CLOBBER.include( static_sourcesdir )
|
51
|
+
CLEAN.include( static_builddir )
|
52
|
+
|
53
|
+
# Static OpenSSL build vars
|
54
|
+
self.static_openssl_builddir = static_builddir + "openssl-#{openssl_version}"
|
55
|
+
|
56
|
+
self.openssl_source_uri =
|
57
|
+
URI( "http://www.openssl.org/source/openssl-#{openssl_version}.tar.gz" )
|
58
|
+
self.openssl_tarball = static_sourcesdir + File.basename( openssl_source_uri.path )
|
59
|
+
self.openssl_makefile = static_openssl_builddir + 'Makefile'
|
60
|
+
|
61
|
+
self.libssl = static_openssl_builddir + 'libssl.a'
|
62
|
+
self.libcrypto = static_openssl_builddir + 'libcrypto.a'
|
63
|
+
|
64
|
+
self.openssl_patches = Rake::FileList[ (MISCDIR + "openssl-#{openssl_version}.*.patch").to_s ]
|
65
|
+
|
66
|
+
# Static PostgreSQL build vars
|
67
|
+
self.static_postgresql_builddir = static_builddir + "postgresql-#{postgresql_version}"
|
68
|
+
self.postgresql_source_uri = begin
|
69
|
+
uristring = "http://ftp.postgresql.org/pub/source/v%s/postgresql-%s.tar.bz2" %
|
70
|
+
[ postgresql_version, postgresql_version ]
|
71
|
+
URI( uristring )
|
72
|
+
end
|
73
|
+
self.postgresql_tarball = static_sourcesdir + File.basename( postgresql_source_uri.path )
|
74
|
+
|
75
|
+
self.static_postgresql_srcdir = static_postgresql_builddir + 'src'
|
76
|
+
self.static_postgresql_libdir = static_postgresql_srcdir + 'interfaces/libpq'
|
77
|
+
self.static_postgresql_incdir = static_postgresql_srcdir + 'include'
|
78
|
+
|
79
|
+
self.postgresql_global_makefile = static_postgresql_srcdir + 'Makefile.global'
|
80
|
+
self.postgresql_shlib_makefile = static_postgresql_srcdir + 'Makefile.shlib'
|
81
|
+
self.postgresql_shlib_mf_orig = static_postgresql_srcdir + 'Makefile.shlib.orig'
|
82
|
+
self.postgresql_lib = static_postgresql_libdir + 'libpq.dll'
|
83
|
+
self.postgresql_patches = Rake::FileList[ (MISCDIR + "postgresql-#{postgresql_version}.*.patch").to_s ]
|
84
|
+
|
85
|
+
# clean intermediate files and folders
|
86
|
+
CLEAN.include( static_builddir.to_s )
|
87
|
+
|
88
|
+
#####################################################################
|
89
|
+
### C R O S S - C O M P I L A T I O N - T A S K S
|
90
|
+
#####################################################################
|
91
|
+
|
92
|
+
|
93
|
+
directory static_sourcesdir.to_s
|
94
|
+
|
95
|
+
#
|
96
|
+
# Static OpenSSL build tasks
|
97
|
+
#
|
98
|
+
directory static_openssl_builddir.to_s
|
99
|
+
|
100
|
+
# openssl source file should be stored there
|
101
|
+
file openssl_tarball => static_sourcesdir do |t|
|
102
|
+
download( openssl_source_uri, t.name )
|
103
|
+
end
|
104
|
+
|
105
|
+
# Extract the openssl builds
|
106
|
+
file static_openssl_builddir => openssl_tarball do |t|
|
107
|
+
puts "extracting %s to %s" % [ openssl_tarball, static_openssl_builddir.parent ]
|
108
|
+
static_openssl_builddir.mkpath
|
109
|
+
run 'tar', '-xzf', openssl_tarball.to_s, '-C', static_openssl_builddir.parent.to_s
|
110
|
+
openssl_makefile.unlink if openssl_makefile.exist?
|
111
|
+
|
112
|
+
openssl_patches.each do |patchfile|
|
113
|
+
puts " applying patch #{patchfile}..."
|
114
|
+
run 'patch', '-Np1', '-d', static_openssl_builddir.to_s,
|
115
|
+
'-i', File.expand_path( patchfile, BASEDIR )
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
self.cmd_prelude = [
|
120
|
+
"env",
|
121
|
+
"CROSS_COMPILE=#{host_platform}-",
|
122
|
+
"CFLAGS=-DDSO_WIN32",
|
123
|
+
]
|
124
|
+
|
125
|
+
|
126
|
+
# generate the makefile in a clean build location
|
127
|
+
file openssl_makefile => static_openssl_builddir do |t|
|
128
|
+
chdir( static_openssl_builddir ) do
|
129
|
+
cmd = cmd_prelude.dup
|
130
|
+
cmd << "./Configure" << "-static" << openssl_config
|
131
|
+
|
132
|
+
run( *cmd )
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
desc "compile static openssl libraries"
|
137
|
+
task "openssl_libs:#{for_platform}" => [ libssl, libcrypto ]
|
138
|
+
|
139
|
+
task "compile_static_openssl:#{for_platform}" => openssl_makefile do |t|
|
140
|
+
chdir( static_openssl_builddir ) do
|
141
|
+
cmd = cmd_prelude.dup
|
142
|
+
cmd << 'make' << "-j#{NUM_CPUS}" << 'build_libs'
|
143
|
+
|
144
|
+
run( *cmd )
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
desc "compile static #{libssl}"
|
149
|
+
file libssl => "compile_static_openssl:#{for_platform}"
|
150
|
+
|
151
|
+
desc "compile static #{libcrypto}"
|
152
|
+
file libcrypto => "compile_static_openssl:#{for_platform}"
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
#
|
157
|
+
# Static PostgreSQL build tasks
|
158
|
+
#
|
159
|
+
directory static_postgresql_builddir.to_s
|
160
|
+
|
161
|
+
|
162
|
+
# postgresql source file should be stored there
|
163
|
+
file postgresql_tarball => static_sourcesdir do |t|
|
164
|
+
download( postgresql_source_uri, t.name )
|
165
|
+
end
|
166
|
+
|
167
|
+
# Extract the postgresql sources
|
168
|
+
file static_postgresql_builddir => postgresql_tarball do |t|
|
169
|
+
puts "extracting %s to %s" % [ postgresql_tarball, static_postgresql_builddir.parent ]
|
170
|
+
static_postgresql_builddir.mkpath
|
171
|
+
run 'tar', '-xjf', postgresql_tarball.to_s, '-C', static_postgresql_builddir.parent.to_s
|
172
|
+
|
173
|
+
postgresql_patches.each do |patchfile|
|
174
|
+
puts " applying patch #{patchfile}..."
|
175
|
+
run 'patch', '-Np1', '-d', static_postgresql_builddir.to_s,
|
176
|
+
'-i', File.expand_path( patchfile, BASEDIR )
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# generate the makefile in a clean build location
|
181
|
+
file postgresql_global_makefile => [ static_postgresql_builddir, "openssl_libs:#{for_platform}" ] do |t|
|
182
|
+
options = [
|
183
|
+
"--target=#{host_platform}",
|
184
|
+
"--host=#{host_platform}",
|
185
|
+
'--with-openssl',
|
186
|
+
'--without-zlib',
|
187
|
+
]
|
188
|
+
|
189
|
+
chdir( static_postgresql_builddir ) do
|
190
|
+
configure_path = static_postgresql_builddir + 'configure'
|
191
|
+
cmd = [ configure_path.to_s, *options ]
|
192
|
+
cmd << "CFLAGS=-L#{static_openssl_builddir}"
|
193
|
+
cmd << "LDFLAGS=-L#{static_openssl_builddir}"
|
194
|
+
cmd << "LDFLAGS_SL=-L#{static_openssl_builddir}"
|
195
|
+
cmd << "LIBS=-lwsock32 -lgdi32 -lws2_32 -lcrypt32"
|
196
|
+
cmd << "CPPFLAGS=-I#{static_openssl_builddir}/include"
|
197
|
+
|
198
|
+
run( *cmd )
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
|
203
|
+
# make libpq.dll
|
204
|
+
task postgresql_lib => [ postgresql_global_makefile ] do |t|
|
205
|
+
# Work around missing dependency to libcommon in PostgreSQL-9.4.0
|
206
|
+
chdir( static_postgresql_srcdir + "common" ) do
|
207
|
+
sh 'make', "-j#{NUM_CPUS}"
|
208
|
+
end
|
209
|
+
chdir( static_postgresql_srcdir + "port" ) do
|
210
|
+
sh 'make', "-j#{NUM_CPUS}"
|
211
|
+
end
|
212
|
+
|
213
|
+
chdir( postgresql_lib.dirname ) do
|
214
|
+
sh 'make',
|
215
|
+
"-j#{NUM_CPUS}",
|
216
|
+
postgresql_lib.basename.to_s,
|
217
|
+
'SHLIB_LINK=-lssl -lcrypto -lcrypt32 -lgdi32 -lsecur32 -lwsock32 -lws2_32'
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
#desc 'compile libpg.a'
|
223
|
+
task "native:#{for_platform}" => postgresql_lib
|
224
|
+
|
225
|
+
# copy libpq.dll to lib dir
|
226
|
+
dest_libpq = "lib/#{for_platform}/#{postgresql_lib.basename}"
|
227
|
+
directory File.dirname(dest_libpq)
|
228
|
+
file dest_libpq => [postgresql_lib, File.dirname(dest_libpq)] do
|
229
|
+
cp postgresql_lib, dest_libpq
|
230
|
+
end
|
231
|
+
|
232
|
+
stage_libpq = "tmp/#{for_platform}/stage/#{dest_libpq}"
|
233
|
+
directory File.dirname(stage_libpq)
|
234
|
+
file stage_libpq => [postgresql_lib, File.dirname(stage_libpq)] do |t|
|
235
|
+
cp postgresql_lib, stage_libpq
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
def download(url, save_to)
|
240
|
+
part = save_to+".part"
|
241
|
+
sh "wget #{url.to_s.inspect} -O #{part.inspect} || curl #{url.to_s.inspect} -o #{part.inspect}"
|
242
|
+
FileUtils.mv part, save_to
|
243
|
+
end
|
244
|
+
|
245
|
+
def run(*args)
|
246
|
+
sh(*args)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
CrossLibraries = [
|
251
|
+
['x64-mingw-ucrt', 'mingw64', 'x86_64-w64-mingw32'],
|
252
|
+
['x86-mingw32', 'mingw', 'i686-w64-mingw32'],
|
253
|
+
['x64-mingw32', 'mingw64', 'x86_64-w64-mingw32'],
|
254
|
+
].map do |platform, openssl_config, toolchain|
|
255
|
+
CrossLibrary.new platform, openssl_config, toolchain
|
256
|
+
end
|
257
|
+
|
258
|
+
desc 'cross compile pg for win32'
|
259
|
+
task :cross => [ :mingw32 ]
|
260
|
+
|
261
|
+
task :mingw32 do
|
262
|
+
# Use Rake::ExtensionCompiler helpers to find the proper host
|
263
|
+
unless Rake::ExtensionCompiler.mingw_host then
|
264
|
+
warn "You need to install mingw32 cross compile functionality to be able to continue."
|
265
|
+
warn "Please refer to your distribution/package manager documentation about installation."
|
266
|
+
fail
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
task 'gem:windows:prepare' do
|
271
|
+
require 'io/console'
|
272
|
+
require 'rake_compiler_dock'
|
273
|
+
|
274
|
+
# Copy gem signing key and certs to be accessible from the docker container
|
275
|
+
mkdir_p 'build/gem'
|
276
|
+
sh "cp ~/.gem/gem-*.pem build/gem/ || true"
|
277
|
+
sh "bundle package"
|
278
|
+
begin
|
279
|
+
OpenSSL::PKey.read(File.read(File.expand_path("~/.gem/gem-private_key.pem")), ENV["GEM_PRIVATE_KEY_PASSPHRASE"] || "")
|
280
|
+
rescue OpenSSL::PKey::PKeyError
|
281
|
+
ENV["GEM_PRIVATE_KEY_PASSPHRASE"] = STDIN.getpass("Enter passphrase of gem signature key: ")
|
282
|
+
retry
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
CrossLibraries.each do |xlib|
|
287
|
+
platform = xlib.for_platform
|
288
|
+
desc "Build fat binary gem for platform #{platform}"
|
289
|
+
task "gem:windows:#{platform}" => ['gem:windows:prepare', xlib.openssl_tarball, xlib.postgresql_tarball] do
|
290
|
+
RakeCompilerDock.sh <<-EOT, platform: platform
|
291
|
+
(cp build/gem/gem-*.pem ~/.gem/ || true) &&
|
292
|
+
bundle install --local &&
|
293
|
+
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
|
294
|
+
EOT
|
295
|
+
end
|
296
|
+
desc "Build the windows binary gems"
|
297
|
+
multitask 'gem:windows' => "gem:windows:#{platform}"
|
298
|
+
end
|
data/certs/ged.pem
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIID+DCCAmCgAwIBAgIBBDANBgkqhkiG9w0BAQsFADAiMSAwHgYDVQQDDBdnZWQv
|
3
|
+
REM9RmFlcmllTVVEL0RDPW9yZzAeFw0yMjAxMDcyMzU4MTRaFw0yMzAxMDcyMzU4
|
4
|
+
MTRaMCIxIDAeBgNVBAMMF2dlZC9EQz1GYWVyaWVNVUQvREM9b3JnMIIBojANBgkq
|
5
|
+
hkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAvyVhkRzvlEs0fe7145BYLfN6njX9ih5H
|
6
|
+
L60U0p0euIurpv84op9CNKF9tx+1WKwyQvQP7qFGuZxkSUuWcP/sFhDXL1lWUuIl
|
7
|
+
M4uHbGCRmOshDrF4dgnBeOvkHr1fIhPlJm5FO+Vew8tSQmlDsosxLUx+VB7DrVFO
|
8
|
+
5PU2AEbf04GGSrmqADGWXeaslaoRdb1fu/0M5qfPTRn5V39sWD9umuDAF9qqil/x
|
9
|
+
Sl6phTvgBrG8GExHbNZpLARd3xrBYLEFsX7RvBn2UPfgsrtvpdXjsHGfpT3IPN+B
|
10
|
+
vQ66lts4alKC69TE5cuKasWBm+16A4aEe3XdZBRNmtOu/g81gvwA7fkJHKllJuaI
|
11
|
+
dXzdHqq+zbGZVSQ7pRYHYomD0IiDe1DbIouFnPWmagaBnGHwXkDT2bKKP+s2v21m
|
12
|
+
ozilJg4aar2okb/RA6VS87o+d7g6LpDDMMQjH4G9OPnJENLdhu8KnPw/ivSVvQw7
|
13
|
+
N2I4L/ZOIe2DIVuYH7aLHfjZDQv/mNgpAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYD
|
14
|
+
VR0PBAQDAgSwMB0GA1UdDgQWBBRyjf55EbrHagiRLqt5YAd3yb8k4DANBgkqhkiG
|
15
|
+
9w0BAQsFAAOCAYEASrm1AbEoxACZ9WXJH3R5axV3U0CA4xaETlL2YT+2nOfVBMQ9
|
16
|
+
0ZlkPx6j4ghKJgAIi1TMfDM2JyPJsppQh8tiNccDjWc62UZRY/dq26cMqf/lcI+a
|
17
|
+
6YBuEYvzZfearwVs8tHnXtwYV3WSCoCOQaB+nq2lA1O+nkKNl41WOsVbNama5jx3
|
18
|
+
8cQtVSEEmZy6jIDJ8c5TmBJ7BQUDEUEWA/A3V42Xyctoj7DvUXWE0lP+X6ypAVSr
|
19
|
+
lFh3TS64D7NTvxkmg7natUoCvobl6kGl4yMaqE4YRTlfuzhpf91TSOntClqrAOsS
|
20
|
+
K1s56WndQj3IoBocdY9mQhDZLtLHofSkymoP8btBlj5SsN24TiF0VMSZlctSCYZg
|
21
|
+
GKyHim/MMlIfGOWsgfioq5jzwmql7W4CDubbb8Lkg70v+hN2E/MnNVAcNE3gyaGc
|
22
|
+
P5YP5BAbNW+gvd3QHRiWTTuhgHrdDnGdXg93N2M5KHn1ug8BtPLQwlcFwEpKnlLn
|
23
|
+
btEP+7EplFuoiMfd
|
24
|
+
-----END CERTIFICATE-----
|