Skip to content

Commit 40b251f

Browse files
larskaniscoderjoe
authored andcommittedJul 29, 2017
Add compat with RubyInstaller-2.4.1
It adds gem metadata for automatic installation of the freetds package which is part of the official MSYS2/MINGW repository now. This makes installation of the tiny_tds source gem as easy as installation of the binary windows gem, but works for RubyInstaller-2.4+ only. The freetds MINGW package is maintained here: https://github.com/Alexpux/MINGW-packages/tree/master/mingw-w64-freetds The Appveyor tests still work with our ports build and doesn't test against the new freetds package, so far. This disables the perl hack for OpenSSL, when the perl version is recent enough. Otherwise mixing git's shell commands into the path breaks MSYS2 builds, as used by RubyInstaller-2.4. This also removes lib directories from DLL search path, because they don't contain any DLLs. The update of libiconv is required for compat with MSYS2. The patch file is derived from https://github.com/Alexpux/MINGW-packages/tree/master/mingw-w64-freetds
1 parent 01cfc40 commit 40b251f

File tree

10 files changed

+78
-21
lines changed

10 files changed

+78
-21
lines changed
 

‎Gemfile

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ source 'https://rubygems.org'
22
gemspec
33

44
group :development do
5-
gem 'rake-compiler-dock', github: 'rake-compiler/rake-compiler-dock'
65
end
76

87
group :test do

‎Rakefile

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Rake::ExtensionTask.new('tiny_tds', SPEC) do |ext|
2929

3030
# Add dependent DLLs to the cross gems
3131
ext.cross_compiling do |spec|
32+
# The fat binary gem doesn't depend on the freetds package, since it bundles the library.
33+
spec.metadata.delete('msys2_mingw_dependencies')
34+
3235
platform_host_map = GEM_PLATFORM_HOSTS
3336
gemplat = spec.platform.to_s
3437
host = platform_host_map[gemplat]

‎appveyor.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ init:
33
- SET PATH=C:\MinGW\msys\1.0\bin;%PATH%
44
- SET RAKEOPT=-rdevkit
55
- SET TESTOPTS='-v'
6+
- SET MAKE=make V=1
67
clone_depth: 5
78
skip_tags: true
89
skip_branch_with_pr: true
@@ -42,8 +43,8 @@ environment:
4243
TINYTDS_UNIT_AZURE_PASS:
4344
secure: fYKSKV4v+36OFQp2nZdX4DfUpgmy5cm0wuR73cgdmEk=
4445
matrix:
45-
- ruby_version: "23-x64"
46-
- ruby_version: "23"
46+
- ruby_version: "24-x64"
47+
- ruby_version: "24"
4748
- ruby_version: "22-x64"
4849
- ruby_version: "22"
4950
on_failure:

‎ext/tiny_tds/extconsts.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
ICONV_VERSION = ENV['TINYTDS_ICONV_VERSION'] || "1.14"
2+
ICONV_VERSION = ENV['TINYTDS_ICONV_VERSION'] || "1.15"
33
ICONV_SOURCE_URI = "http://ftp.gnu.org/pub/gnu/libiconv/libiconv-#{ICONV_VERSION}.tar.gz"
44

55
OPENSSL_VERSION = ENV['TINYTDS_OPENSSL_VERSION'] || '1.1.0e'

‎lib/tiny_tds.rb

+32-13
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,39 @@
1212
# Support multiple ruby versions, fat binaries under Windows.
1313
if RUBY_PLATFORM =~ /mingw|mswin/ && RUBY_VERSION =~ /(\d+.\d+)/
1414
ver = Regexp.last_match(1)
15-
# Set the PATH environment variable, so that the DLLs can be found.
16-
old_path = ENV['PATH']
17-
begin
18-
ENV['PATH'] = [
19-
TinyTds::Gem.ports_bin_paths,
20-
TinyTds::Gem.ports_lib_paths,
21-
old_path
22-
].flatten.join File::PATH_SEPARATOR
2315

24-
require "tiny_tds/#{ver}/tiny_tds"
25-
rescue LoadError
26-
require 'tiny_tds/tiny_tds'
27-
ensure
28-
ENV['PATH'] = old_path
16+
add_dll_path = proc do |path, &block|
17+
begin
18+
require 'ruby_installer/runtime'
19+
RubyInstaller::Runtime.add_dll_directory(path, &block)
20+
rescue LoadError
21+
old_path = ENV['PATH']
22+
ENV['PATH'] = "#{path};#{old_path}"
23+
begin
24+
block.call
25+
ensure
26+
ENV['PATH'] = old_path
27+
end
28+
end
29+
end
30+
31+
add_dll_paths = proc do |paths, &block|
32+
if path=paths.shift
33+
add_dll_path.call(path) do
34+
add_dll_paths.call(paths, &block)
35+
end
36+
else
37+
block.call
38+
end
39+
end
40+
41+
# Temporary add bin directories for DLL search, so that freetds DLLs can be found.
42+
add_dll_paths.call( TinyTds::Gem.ports_bin_paths ) do
43+
begin
44+
require "tiny_tds/#{ver}/tiny_tds"
45+
rescue LoadError
46+
require 'tiny_tds/tiny_tds'
47+
end
2948
end
3049
else
3150
# Load dependent shared libraries into the process, so that they are already present,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
From 56e8972f66c3e948e2ad6885595c58fd23dcdb37 Mon Sep 17 00:00:00 2001
2+
From: Lars Kanis <kanis@comcard.de>
3+
Date: Thu, 6 Jul 2017 17:09:40 +0200
4+
Subject: [PATCH] Don't use MSYS2 file libws2_32.a for MINGW build
5+
6+
This file is intended for MSYS2/cygwin builds and blocks OpenSSL
7+
detection of freetds on i686.
8+
---
9+
configure | 2 --
10+
configure.ac | 2 --
11+
2 files changed, 4 deletions(-)
12+
13+
diff --git a/configure b/configure
14+
index 9495a49..31eb01d 100644
15+
--- a/configure
16+
+++ b/configure
17+
@@ -15915,8 +15915,6 @@ case $host in
18+
tds_mingw=yes
19+
if test "$host_cpu" = "x86_64"; then
20+
LIBS="-lws2_32"
21+
- elif test -r /usr/lib/w32api/libws2_32.a; then
22+
- LIBS="-L/usr/lib/w32api -lws2_32"
23+
else
24+
LIBS="-lws2_32"
25+
fi
26+
--
27+
2.6.2.windows.1
28+

‎tasks/ports.rake

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ namespace :ports do
4343
# freetds doesn't have an option that will provide an rpath
4444
# so we do it manually
4545
ENV['OPENSSL_CFLAGS'] = "-Wl,-rpath -Wl,#{openssl.path}/lib"
46+
# Add the pkgconfig file with MSYS2'ish path, to prefer our ports build
47+
# over MSYS2 system OpenSSL.
48+
ENV['PKG_CONFIG_PATH'] = "#{openssl.path.gsub(/^(\w):/i){"/"+$1.downcase}}/lib/pkgconfig:#{ENV['PKG_CONFIG_PATH']}"
4649
freetds.configure_options << "--with-openssl=#{openssl.path}"
4750
end
4851

‎tasks/ports/freetds.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def configure_defaults
2323
end
2424

2525
if windows?
26-
opts << '--sysconfdir=C:\Sites'
26+
opts << '--sysconfdir=C:/Sites'
2727
opts << '--enable-sspi'
2828
end
2929

‎tasks/ports/openssl.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ def install
2828
private
2929

3030
def execute(action, command, options={})
31+
# OpenSSL Requires Perl >= 5.10, while the Ruby devkit uses MSYS1 with Perl 5.8.8.
32+
# To overcome this, prepend Git's usr/bin to the PATH.
33+
# It has MSYS2 with a recent version of perl.
3134
prev_path = ENV['PATH']
32-
if host =~ /mingw/
35+
if host =~ /mingw/ && IO.popen(["perl", "-e", "print($])"], &:read).to_f < 5.010
3336
git_perl = 'C:/Program Files/Git/usr/bin'
3437
if File.directory?(git_perl)
3538
ENV['PATH'] = "#{git_perl}#{File::PATH_SEPARATOR}#{ENV['PATH']}"

‎tiny_tds.gemspec

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ Gem::Specification.new do |s|
1919
s.extensions = ['ext/tiny_tds/extconf.rb']
2020
s.license = 'MIT'
2121
s.required_ruby_version = '>= 2.0.0'
22-
s.add_runtime_dependency 'mini_portile2', '~> 2.0'
22+
s.metadata['msys2_mingw_dependencies'] = 'freetds'
23+
s.add_development_dependency 'mini_portile2', '~> 2.0'
2324
s.add_development_dependency 'rake', '~> 10.4'
24-
s.add_development_dependency 'rake-compiler', '0.9.5'
25+
s.add_development_dependency 'rake-compiler', '~> 1.0'
2526
s.add_development_dependency 'rake-compiler-dock', '~> 0.6.0'
2627
s.add_development_dependency 'minitest', '~> 5.6'
2728
s.add_development_dependency 'connection_pool', '~> 2.2'

0 commit comments

Comments
 (0)
Please sign in to comment.