tiny_tds 2.1.6-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +407 -0
  3. data/.codeclimate.yml +20 -0
  4. data/.gitattributes +1 -0
  5. data/.gitignore +22 -0
  6. data/.rubocop.yml +31 -0
  7. data/CHANGELOG.md +280 -0
  8. data/CODE_OF_CONDUCT.md +31 -0
  9. data/Gemfile +2 -0
  10. data/ISSUE_TEMPLATE.md +38 -0
  11. data/MIT-LICENSE +23 -0
  12. data/README.md +504 -0
  13. data/Rakefile +62 -0
  14. data/VERSION +1 -0
  15. data/bin/defncopy-ttds +3 -0
  16. data/bin/tsql-ttds +3 -0
  17. data/docker-compose.yml +34 -0
  18. data/exe/.keep +0 -0
  19. data/ext/tiny_tds/client.c +499 -0
  20. data/ext/tiny_tds/client.h +53 -0
  21. data/ext/tiny_tds/extconf.rb +92 -0
  22. data/ext/tiny_tds/extconsts.rb +15 -0
  23. data/ext/tiny_tds/result.c +634 -0
  24. data/ext/tiny_tds/result.h +32 -0
  25. data/ext/tiny_tds/tiny_tds_ext.c +12 -0
  26. data/ext/tiny_tds/tiny_tds_ext.h +17 -0
  27. data/lib/tiny_tds/3.1/tiny_tds.so +0 -0
  28. data/lib/tiny_tds/3.2/tiny_tds.so +0 -0
  29. data/lib/tiny_tds/bin.rb +104 -0
  30. data/lib/tiny_tds/client.rb +136 -0
  31. data/lib/tiny_tds/error.rb +14 -0
  32. data/lib/tiny_tds/gem.rb +27 -0
  33. data/lib/tiny_tds/result.rb +7 -0
  34. data/lib/tiny_tds/version.rb +3 -0
  35. data/lib/tiny_tds.rb +61 -0
  36. data/patches/freetds/1.00.27/0001-mingw_missing_inet_pton.diff +34 -0
  37. data/patches/freetds/1.00.27/0002-Don-t-use-MSYS2-file-libws2_32.diff +28 -0
  38. data/patches/libiconv/1.14/1-avoid-gets-error.patch +17 -0
  39. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/bsqldb.exe +0 -0
  40. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/datacopy.exe +0 -0
  41. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/defncopy.exe +0 -0
  42. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/freebcp.exe +0 -0
  43. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/libct-4.dll +0 -0
  44. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/libsybdb-5.dll +0 -0
  45. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/osql +388 -0
  46. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/tdspool.exe +0 -0
  47. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/tsql.exe +0 -0
  48. data/ports/x64-mingw-ucrt/freetds/1.1.24/lib/libct.dll.a +0 -0
  49. data/ports/x64-mingw-ucrt/freetds/1.1.24/lib/libct.la +41 -0
  50. data/ports/x64-mingw-ucrt/freetds/1.1.24/lib/libsybdb.dll.a +0 -0
  51. data/ports/x64-mingw-ucrt/freetds/1.1.24/lib/libsybdb.la +41 -0
  52. data/ports/x64-mingw-ucrt/libiconv/1.15/bin/iconv.exe +0 -0
  53. data/ports/x64-mingw-ucrt/libiconv/1.15/bin/libcharset-1.dll +0 -0
  54. data/ports/x64-mingw-ucrt/libiconv/1.15/bin/libiconv-2.dll +0 -0
  55. data/ports/x64-mingw-ucrt/libiconv/1.15/lib/charset.alias +4 -0
  56. data/ports/x64-mingw-ucrt/libiconv/1.15/lib/libcharset.dll.a +0 -0
  57. data/ports/x64-mingw-ucrt/libiconv/1.15/lib/libcharset.la +41 -0
  58. data/ports/x64-mingw-ucrt/libiconv/1.15/lib/libiconv.dll.a +0 -0
  59. data/ports/x64-mingw-ucrt/libiconv/1.15/lib/libiconv.la +41 -0
  60. data/ports/x64-mingw-ucrt/openssl/1.1.1s/bin/c_rehash +251 -0
  61. data/ports/x64-mingw-ucrt/openssl/1.1.1s/bin/libcrypto-1_1-x64.dll +0 -0
  62. data/ports/x64-mingw-ucrt/openssl/1.1.1s/bin/libssl-1_1-x64.dll +0 -0
  63. data/ports/x64-mingw-ucrt/openssl/1.1.1s/bin/openssl.exe +0 -0
  64. data/ports/x64-mingw-ucrt/openssl/1.1.1s/lib/libcrypto.a +0 -0
  65. data/ports/x64-mingw-ucrt/openssl/1.1.1s/lib/libcrypto.dll.a +0 -0
  66. data/ports/x64-mingw-ucrt/openssl/1.1.1s/lib/libssl.a +0 -0
  67. data/ports/x64-mingw-ucrt/openssl/1.1.1s/lib/libssl.dll.a +0 -0
  68. data/setup_cimgruby_dev.sh +25 -0
  69. data/start_dev.sh +21 -0
  70. data/tasks/native_gem.rake +23 -0
  71. data/tasks/package.rake +8 -0
  72. data/tasks/ports/freetds.rb +37 -0
  73. data/tasks/ports/libiconv.rb +26 -0
  74. data/tasks/ports/openssl.rb +62 -0
  75. data/tasks/ports/recipe.rb +64 -0
  76. data/tasks/ports.rake +108 -0
  77. data/tasks/test.rake +9 -0
  78. data/test/benchmark/query.rb +77 -0
  79. data/test/benchmark/query_odbc.rb +106 -0
  80. data/test/benchmark/query_tinytds.rb +126 -0
  81. data/test/bin/install-freetds.sh +20 -0
  82. data/test/bin/install-mssql.ps1 +31 -0
  83. data/test/bin/install-mssqltools.sh +9 -0
  84. data/test/bin/install-openssl.sh +18 -0
  85. data/test/bin/setup_tinytds_db.sh +7 -0
  86. data/test/bin/setup_volume_permissions.sh +10 -0
  87. data/test/client_test.rb +275 -0
  88. data/test/gem_test.rb +177 -0
  89. data/test/result_test.rb +814 -0
  90. data/test/schema/1px.gif +0 -0
  91. data/test/schema/sqlserver_2000.sql +140 -0
  92. data/test/schema/sqlserver_2005.sql +140 -0
  93. data/test/schema/sqlserver_2008.sql +140 -0
  94. data/test/schema/sqlserver_2014.sql +140 -0
  95. data/test/schema/sqlserver_2016.sql +140 -0
  96. data/test/schema/sqlserver_azure.sql +140 -0
  97. data/test/schema/sybase_ase.sql +138 -0
  98. data/test/schema_test.rb +443 -0
  99. data/test/sql/db-create.sql +18 -0
  100. data/test/sql/db-login.sql +38 -0
  101. data/test/test_helper.rb +280 -0
  102. data/test/thread_test.rb +98 -0
  103. data/tiny_tds.gemspec +31 -0
  104. metadata +267 -0
@@ -0,0 +1,251 @@
1
+ #!/usr/bin/env perl
2
+
3
+ # WARNING: do not edit!
4
+ # Generated by Makefile from tools/c_rehash.in
5
+ # Copyright 1999-2022 The OpenSSL Project Authors. All Rights Reserved.
6
+ #
7
+ # Licensed under the OpenSSL license (the "License"). You may not use
8
+ # this file except in compliance with the License. You can obtain a copy
9
+ # in the file LICENSE in the source distribution or at
10
+ # https://www.openssl.org/source/license.html
11
+
12
+ # Perl c_rehash script, scan all files in a directory
13
+ # and add symbolic links to their hash values.
14
+
15
+ my $dir = "/root/project/ports/x64-mingw-ucrt/openssl/1.1.1s";
16
+ my $prefix = "/root/project/ports/x64-mingw-ucrt/openssl/1.1.1s";
17
+
18
+ my $errorcount = 0;
19
+ my $openssl = $ENV{OPENSSL} || "openssl";
20
+ my $pwd;
21
+ my $x509hash = "-subject_hash";
22
+ my $crlhash = "-hash";
23
+ my $verbose = 0;
24
+ my $symlink_exists=eval {symlink("",""); 1};
25
+ my $removelinks = 1;
26
+
27
+ ## Parse flags.
28
+ while ( $ARGV[0] =~ /^-/ ) {
29
+ my $flag = shift @ARGV;
30
+ last if ( $flag eq '--');
31
+ if ( $flag eq '-old') {
32
+ $x509hash = "-subject_hash_old";
33
+ $crlhash = "-hash_old";
34
+ } elsif ( $flag eq '-h' || $flag eq '-help' ) {
35
+ help();
36
+ } elsif ( $flag eq '-n' ) {
37
+ $removelinks = 0;
38
+ } elsif ( $flag eq '-v' ) {
39
+ $verbose++;
40
+ }
41
+ else {
42
+ print STDERR "Usage error; try -h.\n";
43
+ exit 1;
44
+ }
45
+ }
46
+
47
+ sub help {
48
+ print "Usage: c_rehash [-old] [-h] [-help] [-v] [dirs...]\n";
49
+ print " -old use old-style digest\n";
50
+ print " -h or -help print this help text\n";
51
+ print " -v print files removed and linked\n";
52
+ exit 0;
53
+ }
54
+
55
+ eval "require Cwd";
56
+ if (defined(&Cwd::getcwd)) {
57
+ $pwd=Cwd::getcwd();
58
+ } else {
59
+ $pwd=`pwd`;
60
+ chomp($pwd);
61
+ }
62
+
63
+ # DOS/Win32 or Unix delimiter? Prefix our installdir, then search.
64
+ my $path_delim = ($pwd =~ /^[a-z]\:/i) ? ';' : ':';
65
+ $ENV{PATH} = "$prefix/bin" . ($ENV{PATH} ? $path_delim . $ENV{PATH} : "");
66
+
67
+ if (! -x $openssl) {
68
+ my $found = 0;
69
+ foreach (split /$path_delim/, $ENV{PATH}) {
70
+ if (-x "$_/$openssl") {
71
+ $found = 1;
72
+ $openssl = "$_/$openssl";
73
+ last;
74
+ }
75
+ }
76
+ if ($found == 0) {
77
+ print STDERR "c_rehash: rehashing skipped ('openssl' program not available)\n";
78
+ exit 0;
79
+ }
80
+ }
81
+
82
+ if (@ARGV) {
83
+ @dirlist = @ARGV;
84
+ } elsif ($ENV{SSL_CERT_DIR}) {
85
+ @dirlist = split /$path_delim/, $ENV{SSL_CERT_DIR};
86
+ } else {
87
+ $dirlist[0] = "$dir/certs";
88
+ }
89
+
90
+ if (-d $dirlist[0]) {
91
+ chdir $dirlist[0];
92
+ $openssl="$pwd/$openssl" if (!-x $openssl);
93
+ chdir $pwd;
94
+ }
95
+
96
+ foreach (@dirlist) {
97
+ if (-d $_ ) {
98
+ if ( -w $_) {
99
+ hash_dir($_);
100
+ } else {
101
+ print "Skipping $_, can't write\n";
102
+ $errorcount++;
103
+ }
104
+ }
105
+ }
106
+ exit($errorcount);
107
+
108
+ sub copy_file {
109
+ my ($src_fname, $dst_fname) = @_;
110
+
111
+ if (open(my $in, "<", $src_fname)) {
112
+ if (open(my $out, ">", $dst_fname)) {
113
+ print $out $_ while (<$in>);
114
+ close $out;
115
+ } else {
116
+ warn "Cannot open $dst_fname for write, $!";
117
+ }
118
+ close $in;
119
+ } else {
120
+ warn "Cannot open $src_fname for read, $!";
121
+ }
122
+ }
123
+
124
+ sub hash_dir {
125
+ my $dir = shift;
126
+ my %hashlist;
127
+
128
+ print "Doing $dir\n";
129
+
130
+ if (!chdir $dir) {
131
+ print STDERR "WARNING: Cannot chdir to '$dir', $!\n";
132
+ return;
133
+ }
134
+
135
+ opendir(DIR, ".") || print STDERR "WARNING: Cannot opendir '.', $!\n";
136
+ my @flist = sort readdir(DIR);
137
+ closedir DIR;
138
+ if ( $removelinks ) {
139
+ # Delete any existing symbolic links
140
+ foreach (grep {/^[\da-f]+\.r{0,1}\d+$/} @flist) {
141
+ if (-l $_) {
142
+ print "unlink $_\n" if $verbose;
143
+ unlink $_ || warn "Can't unlink $_, $!\n";
144
+ }
145
+ }
146
+ }
147
+ FILE: foreach $fname (grep {/\.(pem)|(crt)|(cer)|(crl)$/} @flist) {
148
+ # Check to see if certificates and/or CRLs present.
149
+ my ($cert, $crl) = check_file($fname);
150
+ if (!$cert && !$crl) {
151
+ print STDERR "WARNING: $fname does not contain a certificate or CRL: skipping\n";
152
+ next;
153
+ }
154
+ link_hash_cert($fname) if ($cert);
155
+ link_hash_crl($fname) if ($crl);
156
+ }
157
+
158
+ chdir $pwd;
159
+ }
160
+
161
+ sub check_file {
162
+ my ($is_cert, $is_crl) = (0,0);
163
+ my $fname = $_[0];
164
+
165
+ open(my $in, "<", $fname);
166
+ while(<$in>) {
167
+ if (/^-----BEGIN (.*)-----/) {
168
+ my $hdr = $1;
169
+ if ($hdr =~ /^(X509 |TRUSTED |)CERTIFICATE$/) {
170
+ $is_cert = 1;
171
+ last if ($is_crl);
172
+ } elsif ($hdr eq "X509 CRL") {
173
+ $is_crl = 1;
174
+ last if ($is_cert);
175
+ }
176
+ }
177
+ }
178
+ close $in;
179
+ return ($is_cert, $is_crl);
180
+ }
181
+
182
+ sub compute_hash {
183
+ my $fh;
184
+ if ( $^O eq "VMS" ) {
185
+ # VMS uses the open through shell
186
+ # The file names are safe there and list form is unsupported
187
+ if (!open($fh, "-|", join(' ', @_))) {
188
+ print STDERR "Cannot compute hash on '$fname'\n";
189
+ return;
190
+ }
191
+ } else {
192
+ if (!open($fh, "-|", @_)) {
193
+ print STDERR "Cannot compute hash on '$fname'\n";
194
+ return;
195
+ }
196
+ }
197
+ return (<$fh>, <$fh>);
198
+ }
199
+
200
+ # Link a certificate to its subject name hash value, each hash is of
201
+ # the form <hash>.<n> where n is an integer. If the hash value already exists
202
+ # then we need to up the value of n, unless its a duplicate in which
203
+ # case we skip the link. We check for duplicates by comparing the
204
+ # certificate fingerprints
205
+
206
+ sub link_hash_cert {
207
+ link_hash($_[0], 'cert');
208
+ }
209
+
210
+ # Same as above except for a CRL. CRL links are of the form <hash>.r<n>
211
+
212
+ sub link_hash_crl {
213
+ link_hash($_[0], 'crl');
214
+ }
215
+
216
+ sub link_hash {
217
+ my ($fname, $type) = @_;
218
+ my $is_cert = $type eq 'cert';
219
+
220
+ my ($hash, $fprint) = compute_hash($openssl,
221
+ $is_cert ? "x509" : "crl",
222
+ $is_cert ? $x509hash : $crlhash,
223
+ "-fingerprint", "-noout",
224
+ "-in", $fname);
225
+ chomp $hash;
226
+ chomp $fprint;
227
+ return if !$hash;
228
+ $fprint =~ s/^.*=//;
229
+ $fprint =~ tr/://d;
230
+ my $suffix = 0;
231
+ # Search for an unused hash filename
232
+ my $crlmark = $is_cert ? "" : "r";
233
+ while(exists $hashlist{"$hash.$crlmark$suffix"}) {
234
+ # Hash matches: if fingerprint matches its a duplicate cert
235
+ if ($hashlist{"$hash.$crlmark$suffix"} eq $fprint) {
236
+ my $what = $is_cert ? 'certificate' : 'CRL';
237
+ print STDERR "WARNING: Skipping duplicate $what $fname\n";
238
+ return;
239
+ }
240
+ $suffix++;
241
+ }
242
+ $hash .= ".$crlmark$suffix";
243
+ if ($symlink_exists) {
244
+ print "link $fname -> $hash\n" if $verbose;
245
+ symlink $fname, $hash || warn "Can't symlink, $!";
246
+ } else {
247
+ print "copy $fname -> $hash\n" if $verbose;
248
+ copy_file($fname, $hash);
249
+ }
250
+ $hashlist{$hash} = $fprint;
251
+ }
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -x
4
+ set -e
5
+
6
+ # this should mirror the steps outlined in the circleci yml
7
+ echo "Installing mssql-tools..."
8
+ sleep 5
9
+ sudo -E ./test/bin/install-mssqltools.sh
10
+
11
+ echo "Configurating tinytds test database..."
12
+ sleep 5
13
+ ./test/bin/setup_tinytds_db.sh
14
+
15
+ echo "Building openssl library..."
16
+ sleep 5
17
+ sudo -E ./test/bin/install-openssl.sh
18
+
19
+ echo "Building freetds library..."
20
+ sleep 5
21
+ sudo -E ./test/bin/install-freetds.sh
22
+
23
+ echo "Installing gems..."
24
+ sleep 5
25
+ bundle install
data/start_dev.sh ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -x
4
+ set -e
5
+
6
+ # set volume read/write permissions to work both outside and inside container
7
+ sudo ./test/bin/setup_volume_permissions.sh
8
+
9
+ docker-compose up -d
10
+ echo "Waiting for containers to start..."
11
+ sleep 10
12
+
13
+ # setup circleci ruby container for development
14
+ docker exec cimg_ruby bash -c './setup_cimgruby_dev.sh'
15
+
16
+ # enter container
17
+ set +x
18
+ echo "cimg/ruby container is ready for tiny_tds development.........."
19
+ echo "To enter container run: docker exec -it cimg_ruby /bin/bash"
20
+ echo "To build solution run: docker exec cimg_ruby bash -c 'bundle exec rake build'"
21
+ echo "To test solution run: docker exec cimg_ruby bash -c 'bundle exec rake test'"
@@ -0,0 +1,23 @@
1
+ # encoding: UTF-8
2
+
3
+ desc 'Build the native binary gems using rake-compiler-dock'
4
+ task 'gem:native' => ['ports:cross'] do
5
+ require 'rake_compiler_dock'
6
+
7
+ # make sure to install our bundle
8
+ sh "bundle package --all" # Avoid repeated downloads of gems by using gem files from the host.
9
+
10
+ GEM_PLATFORM_HOSTS.each do |plat, meta|
11
+ RakeCompilerDock.sh "bundle --local && RUBY_CC_VERSION=#{meta[:ruby_versions]} rake native:#{plat} gem", platform: plat
12
+ end
13
+ end
14
+
15
+ # assumes you are in a container provided by Rake compiler
16
+ # if not, use the task above
17
+ task 'gem:for_platform', [:gem_platform] do |_task, args|
18
+ args.with_defaults(gem_platform: RbConfig::CONFIG["arch"])
19
+
20
+ sh "bundle install"
21
+ Rake::Task["ports:compile"].invoke(GEM_PLATFORM_HOSTS[args.gem_platform][:host], args.gem_platform)
22
+ sh "RUBY_CC_VERSION=#{GEM_PLATFORM_HOSTS[args.gem_platform][:ruby_versions]} rake native:#{args.gem_platform} gem"
23
+ end
@@ -0,0 +1,8 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems/package_task'
3
+
4
+ Gem::PackageTask.new(SPEC) do |pkg|
5
+ pkg.need_tar = false
6
+ pkg.need_zip = false
7
+ end
8
+
@@ -0,0 +1,37 @@
1
+ require_relative './recipe'
2
+
3
+ module Ports
4
+ class Freetds < Recipe
5
+ def initialize(version)
6
+ super('freetds', version)
7
+
8
+ set_patches
9
+ end
10
+
11
+ private
12
+
13
+ def configure_defaults
14
+ opts = super
15
+
16
+ opts << '--with-pic'
17
+ opts << '--disable-odbc'
18
+
19
+ if version =~ /0\.91/
20
+ opts << '--with-tdsver=7.1'
21
+ else
22
+ opts << '--with-tdsver=7.3'
23
+ end
24
+
25
+ if windows?
26
+ opts << '--sysconfdir=C:/Sites'
27
+ opts << '--enable-sspi'
28
+ end
29
+
30
+ opts
31
+ end
32
+
33
+ def set_patches
34
+ self.patch_files.concat get_patches(name, version)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ require_relative './recipe'
2
+
3
+ module Ports
4
+ class Libiconv < Recipe
5
+ def initialize(version)
6
+ super('libiconv', version)
7
+
8
+ set_patches
9
+ end
10
+
11
+ private
12
+
13
+ def configure_defaults
14
+ [
15
+ "--host=#{@host}",
16
+ '--disable-static',
17
+ '--enable-shared',
18
+ 'CFLAGS=-fPIC -O2'
19
+ ]
20
+ end
21
+
22
+ def set_patches
23
+ self.patch_files.concat get_patches(name, version)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,62 @@
1
+ require_relative './recipe'
2
+
3
+ module Ports
4
+ class Openssl < Recipe
5
+ def initialize(version)
6
+ super('openssl', version)
7
+
8
+ set_patches
9
+ end
10
+
11
+ def configure
12
+ return if configured?
13
+
14
+ md5_file = File.join(tmp_path, 'configure.md5')
15
+ digest = Digest::MD5.hexdigest(computed_options.to_s)
16
+ File.open(md5_file, "w") { |f| f.write digest }
17
+
18
+ # Windows doesn't recognize the shebang so always explicitly use sh
19
+ execute('configure', "sh -c \"./Configure #{computed_options.join(' ')}\"")
20
+ end
21
+
22
+ def install
23
+ unless installed?
24
+ execute('install', %Q(#{make_cmd} install_sw install_ssldirs))
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def configure_defaults
31
+ opts = [
32
+ 'shared',
33
+ target_arch,
34
+ "--openssldir=#{path}",
35
+ ]
36
+
37
+ if cross_build?
38
+ opts << "--cross-compile-prefix=#{host}-"
39
+ end
40
+
41
+ opts
42
+ end
43
+
44
+ def target_arch
45
+ if windows?
46
+ arch = ''
47
+ arch = '64' if host=~ /x86_64/
48
+
49
+ "mingw#{arch}"
50
+ else
51
+ arch = 'x32'
52
+ arch = 'x86_64' if host=~ /x86_64/
53
+
54
+ "linux-#{arch}"
55
+ end
56
+ end
57
+
58
+ def set_patches
59
+ self.patch_files.concat get_patches(name, version)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,64 @@
1
+ # encoding: UTF-8
2
+ require 'mini_portile2'
3
+ require 'fileutils'
4
+ require 'rbconfig'
5
+
6
+ module Ports
7
+ class Recipe < MiniPortile
8
+ attr_writer :gem_platform
9
+
10
+ def cook
11
+ checkpoint = "ports/checkpoints/#{name}-#{version}-#{gem_platform}.installed"
12
+
13
+ unless File.exist? checkpoint
14
+ super
15
+ FileUtils.mkdir_p("ports/checkpoints")
16
+ FileUtils.touch checkpoint
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :gem_platform
23
+
24
+ def port_path
25
+ "#{@target}/#{gem_platform}/#{@name}/#{@version}"
26
+ end
27
+
28
+ def tmp_path
29
+ "tmp/#{gem_platform}/ports/#{@name}/#{@version}"
30
+ end
31
+
32
+ def configure_defaults
33
+ [
34
+ "--host=#{@host}",
35
+ '--disable-static',
36
+ '--enable-shared'
37
+ ]
38
+ end
39
+
40
+ def windows?
41
+ host =~ /mswin|mingw32/
42
+ end
43
+
44
+ def system_host
45
+ RbConfig::CONFIG['host']
46
+ end
47
+
48
+ def cross_build?
49
+ host != system_host
50
+ end
51
+
52
+ def get_patches(libname, version)
53
+ patches = []
54
+
55
+ patch_path = File.expand_path(
56
+ File.join('..','..','..','patches',libname,version),
57
+ __FILE__
58
+ )
59
+
60
+ patches.concat(Dir[File.join(patch_path, '*.patch')].sort)
61
+ patches.concat(Dir[File.join(patch_path, '*.diff')].sort)
62
+ end
63
+ end
64
+ end
data/tasks/ports.rake ADDED
@@ -0,0 +1,108 @@
1
+ # encoding: UTF-8
2
+ require 'mini_portile2'
3
+ require 'fileutils'
4
+ require_relative 'ports/libiconv'
5
+ require_relative 'ports/openssl'
6
+ require_relative 'ports/freetds'
7
+ require_relative '../ext/tiny_tds/extconsts'
8
+
9
+ namespace :ports do
10
+ libraries_to_compile = {
11
+ openssl: Ports::Openssl.new(OPENSSL_VERSION),
12
+ libiconv: Ports::Libiconv.new(ICONV_VERSION),
13
+ freetds: Ports::Freetds.new(FREETDS_VERSION)
14
+ }
15
+
16
+ directory "ports"
17
+ CLEAN.include "ports/*mingw*"
18
+ CLEAN.include "ports/*.installed"
19
+
20
+ task :openssl, [:host, :gem_platform] do |_task, args|
21
+ args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
22
+
23
+ libraries_to_compile[:openssl].files = [OPENSSL_SOURCE_URI]
24
+ libraries_to_compile[:openssl].host = args.host
25
+ libraries_to_compile[:openssl].gem_platform = args.gem_platform
26
+
27
+ libraries_to_compile[:openssl].cook
28
+ libraries_to_compile[:openssl].activate
29
+ end
30
+
31
+ task :libiconv, [:host, :gem_platform] do |_task, args|
32
+ args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
33
+
34
+ libraries_to_compile[:libiconv].files = [ICONV_SOURCE_URI]
35
+ libraries_to_compile[:libiconv].host = args.host
36
+ libraries_to_compile[:libiconv].gem_platform = args.gem_platform
37
+ libraries_to_compile[:libiconv].cook
38
+ libraries_to_compile[:libiconv].activate
39
+ end
40
+
41
+ task :freetds, [:host, :gem_platform] do |_task, args|
42
+ args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
43
+
44
+ libraries_to_compile[:freetds].files = [FREETDS_SOURCE_URI]
45
+ libraries_to_compile[:freetds].host = args.host
46
+ libraries_to_compile[:freetds].gem_platform = args.gem_platform
47
+
48
+ if libraries_to_compile[:openssl]
49
+ # freetds doesn't have an option that will provide an rpath
50
+ # so we do it manually
51
+ ENV['OPENSSL_CFLAGS'] = "-Wl,-rpath -Wl,#{libraries_to_compile[:openssl].path}/lib"
52
+ # Add the pkgconfig file with MSYS2'ish path, to prefer our ports build
53
+ # over MSYS2 system OpenSSL.
54
+ ENV['PKG_CONFIG_PATH'] = "#{libraries_to_compile[:openssl].path.gsub(/^(\w):/i) { "/" + $1.downcase }}/lib/pkgconfig:#{ENV['PKG_CONFIG_PATH']}"
55
+ libraries_to_compile[:freetds].configure_options << "--with-openssl=#{libraries_to_compile[:openssl].path}"
56
+ end
57
+
58
+ if libraries_to_compile[:libiconv]
59
+ libraries_to_compile[:freetds].configure_options << "--with-libiconv-prefix=#{libraries_to_compile[:libiconv].path}"
60
+ end
61
+
62
+ libraries_to_compile[:freetds].cook
63
+ libraries_to_compile[:freetds].activate
64
+ end
65
+
66
+ task :compile, [:host, :gem_platform] do |_task, args|
67
+ args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
68
+
69
+ puts "Compiling ports for #{args.host} (Ruby platform #{args.gem_platform}) ..."
70
+
71
+ libraries_to_compile.keys.each do |lib|
72
+ Rake::Task["ports:#{lib}"].invoke(args.host, args.gem_platform)
73
+ end
74
+ end
75
+
76
+ desc 'Build the ports windows binaries via rake-compiler-dock'
77
+ task 'cross' do
78
+ require 'rake_compiler_dock'
79
+
80
+ # build the ports for all our cross compile hosts
81
+ GEM_PLATFORM_HOSTS.each do |gem_platform, meta|
82
+ # make sure to install our bundle
83
+ build = ['bundle']
84
+ build << "RUBY_CC_VERSION=#{meta[:ruby_versions]} rake ports:compile[#{meta[:host]},#{gem_platform}] MAKE='make -j`nproc`'"
85
+ RakeCompilerDock.sh build.join(' && '), platform: gem_platform
86
+ end
87
+ end
88
+
89
+ desc "Notes the actual versions for the compiled ports into a file"
90
+ task "version_file", [:gem_platform] do |_task, args|
91
+ args.with_defaults(gem_platform: RbConfig::CONFIG["arch"])
92
+
93
+ ports_version = {}
94
+
95
+ libraries_to_compile.each do |library, library_recipe|
96
+ ports_version[library] = library_recipe.version
97
+ end
98
+
99
+ ports_version[:platform] = args.gem_platform
100
+
101
+ File.open(".ports_versions", "w") do |f|
102
+ f.write ports_version
103
+ end
104
+ end
105
+ end
106
+
107
+ desc 'Build ports and activate libraries for the current architecture.'
108
+ task :ports => ['ports:compile']
data/tasks/test.rake ADDED
@@ -0,0 +1,9 @@
1
+ # encoding: UTF-8
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/**/*_test.rb']
7
+ t.verbose = true
8
+ end
9
+