pg 0.17.1 → 0.18.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/ChangeLog +2407 -2
  4. data/History.rdoc +68 -0
  5. data/Manifest.txt +29 -1
  6. data/README-Windows.rdoc +15 -26
  7. data/README.rdoc +52 -2
  8. data/Rakefile +56 -18
  9. data/Rakefile.cross +77 -49
  10. data/ext/extconf.rb +33 -26
  11. data/ext/pg.c +142 -21
  12. data/ext/pg.h +242 -6
  13. data/ext/pg_binary_decoder.c +162 -0
  14. data/ext/pg_binary_encoder.c +162 -0
  15. data/ext/pg_coder.c +479 -0
  16. data/ext/pg_connection.c +858 -553
  17. data/ext/pg_copy_coder.c +561 -0
  18. data/ext/pg_errors.c +6 -0
  19. data/ext/pg_result.c +479 -128
  20. data/ext/pg_text_decoder.c +421 -0
  21. data/ext/pg_text_encoder.c +663 -0
  22. data/ext/pg_type_map.c +159 -0
  23. data/ext/pg_type_map_all_strings.c +116 -0
  24. data/ext/pg_type_map_by_class.c +239 -0
  25. data/ext/pg_type_map_by_column.c +312 -0
  26. data/ext/pg_type_map_by_mri_type.c +284 -0
  27. data/ext/pg_type_map_by_oid.c +355 -0
  28. data/ext/pg_type_map_in_ruby.c +299 -0
  29. data/ext/util.c +149 -0
  30. data/ext/util.h +65 -0
  31. data/lib/pg/basic_type_mapping.rb +399 -0
  32. data/lib/pg/coder.rb +83 -0
  33. data/lib/pg/connection.rb +81 -29
  34. data/lib/pg/result.rb +13 -3
  35. data/lib/pg/text_decoder.rb +44 -0
  36. data/lib/pg/text_encoder.rb +27 -0
  37. data/lib/pg/type_map_by_column.rb +15 -0
  38. data/lib/pg.rb +12 -2
  39. data/spec/{lib/helpers.rb → helpers.rb} +101 -39
  40. data/spec/pg/basic_type_mapping_spec.rb +251 -0
  41. data/spec/pg/connection_spec.rb +516 -218
  42. data/spec/pg/result_spec.rb +216 -112
  43. data/spec/pg/type_map_by_class_spec.rb +138 -0
  44. data/spec/pg/type_map_by_column_spec.rb +222 -0
  45. data/spec/pg/type_map_by_mri_type_spec.rb +136 -0
  46. data/spec/pg/type_map_by_oid_spec.rb +149 -0
  47. data/spec/pg/type_map_in_ruby_spec.rb +164 -0
  48. data/spec/pg/type_map_spec.rb +22 -0
  49. data/spec/pg/type_spec.rb +697 -0
  50. data/spec/pg_spec.rb +24 -18
  51. data.tar.gz.sig +0 -0
  52. metadata +111 -45
  53. metadata.gz.sig +0 -0
data/History.rdoc CHANGED
@@ -1,3 +1,71 @@
1
+ == v0.18.4 [2015-11-13] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ Enhancements:
4
+ - Fixing compilation problems with Microsoft Visual Studio 2008. GH #10
5
+ - Avoid name clash with xcode and jemalloc. PR#22, PR#23
6
+
7
+ Bugfixes:
8
+ - Avoid segfault, when quote_ident or TextEncoder::Identifier
9
+ is called with Array containing non-strings. #226
10
+
11
+
12
+ == v0.18.3 [2015-09-03] Michael Granger <ged@FaerieMUD.org>
13
+
14
+ Enhancements:
15
+ - Use rake-compiler-dock to build windows gems easily.
16
+ - Add CI-tests on appveyor and fix test cases accordingly.
17
+
18
+ Bugfixes:
19
+ - Fix data type resulting in wrong base64 encoding.
20
+ - Change instance_of checks to kind_of for subclassing. #220
21
+ - TextDecoder::Date returns an actual Ruby Date instead of a Time
22
+ (thanks to Thomas Ramfjord)
23
+
24
+
25
+ == v0.18.2 [2015-05-14] Michael Granger <ged@FaerieMUD.org>
26
+
27
+ Enhancements:
28
+
29
+ - Allow URI connection string (thanks to Chris Bandy)
30
+ - Allow Array type parameter to conn.quote_ident
31
+
32
+ Bugfixes:
33
+
34
+ - Speedups and fixes for PG::TextDecoder::Identifier and quoting behavior
35
+ - Revert addition of PG::Connection#hostaddr [#202].
36
+ - Fix decoding of fractional timezones and timestamps [#203]
37
+ - Fixes for non-C99 compilers
38
+ - Avoid possible symbol name clash when linking againt static libpq.
39
+
40
+
41
+ == v0.18.1 [2015-01-05] Michael Granger <ged@FaerieMUD.org>
42
+
43
+ Correct the minimum compatible Ruby version to 1.9.3. #199
44
+
45
+
46
+ == v0.18.0 [2015-01-01] Michael Granger <ged@FaerieMUD.org>
47
+
48
+ Bugfixes:
49
+ - Fix OID to Integer mapping (it is unsigned now). #187
50
+ - Fix possible segfault in conjunction with notice receiver. #185
51
+
52
+ Enhancements:
53
+
54
+ - Add an extensible type cast system.
55
+ - A lot of performance improvements.
56
+ - Return frozen String objects for result field names.
57
+ - Add PG::Result#stream_each and #stream_each_row as fast helpers for
58
+ the single row mode.
59
+ - Add Enumerator variant to PG::Result#each and #each_row.
60
+ - Add PG::Connection#conninfo and #hostaddr.
61
+ - Add PG.init_openssl and PG.init_ssl methods.
62
+ - Add PG::Result.inspect
63
+ - Force zero termination for all text strings that are given to libpq.
64
+ It raises an ArgumentError if the string contains a null byte.
65
+ - Update Windows cross build to PostgreSQL 9.3.
66
+
67
+
68
+
1
69
  == v0.17.1 [2013-12-18] Michael Granger <ged@FaerieMUD.org>
2
70
 
3
71
  Bugfixes:
data/Manifest.txt CHANGED
@@ -20,17 +20,37 @@ ext/gvl_wrappers.c
20
20
  ext/gvl_wrappers.h
21
21
  ext/pg.c
22
22
  ext/pg.h
23
+ ext/pg_binary_decoder.c
24
+ ext/pg_binary_encoder.c
25
+ ext/pg_coder.c
23
26
  ext/pg_connection.c
27
+ ext/pg_copy_coder.c
24
28
  ext/pg_errors.c
25
29
  ext/pg_result.c
30
+ ext/pg_text_decoder.c
31
+ ext/pg_text_encoder.c
32
+ ext/pg_type_map.c
33
+ ext/pg_type_map_all_strings.c
34
+ ext/pg_type_map_by_class.c
35
+ ext/pg_type_map_by_column.c
36
+ ext/pg_type_map_by_mri_type.c
37
+ ext/pg_type_map_by_oid.c
38
+ ext/pg_type_map_in_ruby.c
39
+ ext/util.c
40
+ ext/util.h
26
41
  ext/vc/pg.sln
27
42
  ext/vc/pg_18/pg.vcproj
28
43
  ext/vc/pg_19/pg_19.vcproj
29
44
  lib/pg.rb
45
+ lib/pg/basic_type_mapping.rb
46
+ lib/pg/coder.rb
30
47
  lib/pg/connection.rb
31
48
  lib/pg/constants.rb
32
49
  lib/pg/exceptions.rb
33
50
  lib/pg/result.rb
51
+ lib/pg/text_decoder.rb
52
+ lib/pg/text_encoder.rb
53
+ lib/pg/type_map_by_column.rb
34
54
  sample/array_insert.rb
35
55
  sample/async_api.rb
36
56
  sample/async_copyto.rb
@@ -51,7 +71,15 @@ sample/wal_shipper.rb
51
71
  sample/warehouse_partitions.rb
52
72
  spec/data/expected_trace.out
53
73
  spec/data/random_binary_data
54
- spec/lib/helpers.rb
74
+ spec/helpers.rb
75
+ spec/pg/basic_type_mapping_spec.rb
55
76
  spec/pg/connection_spec.rb
56
77
  spec/pg/result_spec.rb
78
+ spec/pg/type_map_by_class_spec.rb
79
+ spec/pg/type_map_by_column_spec.rb
80
+ spec/pg/type_map_by_mri_type_spec.rb
81
+ spec/pg/type_map_by_oid_spec.rb
82
+ spec/pg/type_map_in_ruby_spec.rb
83
+ spec/pg/type_map_spec.rb
84
+ spec/pg/type_spec.rb
57
85
  spec/pg_spec.rb
data/README-Windows.rdoc CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  In order to build this extension on MS Windows you will need a couple things.
4
4
 
5
- First, a compiler. For the one click installer this means you should either
6
- use VC++ 6.0 or the compiler that comes with cygwin or mingw if you're
7
- building on that platform.
5
+ First, a compiler. For the one click installer this means you should use
6
+ the DevKit or the compiler that comes with cygwin if you're building on that
7
+ platform.
8
8
 
9
9
  If you've built Ruby yourself, you should use the same compiler to build
10
10
  this library that you used to build Ruby.
@@ -29,34 +29,23 @@ Adjust your path accordingly. BE SURE TO USE THE SHORT PATH NAMES! If you
29
29
  try to use a path with spaces in it, the nmake.exe program will choke.
30
30
 
31
31
 
32
- == Cross compiling for mswin32
32
+ == Building binary 'pg' gems for MS Windows
33
33
 
34
- Using rake-compiler a cross compiled pg gem can be build on a Linux or MacOS X
35
- host for the win32 platform. The generated gem is statically linked against
36
- libpq and libssl. OpenSSL and PostgreSQL are downloaded and compiled from the
37
- sources. There are no runtime dependencies to any but the standard Windows
38
- DLLs.
34
+ Binary gems for windows can be built on Linux, OS-X and even on Windows
35
+ with the help of docker. This is how regular windows gems are built for
36
+ rubygems.org .
39
37
 
40
- Install mingw32 using the instructions in rake-compiler's README.
41
- For Debian/Ubuntu it is <tt>apt-get install gcc-mingw32</tt> .
42
- Use ruby-1.8.7 for the following commands.
38
+ To do this, install boot2docker [on Windows](https://github.com/boot2docker/windows-installer/releases)
39
+ or [on OS X](https://github.com/boot2docker/osx-installer/releases) and make
40
+ sure it is started. A native Docker installation is best on Linux.
43
41
 
44
- Download and cross compile ruby 1.8 and 1.9 for win32 with:
42
+ Then run:
45
43
 
46
- rake-compiler cross-ruby VERSION=1.8.7-p352
47
- rake-compiler cross-ruby VERSION=1.9.2-p290
44
+ rake gem:windows
48
45
 
49
- Download and cross compile pg for win32:
50
-
51
- rake cross native gem
52
-
53
- or with custom versions:
54
-
55
- rake cross native gem RUBY_CC_VERSION=1.8.7:1.9.2 \
56
- OPENSSL_VERSION=1.0.0e POSTGRESQL_VERSION=9.1.1
57
-
58
- If everything works, there should be pg-VERSION-x86-mingw32.gem in the pkg
59
- directory.
46
+ This will download a docker image suited for building windows gems, and it
47
+ will download and build OpenSSL and PostgreSQL. Finally the gem is built
48
+ containing binaries for all supported ruby versions.
60
49
 
61
50
 
62
51
  == Reporting Problems
data/README.rdoc CHANGED
@@ -4,6 +4,8 @@ home :: https://bitbucket.org/ged/ruby-pg
4
4
  mirror :: https://github.com/ged/ruby-pg
5
5
  docs :: http://deveiate.org/code/pg
6
6
 
7
+ {<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]
8
+
7
9
 
8
10
  == Description
9
11
 
@@ -29,7 +31,8 @@ A small example usage:
29
31
 
30
32
  == Build Status
31
33
 
32
- {<img src="https://travis-ci.org/ged/ruby-pg.png?branch=master" alt="Build Status" />}[https://travis-ci.org/ged/ruby-pg]
34
+ {<img src="https://travis-ci.org/ged/ruby-pg.png?branch=master" alt="Build Status Travis-CI" />}[https://travis-ci.org/ged/ruby-pg]
35
+ {<img src="https://ci.appveyor.com/api/projects/status/at4g4swb2cd4xji7/branch/master?svg=true" alt="Build Status Appveyor" />}[https://ci.appveyor.com/project/ged/ruby-pg]
33
36
 
34
37
 
35
38
  == Requirements
@@ -64,6 +67,53 @@ There's also {a Google+ group}[http://goo.gl/TFy1U] and a
64
67
  want to chat about something.
65
68
 
66
69
 
70
+ == Type Casts
71
+
72
+ Pg can optionally type cast result values and query parameters in Ruby or
73
+ native C code. This can speed up data transfers to and from the database,
74
+ because String allocations are reduced and conversions in (slower) Ruby code
75
+ can be omitted.
76
+
77
+ Very basic type casting can be enabled by:
78
+
79
+ conn.type_map_for_results = PG::BasicTypeMapForResults.new conn
80
+ # ... this works for result value mapping:
81
+ conn.exec("select 1, now(), '{2,3}'::int[]").values
82
+ # => [[1, 2014-09-21 20:51:56 +0200, [2, 3]]]
83
+
84
+ conn.type_map_for_queries = PG::BasicTypeMapForQueries.new conn
85
+ # ... and this for param value mapping:
86
+ conn.exec_params("SELECT $1::text, $2::text, $3::text", [1, 1.23, [2,3]]).values
87
+ # => [["1", "1.2300000000000000E+00", "{2,3}"]]
88
+
89
+ But Pg's type casting is highly customizable. That's why it's divided into
90
+ 2 layers:
91
+
92
+ === Encoders / Decoders (ext/pg_*coder.c, lib/pg/*coder.rb)
93
+
94
+ This is the lower layer, containing encoding classes that convert Ruby
95
+ objects for transmission to the DBMS and decoding classes to convert
96
+ received data back to Ruby objects. The classes are namespaced according
97
+ to their format and direction in PG::TextEncoder, PG::TextDecoder,
98
+ PG::BinaryEncoder and PG::BinaryDecoder.
99
+
100
+ It is possible to assign a type OID, format code (text or binary) and
101
+ optionally a name to an encoder or decoder object. It's also possible
102
+ to build composite types by assigning an element encoder/decoder.
103
+ PG::Coder objects can be used to set up a PG::TypeMap or alternatively
104
+ to convert single values to/from their string representation.
105
+
106
+ === PG::TypeMap and derivations (ext/pg_type_map*.c, lib/pg/type_map*.rb)
107
+
108
+ A TypeMap defines which value will be converted by which encoder/decoder.
109
+ There are different type map strategies, implemented by several derivations
110
+ of this class. They can be chosen and configured according to the particular
111
+ needs for type casting. The default type map is PG::TypeMapAllStrings.
112
+
113
+ A type map can be assigned per connection or per query respectively per
114
+ result set. Type maps can also be used for COPY in and out data streaming.
115
+
116
+
67
117
  == Contributing
68
118
 
69
119
  To report bugs, suggest features, or check out the source with Mercurial,
@@ -83,7 +133,7 @@ Lars Kanis <lars@greiz-reinsdorf.de>.
83
133
 
84
134
  == Copying
85
135
 
86
- Copyright (c) 1997-2013 by the authors.
136
+ Copyright (c) 1997-2015 by the authors.
87
137
 
88
138
  * Jeff Davis <ruby-pg@j-davis.com>
89
139
  * Guy Decoux (ts) <decoux@moulon.inra.fr>
data/Rakefile CHANGED
@@ -29,6 +29,8 @@ TMPDIR = BASEDIR + 'tmp'
29
29
  DLEXT = RbConfig::CONFIG['DLEXT']
30
30
  EXT = LIBDIR + "pg_ext.#{DLEXT}"
31
31
 
32
+ GEMSPEC = 'pg.gemspec'
33
+
32
34
  TEST_DIRECTORY = BASEDIR + "tmp_test_specs"
33
35
 
34
36
  CLOBBER.include( TEST_DIRECTORY.to_s )
@@ -53,27 +55,25 @@ $hoespec = Hoe.spec 'pg' do
53
55
  self.extra_rdoc_files = Rake::FileList[ '*.rdoc' ]
54
56
  self.extra_rdoc_files.include( 'POSTGRES', 'LICENSE' )
55
57
  self.extra_rdoc_files.include( 'ext/*.c' )
58
+ self.license :BSD
56
59
 
57
60
  self.developer 'Michael Granger', 'ged@FaerieMUD.org'
58
61
  self.developer 'Lars Kanis', 'lars@greiz-reinsdorf.de'
59
62
 
60
63
  self.dependency 'rake-compiler', '~> 0.9', :developer
61
- self.dependency 'hoe', '~> 3.5.1', :developer
62
- self.dependency 'hoe-deveiate', '~> 0.2', :developer
64
+ self.dependency 'rake-compiler-dock', '~> 0.3', :developer
65
+ self.dependency 'hoe', '~> 3.12', :developer
66
+ self.dependency 'hoe-deveiate', '~> 0.6', :developer
63
67
  self.dependency 'hoe-bundler', '~> 1.0', :developer
68
+ self.dependency 'rspec', '~> 3.0', :developer
64
69
 
65
70
  self.spec_extras[:licenses] = ['BSD', 'Ruby', 'GPL']
66
71
  self.spec_extras[:extensions] = [ 'ext/extconf.rb' ]
67
72
 
68
- self.require_ruby_version( '>= 1.8.7' )
73
+ self.require_ruby_version( '>= 1.9.3' )
69
74
 
70
75
  self.hg_sign_tags = true if self.respond_to?( :hg_sign_tags= )
71
76
  self.check_history_on_release = true if self.respond_to?( :check_history_on_release= )
72
- self.spec_extras[:rdoc_options] = [
73
- '-f', 'fivefish',
74
- '-t', 'pg: The Ruby Interface to PostgreSQL',
75
- '-m', 'README.rdoc',
76
- ]
77
77
 
78
78
  self.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}"
79
79
  end
@@ -118,16 +118,38 @@ Rake::ExtensionTask.new do |ext|
118
118
  ext.cross_compile = true
119
119
  ext.cross_platform = CrossLibraries.map &:for_platform
120
120
 
121
- ext.cross_config_options += CrossLibraries.map do |lib|
122
- {
123
- lib.for_platform => [
124
- "--with-pg-include=#{lib.static_postgresql_libdir}",
125
- "--with-opt-include=#{lib.static_postgresql_incdir}",
126
- "--with-pg-lib=#{lib.static_postgresql_libdir}",
127
- "--with-opt-lib=#{lib.static_openssl_builddir}",
128
- ]
129
- }
130
- end
121
+ ext.cross_config_options += CrossLibraries.map do |lib|
122
+ {
123
+ lib.for_platform => [
124
+ "--enable-windows-cross",
125
+ "--with-pg-include=#{lib.static_postgresql_incdir}",
126
+ "--with-pg-lib=#{lib.static_postgresql_libdir}",
127
+ # libpq-fe.h resides in src/interfaces/libpq/ before make install
128
+ "--with-opt-include=#{lib.static_postgresql_libdir}",
129
+ ]
130
+ }
131
+ end
132
+
133
+ # Add libpq.dll to windows binary gemspec
134
+ ext.cross_compiling do |spec|
135
+ # mingw32-platform strings differ (RUBY_PLATFORM=i386-mingw32 vs. x86-mingw32 for rubygems)
136
+ spec.files << "lib/#{spec.platform.to_s.gsub(/^x86-/, "i386-")}/libpq.dll"
137
+ end
138
+ end
139
+
140
+
141
+ # Use the fivefish formatter for docs generated from development checkout
142
+ if File.directory?( '.hg' )
143
+ require 'rdoc/task'
144
+
145
+ Rake::Task[ 'docs' ].clear
146
+ RDoc::Task.new( 'docs' ) do |rdoc|
147
+ rdoc.main = "README.rdoc"
148
+ rdoc.rdoc_files.include( "*.rdoc", "ChangeLog", "lib/**/*.rb", 'ext/**/*.{c,h}' )
149
+ rdoc.generator = :fivefish
150
+ rdoc.title = "PG: The Ruby PostgreSQL Driver"
151
+ rdoc.rdoc_dir = 'doc'
152
+ end
131
153
  end
132
154
 
133
155
 
@@ -139,6 +161,7 @@ file 'ChangeLog' do |task|
139
161
  if File.exist?('.hg/branch')
140
162
  $stderr.puts "Updating the changelog..."
141
163
  begin
164
+ include Hoe::MercurialHelpers
142
165
  content = make_changelog()
143
166
  rescue NameError
144
167
  abort "Packaging tasks require the hoe-mercurial plugin (gem install hoe-mercurial)"
@@ -178,3 +201,18 @@ file 'ext/pg_errors.c' => ['ext/errorcodes.def'] do
178
201
  # trigger compilation of changed errorcodes.def
179
202
  touch 'ext/pg_errors.c'
180
203
  end
204
+
205
+ task :gemspec => GEMSPEC
206
+ file GEMSPEC => __FILE__
207
+ task GEMSPEC do |task|
208
+ spec = $hoespec.spec
209
+ spec.files.delete( '.gemtest' )
210
+ spec.version = "#{spec.version}.pre#{Time.now.strftime("%Y%m%d%H%M%S")}"
211
+ File.open( task.name, 'w' ) do |fh|
212
+ fh.write( spec.to_ruby )
213
+ end
214
+ end
215
+
216
+ CLOBBER.include( GEMSPEC.to_s )
217
+ task :default => :gemspec
218
+
data/Rakefile.cross CHANGED
@@ -21,17 +21,28 @@ end
21
21
  class CrossLibrary < OpenStruct
22
22
  include Rake::DSL
23
23
 
24
- def initialize(for_platform, openssl_config)
24
+ def initialize(for_platform, openssl_config, toolchain)
25
25
  super()
26
26
 
27
27
  self.for_platform = for_platform
28
28
  self.openssl_config = openssl_config
29
+ self.host_platform = toolchain
29
30
 
30
31
  # Cross-compilation constants
31
- self.openssl_version = ENV['OPENSSL_VERSION'] || '1.0.1e'
32
- self.postgresql_version = ENV['POSTGRESQL_VERSION'] || '9.2.3'
33
-
34
- self.compile_home = Pathname( "./build" ).expand_path
32
+ self.openssl_version = ENV['OPENSSL_VERSION'] || '1.0.2d'
33
+ self.postgresql_version = ENV['POSTGRESQL_VERSION'] || '9.4.4'
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 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
35
46
  self.static_sourcesdir = compile_home + 'sources'
36
47
  self.static_builddir = compile_home + 'builds' + for_platform
37
48
 
@@ -64,25 +75,14 @@ class CrossLibrary < OpenStruct
64
75
  self.postgresql_global_makefile = static_postgresql_srcdir + 'Makefile.global'
65
76
  self.postgresql_shlib_makefile = static_postgresql_srcdir + 'Makefile.shlib'
66
77
  self.postgresql_shlib_mf_orig = static_postgresql_srcdir + 'Makefile.shlib.orig'
67
- self.postgresql_lib = static_postgresql_libdir + 'libpq.a'
78
+ self.postgresql_lib = static_postgresql_libdir + 'libpq.dll'
68
79
  self.postgresql_patches = Rake::FileList[ (MISCDIR + "postgresql-#{postgresql_version}.*.patch").to_s ]
69
80
 
70
- # Use rake-compilers config.yml to determine the toolchain that was used
71
- # to build Ruby for this platform.
72
- self.host_platform = begin
73
- config_file = YAML.load_file(File.expand_path("~/.rake-compiler/config.yml"))
74
- _, rbfile = config_file.find{|key, fname| key.start_with?("rbconfig-#{for_platform}-") }
75
- IO.read(rbfile).match(/CONFIG\["CC"\] = "(.*)"/)[1].sub(/\-gcc/, '')
76
- rescue
77
- nil
78
- end
79
-
80
-
81
81
  # clean intermediate files and folders
82
82
  CLEAN.include( static_builddir.to_s )
83
83
 
84
84
 
85
- ENV['RUBY_CC_VERSION'] ||= '1.8.7:1.9.3:2.0.0'
85
+ ENV['RUBY_CC_VERSION'] ||= '1.9.3:2.0.0'
86
86
 
87
87
  def download(url, save_to)
88
88
  part = save_to+".part"
@@ -136,7 +136,7 @@ class CrossLibrary < OpenStruct
136
136
 
137
137
  # generate the makefile in a clean build location
138
138
  file openssl_makefile => static_openssl_builddir do |t|
139
- Dir.chdir( static_openssl_builddir ) do
139
+ chdir( static_openssl_builddir ) do
140
140
  cmd = cmd_prelude.dup
141
141
  cmd << "./Configure" << openssl_config
142
142
 
@@ -148,7 +148,7 @@ class CrossLibrary < OpenStruct
148
148
  task :openssl_libs => [ libssleay32, libeay32 ]
149
149
 
150
150
  task :compile_static_openssl => openssl_makefile do |t|
151
- Dir.chdir( static_openssl_builddir ) do
151
+ chdir( static_openssl_builddir ) do
152
152
  cmd = cmd_prelude.dup
153
153
  cmd << 'make' << "-j#{NUM_CPUS}" << 'build_libs'
154
154
 
@@ -184,7 +184,6 @@ class CrossLibrary < OpenStruct
184
184
  puts "extracting %s to %s" % [ postgresql_tarball, static_postgresql_builddir.parent ]
185
185
  static_postgresql_builddir.mkpath
186
186
  run 'tar', '-xjf', postgresql_tarball.to_s, '-C', static_postgresql_builddir.parent.to_s
187
- mv postgresql_shlib_makefile, postgresql_shlib_mf_orig
188
187
 
189
188
  postgresql_patches.each do |patchfile|
190
189
  puts " applying patch #{patchfile}..."
@@ -200,10 +199,9 @@ class CrossLibrary < OpenStruct
200
199
  "--host=#{host_platform}",
201
200
  '--with-openssl',
202
201
  '--without-zlib',
203
- '--disable-shared',
204
202
  ]
205
203
 
206
- Dir.chdir( static_postgresql_builddir ) do
204
+ chdir( static_postgresql_builddir ) do
207
205
  configure_path = static_postgresql_builddir + 'configure'
208
206
  cmd = [ configure_path.to_s, *options ]
209
207
  cmd << "CFLAGS=-L#{static_openssl_builddir}"
@@ -217,40 +215,46 @@ class CrossLibrary < OpenStruct
217
215
  end
218
216
 
219
217
 
220
- # patch the Makefile.shlib -- depend on the build dir so it's only
221
- # rewritten if the tarball is re-extracted.
222
- file postgresql_shlib_makefile => postgresql_shlib_mf_orig do |t|
223
- tf = Tempfile.new( postgresql_shlib_makefile.basename.to_s )
224
- postgresql_shlib_mf_orig.open( File::RDONLY ) do |ifh|
225
- ifh.each_line do |line|
226
- tf.print( line.sub(/^(\s*haslibarule\s*=\s*yes)/, "# \\1 ") )
227
- end
218
+ # make libpq.dll
219
+ task postgresql_lib => [ postgresql_global_makefile ] do |t|
220
+ # Work around missing dependency to libcommon in PostgreSQL-9.4.0
221
+ chdir( static_postgresql_srcdir + "common" ) do
222
+ sh 'make', "-j#{NUM_CPUS}"
228
223
  end
229
- tf.close
230
224
 
231
- FileUtils.mv( tf.path, t.name, :verbose => $puts )
225
+ chdir( postgresql_lib.dirname ) do
226
+ sh 'make',
227
+ "-j#{NUM_CPUS}",
228
+ postgresql_lib.basename.to_s,
229
+ 'SHLIB_LINK=-lssleay32 -leay32 -lcrypt32 -lgdi32 -lsecur32 -lwsock32 -lws2_32'
230
+ end
232
231
  end
233
232
 
234
233
 
235
- # make libpq.a
236
- task postgresql_lib => [ postgresql_global_makefile, postgresql_shlib_makefile ] do |t|
237
- Dir.chdir( postgresql_lib.dirname ) do
238
- sh 'make', "-j#{NUM_CPUS}", postgresql_lib.basename.to_s, 'PORTNAME=win32'
239
- end
240
- end
234
+ #desc 'compile libpg.a'
235
+ task :libpq => postgresql_lib
241
236
 
237
+ # copy libpq.dll to lib dir
238
+ dest_libpq = "lib/#{for_platform}/#{postgresql_lib.basename}"
239
+ directory File.dirname(dest_libpq)
240
+ file dest_libpq => [postgresql_lib, File.dirname(dest_libpq)] do
241
+ cp postgresql_lib, dest_libpq
242
+ end
242
243
 
243
- #desc 'compile static libpg.a'
244
- task :static_libpq => postgresql_lib
244
+ stage_libpq = "tmp/#{for_platform}/stage/#{dest_libpq}"
245
+ directory File.dirname(stage_libpq)
246
+ file stage_libpq => [postgresql_lib, File.dirname(stage_libpq)] do |t|
247
+ cp postgresql_lib, stage_libpq
248
+ end
245
249
  end
246
250
  end
247
251
 
248
252
  if File.exist?(File.expand_path("~/.rake-compiler/config.yml"))
249
253
  CrossLibraries = [
250
- ['i386-mingw32', 'mingw'],
251
- ['x64-mingw32', 'mingw64'],
252
- ].map do |platform, openssl_config|
253
- CrossLibrary.new platform, openssl_config
254
+ ['i386-mingw32', 'mingw', 'i686-w64-mingw32'],
255
+ ['x64-mingw32', 'mingw64', 'x86_64-w64-mingw32'],
256
+ ].map do |platform, openssl_config, toolchain|
257
+ CrossLibrary.new platform, openssl_config, toolchain
254
258
  end
255
259
  else
256
260
  $stderr.puts "Cross-compilation disabled -- rake-compiler not properly installed"
@@ -258,10 +262,7 @@ else
258
262
  end
259
263
 
260
264
  desc 'cross compile pg for win32'
261
- task :cross do
262
- ENV['CROSS_COMPILING'] = 'yes'
263
- end
264
- task :cross => [ :mingw32, :static_libpq ]
265
+ task :cross => [ :mingw32, :libpq ]
265
266
 
266
267
  task :mingw32 do
267
268
  # Use Rake::ExtensionCompiler helpers to find the proper host
@@ -271,3 +272,30 @@ task :mingw32 do
271
272
  fail
272
273
  end
273
274
  end
275
+
276
+ # To reduce the gem file size strip mingw32 dlls before packaging
277
+ ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version|
278
+ task "tmp/i386-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/pg_ext.so" do |t|
279
+ sh "i686-w64-mingw32-strip -S tmp/i386-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/pg_ext.so"
280
+ end
281
+
282
+ task "tmp/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/pg_ext.so" do |t|
283
+ sh "x86_64-w64-mingw32-strip -S tmp/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/pg_ext.so"
284
+ end
285
+ end
286
+
287
+ desc "Build the windows binary gems"
288
+ task 'gem:windows' => ['ChangeLog'] do
289
+ require 'rake_compiler_dock'
290
+
291
+ # Copy gem signing key and certs to be accessable from the docker container
292
+ mkdir_p 'build/gem'
293
+ sh "cp ~/.gem/gem-*.pem build/gem/"
294
+
295
+ RakeCompilerDock.sh <<-EOT
296
+ mkdir ~/.gem &&
297
+ cp build/gem/gem-*.pem ~/.gem/ &&
298
+ bundle install &&
299
+ rake cross native gem RUBYOPT=--disable-rubygems RUBY_CC_VERSION=1.9.3:2.0.0:2.1.6:2.2.2
300
+ EOT
301
+ end