pg 1.2.3 → 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.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +986 -0
  4. data/Gemfile +23 -0
  5. data/README-Windows.rdoc +1 -1
  6. data/README.ja.md +300 -0
  7. data/README.md +327 -0
  8. data/Rakefile +123 -144
  9. data/certs/ged.pem +24 -0
  10. data/certs/kanis@comcard.de.pem +20 -0
  11. data/certs/larskanis-2022.pem +26 -0
  12. data/certs/larskanis-2023.pem +24 -0
  13. data/certs/larskanis-2024.pem +24 -0
  14. data/ext/errorcodes.def +16 -5
  15. data/ext/errorcodes.rb +0 -0
  16. data/ext/errorcodes.txt +5 -5
  17. data/ext/extconf.rb +259 -33
  18. data/ext/gvl_wrappers.c +17 -2
  19. data/ext/gvl_wrappers.h +56 -0
  20. data/ext/pg.c +89 -63
  21. data/ext/pg.h +31 -8
  22. data/ext/pg_binary_decoder.c +232 -1
  23. data/ext/pg_binary_encoder.c +428 -1
  24. data/ext/pg_cancel_connection.c +360 -0
  25. data/ext/pg_coder.c +148 -36
  26. data/ext/pg_connection.c +1365 -817
  27. data/ext/pg_copy_coder.c +360 -38
  28. data/ext/pg_errors.c +1 -1
  29. data/ext/pg_record_coder.c +56 -25
  30. data/ext/pg_result.c +187 -76
  31. data/ext/pg_text_decoder.c +32 -11
  32. data/ext/pg_text_encoder.c +65 -33
  33. data/ext/pg_tuple.c +84 -61
  34. data/ext/pg_type_map.c +44 -10
  35. data/ext/pg_type_map_all_strings.c +17 -3
  36. data/ext/pg_type_map_by_class.c +54 -27
  37. data/ext/pg_type_map_by_column.c +74 -31
  38. data/ext/pg_type_map_by_mri_type.c +48 -19
  39. data/ext/pg_type_map_by_oid.c +61 -27
  40. data/ext/pg_type_map_in_ruby.c +55 -21
  41. data/ext/pg_util.c +2 -2
  42. data/lib/pg/basic_type_map_based_on_result.rb +67 -0
  43. data/lib/pg/basic_type_map_for_queries.rb +206 -0
  44. data/lib/pg/basic_type_map_for_results.rb +104 -0
  45. data/lib/pg/basic_type_registry.rb +311 -0
  46. data/lib/pg/binary_decoder/date.rb +9 -0
  47. data/lib/pg/binary_decoder/timestamp.rb +26 -0
  48. data/lib/pg/binary_encoder/timestamp.rb +20 -0
  49. data/lib/pg/cancel_connection.rb +53 -0
  50. data/lib/pg/coder.rb +18 -14
  51. data/lib/pg/connection.rb +894 -91
  52. data/lib/pg/exceptions.rb +20 -1
  53. data/lib/pg/text_decoder/date.rb +21 -0
  54. data/lib/pg/text_decoder/inet.rb +9 -0
  55. data/lib/pg/text_decoder/json.rb +17 -0
  56. data/lib/pg/text_decoder/numeric.rb +9 -0
  57. data/lib/pg/text_decoder/timestamp.rb +30 -0
  58. data/lib/pg/text_encoder/date.rb +13 -0
  59. data/lib/pg/text_encoder/inet.rb +31 -0
  60. data/lib/pg/text_encoder/json.rb +17 -0
  61. data/lib/pg/text_encoder/numeric.rb +9 -0
  62. data/lib/pg/text_encoder/timestamp.rb +24 -0
  63. data/lib/pg/version.rb +4 -0
  64. data/lib/pg.rb +109 -39
  65. data/misc/openssl-pg-segfault.rb +31 -0
  66. data/misc/postgres/History.txt +9 -0
  67. data/misc/postgres/Manifest.txt +5 -0
  68. data/misc/postgres/README.txt +21 -0
  69. data/misc/postgres/Rakefile +21 -0
  70. data/misc/postgres/lib/postgres.rb +16 -0
  71. data/misc/ruby-pg/History.txt +9 -0
  72. data/misc/ruby-pg/Manifest.txt +5 -0
  73. data/misc/ruby-pg/README.txt +21 -0
  74. data/misc/ruby-pg/Rakefile +21 -0
  75. data/misc/ruby-pg/lib/ruby/pg.rb +16 -0
  76. data/misc/yugabyte/Dockerfile +9 -0
  77. data/misc/yugabyte/docker-compose.yml +28 -0
  78. data/misc/yugabyte/pg-test.rb +45 -0
  79. data/pg.gemspec +38 -0
  80. data/ports/patches/krb5/1.21.3/0001-Allow-static-linking-krb5-library.patch +30 -0
  81. data/ports/patches/openssl/3.5.1/0001-aarch64-mingw.patch +21 -0
  82. data/ports/patches/postgresql/17.5/0001-Use-workaround-of-__builtin_setjmp-only-on-MINGW-on-.patch +42 -0
  83. data/ports/patches/postgresql/17.5/0001-libpq-Process-buffered-SSL-read-bytes-to-support-rec.patch +52 -0
  84. data/rakelib/pg_gem_helper.rb +64 -0
  85. data/rakelib/task_extension.rb +46 -0
  86. data/sample/array_insert.rb +20 -0
  87. data/sample/async_api.rb +102 -0
  88. data/sample/async_copyto.rb +39 -0
  89. data/sample/async_mixed.rb +56 -0
  90. data/sample/check_conn.rb +21 -0
  91. data/sample/copydata.rb +71 -0
  92. data/sample/copyfrom.rb +81 -0
  93. data/sample/copyto.rb +19 -0
  94. data/sample/cursor.rb +21 -0
  95. data/sample/disk_usage_report.rb +177 -0
  96. data/sample/issue-119.rb +94 -0
  97. data/sample/losample.rb +69 -0
  98. data/sample/minimal-testcase.rb +17 -0
  99. data/sample/notify_wait.rb +72 -0
  100. data/sample/pg_statistics.rb +285 -0
  101. data/sample/replication_monitor.rb +222 -0
  102. data/sample/test_binary_values.rb +33 -0
  103. data/sample/wal_shipper.rb +434 -0
  104. data/sample/warehouse_partitions.rb +311 -0
  105. data.tar.gz.sig +0 -0
  106. metadata +139 -213
  107. metadata.gz.sig +0 -0
  108. data/.gemtest +0 -0
  109. data/ChangeLog +0 -0
  110. data/History.rdoc +0 -578
  111. data/Manifest.txt +0 -73
  112. data/README.ja.rdoc +0 -13
  113. data/README.rdoc +0 -213
  114. data/Rakefile.cross +0 -299
  115. data/lib/pg/basic_type_mapping.rb +0 -522
  116. data/lib/pg/binary_decoder.rb +0 -23
  117. data/lib/pg/constants.rb +0 -12
  118. data/lib/pg/text_decoder.rb +0 -46
  119. data/lib/pg/text_encoder.rb +0 -59
  120. data/spec/data/expected_trace.out +0 -26
  121. data/spec/data/random_binary_data +0 -0
  122. data/spec/helpers.rb +0 -380
  123. data/spec/pg/basic_type_mapping_spec.rb +0 -630
  124. data/spec/pg/connection_spec.rb +0 -1949
  125. data/spec/pg/connection_sync_spec.rb +0 -41
  126. data/spec/pg/result_spec.rb +0 -681
  127. data/spec/pg/tuple_spec.rb +0 -333
  128. data/spec/pg/type_map_by_class_spec.rb +0 -138
  129. data/spec/pg/type_map_by_column_spec.rb +0 -226
  130. data/spec/pg/type_map_by_mri_type_spec.rb +0 -136
  131. data/spec/pg/type_map_by_oid_spec.rb +0 -149
  132. data/spec/pg/type_map_in_ruby_spec.rb +0 -164
  133. data/spec/pg/type_map_spec.rb +0 -22
  134. data/spec/pg/type_spec.rb +0 -1123
  135. data/spec/pg_spec.rb +0 -50
data/README.rdoc DELETED
@@ -1,213 +0,0 @@
1
- = pg
2
-
3
- home :: https://github.com/ged/ruby-pg
4
- docs :: http://deveiate.org/code/pg
5
-
6
- {<img src="https://badges.gitter.im/Join%20Chat.svg" alt="Join the chat at https://gitter.im/ged/ruby-pg">}[https://gitter.im/ged/ruby-pg?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge]
7
-
8
-
9
- == Description
10
-
11
- Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/].
12
-
13
- It works with {PostgreSQL 9.2 and later}[http://www.postgresql.org/support/versioning/].
14
-
15
- A small example usage:
16
-
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('procpid', 'usename', 'current_query')
28
- end
29
- end
30
-
31
- == Build Status
32
-
33
- {<img src="https://travis-ci.org/ged/ruby-pg.svg?branch=master" alt="Build Status Travis-CI" />}[https://travis-ci.org/ged/ruby-pg]
34
- {<img src="https://ci.appveyor.com/api/projects/status/gjx5axouf3b1wicp?svg=true" alt="Build Status Appveyor" />}[https://ci.appveyor.com/project/ged/ruby-pg-9j8l3]
35
-
36
-
37
- == Requirements
38
-
39
- * Ruby 2.2 or newer
40
- * PostgreSQL 9.2.x or later (with headers, -dev packages, etc).
41
-
42
- It usually works with earlier versions of Ruby/PostgreSQL as well, but those are
43
- not regularly tested.
44
-
45
-
46
- == Versioning
47
-
48
- We tag and release gems according to the {Semantic Versioning}[http://semver.org/] principle.
49
-
50
- 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.
51
-
52
- For example:
53
-
54
- spec.add_dependency 'pg', '~> 1.0'
55
-
56
-
57
- == How To Install
58
-
59
- Install via RubyGems:
60
-
61
- gem install pg
62
-
63
- You may need to specify the path to the 'pg_config' program installed with
64
- Postgres:
65
-
66
- gem install pg -- --with-pg-config=<path to pg_config>
67
-
68
- If you're installing via Bundler, you can provide compile hints like so:
69
-
70
- bundle config build.pg --with-pg-config=<path to pg_config>
71
-
72
- See README-OS_X.rdoc for more information about installing under MacOS X, and
73
- README-Windows.rdoc for Windows build/installation instructions.
74
-
75
- There's also {a Google+ group}[http://goo.gl/TFy1U] and a
76
- {mailing list}[http://groups.google.com/group/ruby-pg] if you get stuck, or just
77
- want to chat about something.
78
-
79
- If you want to install as a signed gem, the public certs of the gem signers
80
- can be found in {the `certs` directory}[https://github.com/ged/ruby-pg/tree/master/certs]
81
- of the repository.
82
-
83
-
84
- == Type Casts
85
-
86
- Pg can optionally type cast result values and query parameters in Ruby or
87
- native C code. This can speed up data transfers to and from the database,
88
- because String allocations are reduced and conversions in (slower) Ruby code
89
- can be omitted.
90
-
91
- Very basic type casting can be enabled by:
92
-
93
- conn.type_map_for_results = PG::BasicTypeMapForResults.new conn
94
- # ... this works for result value mapping:
95
- conn.exec("select 1, now(), '{2,3}'::int[]").values
96
- # => [[1, 2014-09-21 20:51:56 +0200, [2, 3]]]
97
-
98
- conn.type_map_for_queries = PG::BasicTypeMapForQueries.new conn
99
- # ... and this for param value mapping:
100
- conn.exec_params("SELECT $1::text, $2::text, $3::text", [1, 1.23, [2,3]]).values
101
- # => [["1", "1.2300000000000000E+00", "{2,3}"]]
102
-
103
- But Pg's type casting is highly customizable. That's why it's divided into
104
- 2 layers:
105
-
106
- === Encoders / Decoders (ext/pg_*coder.c, lib/pg/*coder.rb)
107
-
108
- This is the lower layer, containing encoding classes that convert Ruby
109
- objects for transmission to the DBMS and decoding classes to convert
110
- received data back to Ruby objects. The classes are namespaced according
111
- to their format and direction in PG::TextEncoder, PG::TextDecoder,
112
- PG::BinaryEncoder and PG::BinaryDecoder.
113
-
114
- It is possible to assign a type OID, format code (text or binary) and
115
- optionally a name to an encoder or decoder object. It's also possible
116
- to build composite types by assigning an element encoder/decoder.
117
- PG::Coder objects can be used to set up a PG::TypeMap or alternatively
118
- to convert single values to/from their string representation.
119
-
120
- The following PostgreSQL column types are supported by ruby-pg (TE = Text Encoder, TD = Text Decoder, BE = Binary Encoder, BD = Binary Decoder):
121
- * 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_rdoc.html#label-Type+Casts] 💡
122
- * BE: {Int2}[rdoc-ref:PG::BinaryEncoder::Int2], {Int4}[rdoc-ref:PG::BinaryEncoder::Int4], {Int8}[rdoc-ref:PG::BinaryEncoder::Int8]
123
- * Float: {TE}[rdoc-ref:PG::TextEncoder::Float], {TD}[rdoc-ref:PG::TextDecoder::Float], {BD}[rdoc-ref:PG::BinaryDecoder::Float]
124
- * Numeric: {TE}[rdoc-ref:PG::TextEncoder::Numeric], {TD}[rdoc-ref:PG::TextDecoder::Numeric]
125
- * 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]
126
- * 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]
127
- * 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]
128
- * 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]
129
- * Timestamp:
130
- * TE: {local}[rdoc-ref:PG::TextEncoder::TimestampWithoutTimeZone], {UTC}[rdoc-ref:PG::TextEncoder::TimestampUtc], {with-TZ}[rdoc-ref:PG::TextEncoder::TimestampWithTimeZone]
131
- * TD: {local}[rdoc-ref:PG::TextDecoder::TimestampLocal], {UTC}[rdoc-ref:PG::TextDecoder::TimestampUtc], {UTC-to-local}[rdoc-ref:PG::TextDecoder::TimestampUtcToLocal]
132
- * BD: {local}[rdoc-ref:PG::BinaryDecoder::TimestampLocal], {UTC}[rdoc-ref:PG::BinaryDecoder::TimestampUtc], {UTC-to-local}[rdoc-ref:PG::BinaryDecoder::TimestampUtcToLocal]
133
- * Date: {TE}[rdoc-ref:PG::TextEncoder::Date], {TD}[rdoc-ref:PG::TextDecoder::Date]
134
- * JSON and JSONB: {TE}[rdoc-ref:PG::TextEncoder::JSON], {TD}[rdoc-ref:PG::TextDecoder::JSON]
135
- * Inet: {TE}[rdoc-ref:PG::TextEncoder::Inet], {TD}[rdoc-ref:PG::TextDecoder::Inet]
136
- * Array: {TE}[rdoc-ref:PG::TextEncoder::Array], {TD}[rdoc-ref:PG::TextDecoder::Array]
137
- * Composite Type (also called "Row" or "Record"): {TE}[rdoc-ref:PG::TextEncoder::Record], {TD}[rdoc-ref:PG::TextDecoder::Record]
138
-
139
- The following text formats can also be encoded although they are not used as column type:
140
- * COPY input and output data: {TE}[rdoc-ref:PG::TextEncoder::CopyRow], {TD}[rdoc-ref:PG::TextDecoder::CopyRow]
141
- * Literal for insertion into SQL string: {TE}[rdoc-ref:PG::TextEncoder::QuotedLiteral]
142
- * SQL-Identifier: {TE}[rdoc-ref:PG::TextEncoder::Identifier], {TD}[rdoc-ref:PG::TextDecoder::Identifier]
143
-
144
- === PG::TypeMap and derivations (ext/pg_type_map*.c, lib/pg/type_map*.rb)
145
-
146
- A TypeMap defines which value will be converted by which encoder/decoder.
147
- There are different type map strategies, implemented by several derivations
148
- of this class. They can be chosen and configured according to the particular
149
- needs for type casting. The default type map is PG::TypeMapAllStrings.
150
-
151
- A type map can be assigned per connection or per query respectively per
152
- result set. Type maps can also be used for COPY in and out data streaming.
153
- See PG::Connection#copy_data .
154
-
155
- The following base type maps are available:
156
- * PG::TypeMapAllStrings - encodes and decodes all values to and from strings (default)
157
- * PG::TypeMapByClass - selects encoder based on the class of the value to be sent
158
- * PG::TypeMapByColumn - selects encoder and decoder by column order
159
- * PG::TypeMapByOid - selects decoder by PostgreSQL type OID
160
- * PG::TypeMapInRuby - define a custom type map in ruby
161
-
162
- The following type maps are prefilled with type mappings from the PG::BasicTypeRegistry :
163
- * PG::BasicTypeMapForResults - a PG::TypeMapByOid prefilled with decoders for common PostgreSQL column types
164
- * PG::BasicTypeMapBasedOnResult - a PG::TypeMapByOid prefilled with encoders for common PostgreSQL column types
165
- * PG::BasicTypeMapForQueries - a PG::TypeMapByClass prefilled with encoders for common Ruby value classes
166
-
167
-
168
- == Contributing
169
-
170
- To report bugs, suggest features, or check out the source with Git,
171
- {check out the project page}[https://github.com/ged/ruby-pg].
172
-
173
- After checking out the source, run:
174
-
175
- $ rake newb
176
-
177
- This task will install any missing dependencies, run the tests/specs, and
178
- generate the API documentation.
179
-
180
- The current maintainers are Michael Granger <ged@FaerieMUD.org> and
181
- Lars Kanis <lars@greiz-reinsdorf.de>.
182
-
183
-
184
- == Copying
185
-
186
- Copyright (c) 1997-2019 by the authors.
187
-
188
- * Jeff Davis <ruby-pg@j-davis.com>
189
- * Guy Decoux (ts) <decoux@moulon.inra.fr>
190
- * Michael Granger <ged@FaerieMUD.org>
191
- * Lars Kanis <lars@greiz-reinsdorf.de>
192
- * Dave Lee
193
- * Eiji Matsumoto <usagi@ruby.club.or.jp>
194
- * Yukihiro Matsumoto <matz@ruby-lang.org>
195
- * Noboru Saitou <noborus@netlab.jp>
196
-
197
- You may redistribute this software under the same terms as Ruby itself; see
198
- https://www.ruby-lang.org/en/about/license.txt or the BSDL file in the source
199
- for details.
200
-
201
- Portions of the code are from the PostgreSQL project, and are distributed
202
- under the terms of the PostgreSQL license, included in the file POSTGRES.
203
-
204
- Portions copyright LAIKA, Inc.
205
-
206
-
207
- == Acknowledgments
208
-
209
- See Contributors.rdoc for the many additional fine people that have contributed
210
- to this library over the years.
211
-
212
- We are thankful to the people at the ruby-list and ruby-dev mailing lists.
213
- And to the people who developed PostgreSQL.
data/Rakefile.cross DELETED
@@ -1,299 +0,0 @@
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
-
11
- MISCDIR = BASEDIR + 'misc'
12
-
13
- NUM_CPUS = if File.exist?('/proc/cpuinfo')
14
- File.read('/proc/cpuinfo').scan('processor').length
15
- elsif RUBY_PLATFORM.include?( 'darwin' )
16
- `system_profiler SPHardwareDataType | grep 'Cores' | awk '{print $5}'`.chomp
17
- else
18
- 1
19
- end
20
-
21
- class CrossLibrary < OpenStruct
22
- include Rake::DSL
23
-
24
- def initialize(for_platform, openssl_config, toolchain)
25
- super()
26
-
27
- self.for_platform = for_platform
28
- self.openssl_config = openssl_config
29
- self.host_platform = toolchain
30
-
31
- # Cross-compilation constants
32
- self.openssl_version = ENV['OPENSSL_VERSION'] || '1.1.1d'
33
- self.postgresql_version = ENV['POSTGRESQL_VERSION'] || '12.1'
34
-
35
- # Check if symlinks work in the current working directory.
36
- # This fails, if rake-compiler-dock is running on a Windows box.
37
- begin
38
- FileUtils.rm_f '.test_symlink'
39
- FileUtils.ln_s '/', '.test_symlink'
40
- rescue NotImplementedError, SystemCallError
41
- # Symlinks don't work -> use home directory instead
42
- self.compile_home = Pathname( "~/.ruby-pg-build" ).expand_path
43
- else
44
- self.compile_home = Pathname( "./build" ).expand_path
45
- end
46
- self.static_sourcesdir = compile_home + 'sources'
47
- self.static_builddir = compile_home + 'builds' + for_platform
48
- CLOBBER.include( static_sourcesdir )
49
- CLEAN.include( static_builddir )
50
-
51
- # Static OpenSSL build vars
52
- self.static_openssl_builddir = static_builddir + "openssl-#{openssl_version}"
53
-
54
- self.openssl_source_uri =
55
- URI( "http://www.openssl.org/source/openssl-#{openssl_version}.tar.gz" )
56
- self.openssl_tarball = static_sourcesdir + File.basename( openssl_source_uri.path )
57
- self.openssl_makefile = static_openssl_builddir + 'Makefile'
58
-
59
- self.libssl = static_openssl_builddir + 'libssl.a'
60
- self.libcrypto = static_openssl_builddir + 'libcrypto.a'
61
-
62
- self.openssl_patches = Rake::FileList[ (MISCDIR + "openssl-#{openssl_version}.*.patch").to_s ]
63
-
64
- # Static PostgreSQL build vars
65
- self.static_postgresql_builddir = static_builddir + "postgresql-#{postgresql_version}"
66
- self.postgresql_source_uri = begin
67
- uristring = "http://ftp.postgresql.org/pub/source/v%s/postgresql-%s.tar.bz2" %
68
- [ postgresql_version, postgresql_version ]
69
- URI( uristring )
70
- end
71
- self.postgresql_tarball = static_sourcesdir + File.basename( postgresql_source_uri.path )
72
-
73
- self.static_postgresql_srcdir = static_postgresql_builddir + 'src'
74
- self.static_postgresql_libdir = static_postgresql_srcdir + 'interfaces/libpq'
75
- self.static_postgresql_incdir = static_postgresql_srcdir + 'include'
76
-
77
- self.postgresql_global_makefile = static_postgresql_srcdir + 'Makefile.global'
78
- self.postgresql_shlib_makefile = static_postgresql_srcdir + 'Makefile.shlib'
79
- self.postgresql_shlib_mf_orig = static_postgresql_srcdir + 'Makefile.shlib.orig'
80
- self.postgresql_lib = static_postgresql_libdir + 'libpq.dll'
81
- self.postgresql_patches = Rake::FileList[ (MISCDIR + "postgresql-#{postgresql_version}.*.patch").to_s ]
82
-
83
- # clean intermediate files and folders
84
- CLEAN.include( static_builddir.to_s )
85
-
86
- #####################################################################
87
- ### C R O S S - C O M P I L A T I O N - T A S K S
88
- #####################################################################
89
-
90
-
91
- directory static_sourcesdir.to_s
92
-
93
- #
94
- # Static OpenSSL build tasks
95
- #
96
- directory static_openssl_builddir.to_s
97
-
98
- # openssl source file should be stored there
99
- file openssl_tarball => static_sourcesdir do |t|
100
- download( openssl_source_uri, t.name )
101
- end
102
-
103
- # Extract the openssl builds
104
- file static_openssl_builddir => openssl_tarball do |t|
105
- puts "extracting %s to %s" % [ openssl_tarball, static_openssl_builddir.parent ]
106
- static_openssl_builddir.mkpath
107
- run 'tar', '-xzf', openssl_tarball.to_s, '-C', static_openssl_builddir.parent.to_s
108
- openssl_makefile.unlink if openssl_makefile.exist?
109
-
110
- openssl_patches.each do |patchfile|
111
- puts " applying patch #{patchfile}..."
112
- run 'patch', '-Np1', '-d', static_openssl_builddir.to_s,
113
- '-i', File.expand_path( patchfile, BASEDIR )
114
- end
115
- end
116
-
117
- self.cmd_prelude = [
118
- "env",
119
- "CROSS_COMPILE=#{host_platform}-",
120
- "CFLAGS=-DDSO_WIN32",
121
- ]
122
-
123
-
124
- # generate the makefile in a clean build location
125
- file openssl_makefile => static_openssl_builddir do |t|
126
- chdir( static_openssl_builddir ) do
127
- cmd = cmd_prelude.dup
128
- cmd << "./Configure" << openssl_config
129
-
130
- run( *cmd )
131
- end
132
- end
133
-
134
- desc "compile static openssl libraries"
135
- task "openssl_libs:#{for_platform}" => [ libssl, libcrypto ]
136
-
137
- task "compile_static_openssl:#{for_platform}" => openssl_makefile do |t|
138
- chdir( static_openssl_builddir ) do
139
- cmd = cmd_prelude.dup
140
- cmd << 'make' << "-j#{NUM_CPUS}" << 'build_libs'
141
-
142
- run( *cmd )
143
- end
144
- end
145
-
146
- desc "compile static #{libssl}"
147
- file libssl => "compile_static_openssl:#{for_platform}" do |t|
148
- rm t.name.gsub(/\.a$/, ".dll.a")
149
- end
150
-
151
- desc "compile static #{libcrypto}"
152
- file libcrypto => "compile_static_openssl:#{for_platform}" do |t|
153
- rm t.name.gsub(/\.a$/, ".dll.a")
154
- end
155
-
156
-
157
-
158
- #
159
- # Static PostgreSQL build tasks
160
- #
161
- directory static_postgresql_builddir.to_s
162
-
163
-
164
- # postgresql source file should be stored there
165
- file postgresql_tarball => static_sourcesdir do |t|
166
- download( postgresql_source_uri, t.name )
167
- end
168
-
169
- # Extract the postgresql sources
170
- file static_postgresql_builddir => postgresql_tarball do |t|
171
- puts "extracting %s to %s" % [ postgresql_tarball, static_postgresql_builddir.parent ]
172
- static_postgresql_builddir.mkpath
173
- run 'tar', '-xjf', postgresql_tarball.to_s, '-C', static_postgresql_builddir.parent.to_s
174
-
175
- postgresql_patches.each do |patchfile|
176
- puts " applying patch #{patchfile}..."
177
- run 'patch', '-Np1', '-d', static_postgresql_builddir.to_s,
178
- '-i', File.expand_path( patchfile, BASEDIR )
179
- end
180
- end
181
-
182
- # generate the makefile in a clean build location
183
- file postgresql_global_makefile => [ static_postgresql_builddir, "openssl_libs:#{for_platform}" ] do |t|
184
- options = [
185
- "--target=#{host_platform}",
186
- "--host=#{host_platform}",
187
- '--with-openssl',
188
- '--without-zlib',
189
- ]
190
-
191
- chdir( static_postgresql_builddir ) do
192
- configure_path = static_postgresql_builddir + 'configure'
193
- cmd = [ configure_path.to_s, *options ]
194
- cmd << "CFLAGS=-L#{static_openssl_builddir}"
195
- cmd << "LDFLAGS=-L#{static_openssl_builddir}"
196
- cmd << "LDFLAGS_SL=-L#{static_openssl_builddir}"
197
- cmd << "LIBS=-lwsock32 -lgdi32 -lws2_32"
198
- cmd << "CPPFLAGS=-I#{static_openssl_builddir}/include"
199
-
200
- run( *cmd )
201
- end
202
- end
203
-
204
-
205
- # make libpq.dll
206
- task postgresql_lib => [ postgresql_global_makefile ] do |t|
207
- # Work around missing dependency to libcommon in PostgreSQL-9.4.0
208
- chdir( static_postgresql_srcdir + "common" ) do
209
- sh 'make', "-j#{NUM_CPUS}"
210
- end
211
- chdir( static_postgresql_srcdir + "port" ) do
212
- sh 'make', "-j#{NUM_CPUS}"
213
- end
214
-
215
- chdir( postgresql_lib.dirname ) do
216
- sh 'make',
217
- "-j#{NUM_CPUS}",
218
- postgresql_lib.basename.to_s,
219
- 'SHLIB_LINK=-lssl -lcrypto -lcrypt32 -lgdi32 -lsecur32 -lwsock32 -lws2_32'
220
- end
221
- end
222
-
223
-
224
- #desc 'compile libpg.a'
225
- task "native:#{for_platform}" => postgresql_lib
226
-
227
- # copy libpq.dll to lib dir
228
- dest_libpq = "lib/#{for_platform}/#{postgresql_lib.basename}"
229
- directory File.dirname(dest_libpq)
230
- file dest_libpq => [postgresql_lib, File.dirname(dest_libpq)] do
231
- cp postgresql_lib, dest_libpq
232
- end
233
-
234
- stage_libpq = "tmp/#{for_platform}/stage/#{dest_libpq}"
235
- directory File.dirname(stage_libpq)
236
- file stage_libpq => [postgresql_lib, File.dirname(stage_libpq)] do |t|
237
- cp postgresql_lib, stage_libpq
238
- end
239
- end
240
-
241
- def download(url, save_to)
242
- part = save_to+".part"
243
- sh "wget #{url.to_s.inspect} -O #{part.inspect} || curl #{url.to_s.inspect} -o #{part.inspect}"
244
- FileUtils.mv part, save_to
245
- end
246
-
247
- def run(*args)
248
- sh(*args)
249
- end
250
- end
251
-
252
- CrossLibraries = [
253
- ['x86-mingw32', 'mingw', 'i686-w64-mingw32'],
254
- ['x64-mingw32', 'mingw64', 'x86_64-w64-mingw32'],
255
- ].map do |platform, openssl_config, toolchain|
256
- CrossLibrary.new platform, openssl_config, toolchain
257
- end
258
-
259
- desc 'cross compile pg for win32'
260
- task :cross => [ :mingw32 ]
261
-
262
- task :mingw32 do
263
- # Use Rake::ExtensionCompiler helpers to find the proper host
264
- unless Rake::ExtensionCompiler.mingw_host then
265
- warn "You need to install mingw32 cross compile functionality to be able to continue."
266
- warn "Please refer to your distribution/package manager documentation about installation."
267
- fail
268
- end
269
- end
270
-
271
- task 'gem:windows:prepare' do
272
- require 'io/console'
273
- require 'rake_compiler_dock'
274
-
275
- # Copy gem signing key and certs to be accessable from the docker container
276
- mkdir_p 'build/gem'
277
- sh "cp ~/.gem/gem-*.pem build/gem/ || true"
278
- sh "bundle package"
279
- begin
280
- OpenSSL::PKey.read(File.read(File.expand_path("~/.gem/gem-private_key.pem")), ENV["GEM_PRIVATE_KEY_PASSPHRASE"] || "")
281
- rescue OpenSSL::PKey::PKeyError
282
- ENV["GEM_PRIVATE_KEY_PASSPHRASE"] = STDIN.getpass("Enter passphrase of gem signature key: ")
283
- retry
284
- end
285
- end
286
-
287
- CrossLibraries.each do |xlib|
288
- platform = xlib.for_platform
289
- desc "Build fat binary gem for platform #{platform}"
290
- task "gem:windows:#{platform}" => ['ChangeLog', 'gem:windows:prepare', xlib.openssl_tarball, xlib.postgresql_tarball] do
291
- RakeCompilerDock.sh <<-EOT, platform: platform
292
- (cp build/gem/gem-*.pem ~/.gem/ || true) &&
293
- bundle install --local &&
294
- rake native:#{platform} pkg/#{$hoespec.spec.full_name}-#{platform}.gem MAKE="make -j`nproc`"
295
- EOT
296
- end
297
- desc "Build the windows binary gems"
298
- multitask 'gem:windows' => "gem:windows:#{platform}"
299
- end