Skip to content

Commit 6e78d13

Browse files
committed
Remove MiniPortile from extension build
The extension build currently downloads and installs sources for libiconv, openssl, and freetds regardless of architecture. This is at odds with the correct procedure of installing these sources via the OS package manager for the non-binary gem build. This commit begins to solve this problem in a few ways: 1. It moves the responsibiliy of managing the MiniPortile builds to a ports rake task 2. It removes all ports specific logic from the extension build save the ability to search the ports directories if they exist (to facilitate the binary gem) 3. It adds cross compilation targets for the ports rake tasks to assist in the creation of the binary gems. 4. It enhances the rake clobber list to include the ports directories. 5. It removes custom logic for ports directory names and moves back towards relying on the MiniPortile defaults as much as possible. Relates to issue #342
1 parent dd35533 commit 6e78d13

22 files changed

+678
-492
lines changed

.travis.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@ services:
44
- docker
55
env:
66
global:
7+
- PATH=/opt/local/bin:$PATH
78
- TESTOPTS="-v"
89
- TINYTDS_UNIT_HOST=localhost
910
rvm:
1011
- 2.1.9
1112
- 2.2.5
1213
- 2.3.1
1314
before_install:
14-
- export PATH=/opt/local/bin:$PATH
1515
- docker info
16-
- sudo ./test/bin/setup.sh
1716
- sudo ./test/bin/install-openssl.sh
18-
- openssl version
1917
- sudo ./test/bin/install-freetds.sh
20-
- tsql -C
18+
- sudo ./test/bin/setup.sh
2119
install:
22-
- export PATH=/opt/local/bin:$PATH
2320
- gem install bundler
2421
- bundle --version
2522
- bundle install

Gemfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ gemspec
33

44
group :development do
55
gem 'rake-compiler-dock', github: 'rake-compiler/rake-compiler-dock'
6-
gem 'byebug'
6+
end
7+
8+
group :test do
9+
gem 'minitest'
710
end

README.md

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ Installing with rubygems should just work. TinyTDS is currently tested on Ruby v
3434
$ gem install tiny_tds
3535
```
3636

37-
If you use Windows, we pre-compile TinyTDS with static versions of FreeTDS and supporting libraries. On all other platforms, we will find these dependencies. It is recommended that you install the latest FreeTDS via your method of choice. For example, here is how to install FreeTDS on Ubuntu. You might also need the `build-essential` and possibly the `libc6-dev` packages.
37+
If you use Windows, we pre-compile TinyTDS with static versions of FreeTDS and supporting libraries.
38+
If you're using RubyInstaller the binary gem will require that devkit is installed and in your path to operate properly.
39+
40+
On all other platforms, we will find these dependencies. It is recommended that you install the latest FreeTDS via your method of choice. For example, here is how to install FreeTDS on Ubuntu. You might also need the `build-essential` and possibly the `libc6-dev` packages.
3841

3942
```shell
4043
$ apt-get wget
@@ -52,20 +55,8 @@ $ make install
5255
If none exist, our native extension will use MiniPortile to install any missing dependencies listed above for your specific platform. These dependencies will be built and linked within the installed TinyTDS gem. Please read the MiniPortile and/or Windows sections at the end of this file for advanced configuration options past the following:
5356

5457
```
55-
--enable-system-freetds / --disable-system-freetds
56-
--enable-system-iconv / --disable-system-iconv
57-
--enable-system-openssl / --disable-system-openssl
58-
Force use of system or builtin freetds/iconv/openssl library.
59-
Default is to prefer system libraries and fallback to builtin.
60-
6158
--with-freetds-dir=DIR
6259
Use the freetds library placed under DIR.
63-
64-
--enable-lookup
65-
Search for freetds through all paths in the PATH environment variable.
66-
67-
--enable-cross-build
68-
Do cross-build.
6960
```
7061

7162

@@ -403,19 +394,6 @@ This is possible using FreeTDS version 0.95 or higher. You must use the `use_utf
403394
The default is true and since FreeTDS v1.0 would do this as well.
404395

405396

406-
## Using MiniPortile
407-
408-
MiniPortile is a minimalistic implementation of a port/recipe system. <https://github.com/luislavena/mini_portile>
409-
410-
The TinyTDS project uses MiniPortile so that we can easily install a local version of FreeTDS and supporting libraries to link against when building a test version of TinyTDS. This same system is also used when installing TinyTDS with Rubygems and building native extensions. It is possible to build TinyTDS with a specific version of FreeTDS using the `TINYTDS_FREETDS_VERSION` environment variable. Here are some exampbles of possible values.
411-
412-
```
413-
$ rake TDSVER='7.1' TINYTDS_FREETDS_VERSION='0.95' -- --disable-system-freetds --disable-system-iconv
414-
```
415-
416-
To find out more about the FreeTDS release system [visit this thread](http://lists.ibiblio.org/pipermail/freetds/2012q1/027756.html) on their mailing list. You can also browse thier FTP server [ftp://ftp.astron.com/pub/freetds/](ftp://ftp.astron.com/pub/freetds/) for version number strings.
417-
418-
419397
## Compiling Gems for Windows
420398

421399
For the convenience of Windows users, TinyTDS ships pre-compiled gems for Ruby 2.0, 2.1, 2.2, and 2.3 on Windows. In order to generate these gems, [rake-compiler-dock](https://github.com/rake-compiler/rake-compiler-dock) is used. This project provides a [Docker image](https://registry.hub.docker.com/u/larskanis/rake-compiler-dock/) with rvm, cross-compilers and a number of different target versions of Ruby.
@@ -463,7 +441,7 @@ CREATE USER [tinytds] FOR LOGIN [tinytds];
463441
EXEC sp_addrolemember N'db_owner', N'tinytds';
464442
```
465443

466-
From here you can now run the tests. This assumes you have both Ruby & the needed FreeTDS installed.
444+
From here you can build and run tests against an installed version of FreeTDS.
467445

468446
```shell
469447
$ bundle install
@@ -479,13 +457,6 @@ $ rake TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_SCHEMA=sqlserver_azure
479457
$ rake TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_UNIT_PORT=5000 TINYTDS_SCHEMA=sybase_ase
480458
```
481459

482-
If you do not want to use MiniPortile to compile a local project version of FreeTDS and instead use your local system version, use the `TINYTDS_SKIP_PORTS` environment variable. This will ignore any port tasks and will instead build and link to your system's FreeTDS installation as a normal gem install would.
483-
484-
```
485-
$ rake TINYTDS_SKIP_PORTS=1
486-
```
487-
488-
489460
## Help & Support
490461

491462
* Github Source: http://github.com/rails-sqlserver/tiny_tds

Rakefile

Lines changed: 26 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,50 @@
11
# encoding: UTF-8
2+
require 'rbconfig'
23
require 'rake'
34
require 'rake/clean'
4-
require 'rbconfig'
5-
require 'rake/testtask'
65
require 'rake/extensiontask'
7-
require 'rubygems/package_task'
86
require_relative './ext/tiny_tds/extconsts'
97

10-
def test_libs
11-
%w(lib test)
12-
end
13-
14-
def test_files
15-
if ENV['TEST_FILES']
16-
ENV['TEST_FILES'].split(',').map(&:strip).sort
17-
else
18-
Dir.glob('test/**/*_test.rb').sort
19-
end
20-
end
21-
22-
def add_file_to_gem(spec, relative_path)
23-
target_path = File.join gem_build_path(spec), relative_path
24-
target_dir = File.dirname(target_path)
25-
mkdir_p target_dir
26-
rm_f target_path
27-
safe_ln relative_path, target_path
28-
spec.files += [relative_path]
29-
end
30-
31-
def gem_build_path(spec)
32-
File.join 'pkg', spec.full_name
33-
end
34-
35-
gemspec = Gem::Specification.load(File.expand_path('../tiny_tds.gemspec', __FILE__))
36-
37-
Rake::TestTask.new do |t|
38-
t.libs = test_libs
39-
t.test_files = test_files
40-
t.verbose = true
41-
end
42-
43-
Gem::PackageTask.new(gemspec) do |pkg|
44-
pkg.need_tar = false
45-
pkg.need_zip = false
46-
end
47-
48-
task :compile
8+
SPEC = Gem::Specification.load(File.expand_path('../tiny_tds.gemspec', __FILE__))
9+
GEM_PLATFORM_HOSTS = {
10+
'x86-mingw32' => 'i686-w64-mingw32',
11+
'x64-mingw32' => 'x86_64-w64-mingw32'
12+
}
4913

50-
task build: [:clean, :compile]
51-
task(:build_quietly) { capture_stds { Rake::Task[:build].invoke } }
14+
# Add our project specific files to clean for a rebuild
15+
CLEAN.include FileList["{ext,lib}/**/*.{so,#{RbConfig::CONFIG['DLEXT']},o}"],
16+
FileList["exe/*"]
5217

53-
task default: [:build, :test]
18+
# Clobber all our temp files and ports files including .install files
19+
# and archives
20+
CLOBBER.include FileList["tmp/**/*"],
21+
FileList["ports/**/*"].exclude(%r{^ports/archives})
5422

5523
Dir['tasks/*.rake'].sort.each { |f| load f }
5624

57-
Rake::ExtensionTask.new('tiny_tds', gemspec) do |ext|
25+
Rake::ExtensionTask.new('tiny_tds', SPEC) do |ext|
5826
ext.lib_dir = 'lib/tiny_tds'
5927
ext.cross_compile = true
60-
ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
61-
ext.cross_config_options += %w(--disable-lookup --enable-cross-build)
28+
ext.cross_platform = GEM_PLATFORM_HOSTS.keys
29+
6230
# Add dependent DLLs to the cross gems
6331
ext.cross_compiling do |spec|
64-
platform_host_map = {
65-
'x86-mingw32' => 'i686-w64-mingw32',
66-
'x64-mingw32' => 'x86_64-w64-mingw32'
67-
}
32+
platform_host_map = GEM_PLATFORM_HOSTS
6833
gemplat = spec.platform.to_s
6934
host = platform_host_map[gemplat]
70-
dlls = [
71-
"libcrypto32-#{OPENSSL_VERSION}-#{host}.dll",
72-
"libssl32-#{OPENSSL_VERSION}-#{host}.dll",
73-
'libiconv-2.dll',
74-
'libsybdb-5.dll'
75-
]
35+
7636
# We don't need the sources in a fat binary gem
7737
spec.files = spec.files.reject { |f| f =~ %r{^ports\/archives/} }
78-
spec.files += dlls.map { |dll| "ports/#{host}/bin/#{File.basename(dll)}" }
38+
39+
# Make sure to include the ports binaries and libraries
40+
spec.files += FileList["ports/#{host}/**/**/{bin,lib}/*"].exclude do |f|
41+
File.directory? f
42+
end
43+
7944
spec.files += Dir.glob('exe/*')
8045
end
8146
end
8247

83-
# Bundle the freetds sources to avoid download while gem install.
84-
task gem_build_path(gemspec) do
85-
add_file_to_gem gemspec, "ports/archives/freetds-#{FREETDS_VERSION}.tar.bz2"
86-
end
87-
88-
desc 'Build the windows binary gems per rake-compiler-dock'
89-
task 'gem:windows' do
90-
require 'rake_compiler_dock'
91-
RakeCompilerDock.sh <<-EOT
92-
bundle && rake cross native gem RUBY_CC_VERSION=2.4.0:2.3.0:2.2.2:2.1.6:2.0.0 CFLAGS="-Wall"
93-
EOT
94-
end
48+
task build: [:clean, :compile]
49+
task default: [:build, :test]
9550

96-
def capture_stds
97-
pstdout = $stdout
98-
$stdout = StringIO.new
99-
pstderr = $stderr
100-
$stderr = StringIO.new
101-
yield
102-
$stdout.string
103-
$stderr.string
104-
ensure
105-
$stdout = pstdout
106-
$stderr = pstderr
107-
end

appveyor.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ skip_branch_with_pr: true
99
matrix:
1010
fast_finish: true
1111
install:
12+
# Output debugging info
1213
- ps: Update-AppveyorBuild -Version "$(Get-Content $env:appveyor_build_folder\VERSION).$env:appveyor_build_number"
1314
- perl --version
1415
- ruby --version
1516
- gem --version
17+
18+
# Set up project prerequisits
1619
- bundle install
17-
- bundle exec rake build
20+
- bundle exec rake ports
1821
build: off
1922
branches:
2023
except:
@@ -26,13 +29,13 @@ test_script:
2629
- ps: Start-Service 'MSSQL$SQL2014'
2730
- timeout /t 4 /nobreak > NUL
2831
- sqlcmd -S ".\SQL2014" -U sa -P Password12! -i %APPVEYOR_BUILD_FOLDER%\test\appveyor\dbsetup.sql
29-
- bundle exec rake TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2014" TINYTDS_SCHEMA=sqlserver_2014 TDSVER=7.1
30-
- bundle exec rake TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2014" TINYTDS_SCHEMA=sqlserver_2014
32+
- bundle exec rake ports build test TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2014" TINYTDS_SCHEMA=sqlserver_2014 TDSVER=7.1
33+
- bundle exec rake ports build test TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2014" TINYTDS_SCHEMA=sqlserver_2014
3134
- ps: Stop-Service 'MSSQL$SQL2014'
3235
- ps: Start-Service 'MSSQL$SQL2012SP1'
3336
- timeout /t 4 /nobreak > NUL
3437
- sqlcmd -S ".\SQL2012SP1" -U sa -P Password12! -i %APPVEYOR_BUILD_FOLDER%\test\appveyor\dbsetup.sql
35-
- bundle exec rake TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2012SP1" TINYTDS_SCHEMA=sqlserver_2014
38+
- bundle exec rake ports build test TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2012SP1" TINYTDS_SCHEMA=sqlserver_2014
3639
environment:
3740
CI_AZURE_HOST:
3841
secure: 8ydpYysZYKEBKvp6plKlYfepH98/zAuT27FFCaJ9Sss=

circle.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ machine:
1313

1414
dependencies:
1515
override:
16+
- sudo ./test/bin/install-openssl.sh
17+
- sudo ./test/bin/install-freetds.sh
1618
- rvm-exec 2.1.9 bundle install
1719
- rvm-exec 2.2.5 bundle install
1820
- rvm-exec 2.3.1 bundle install
19-
- sudo ./test/bin/install-openssl.sh
20-
- openssl version
21-
- sudo ./test/bin/install-freetds.sh
22-
- tsql -C
2321

2422
database:
2523
post:

0 commit comments

Comments
 (0)