Skip to content

Commit 68c41a2

Browse files
committed
Update for MinGW-x64
1 parent d198e90 commit 68c41a2

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
require 'rake'
33

44
# Load custom tasks (careful attention to define tasks before prerequisites)
5+
load 'tasks/vendor_mysql.rake'
56
load 'tasks/rspec.rake'
67
load 'tasks/compile.rake'
78
load 'tasks/generate.rake'
89
load 'tasks/benchmarks.rake'
9-
load 'tasks/vendor_mysql.rake'
1010

1111
task :default => :spec

tasks/compile.rake

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
require "rake/extensiontask"
22

3-
CONNECTOR_VERSION = "6.0.2" #"mysql-connector-c-noinstall-6.0.2-win32.zip"
4-
CONNECTOR_MIRROR = ENV['CONNECTOR_MIRROR'] || ENV['MYSQL_MIRROR'] || "http://mysql.he.net/"
5-
63
def gemspec
74
@clean_gemspec ||= eval(File.read(File.expand_path('../../mysql2.gemspec', __FILE__)))
85
end
96

107
Rake::ExtensionTask.new("mysql2", gemspec) do |ext|
11-
# reference where the vendored MySQL got extracted
12-
connector_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', "mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32"))
13-
14-
# DRY options feed into compile or cross-compile process
15-
windows_options = [
16-
"--with-mysql-include=#{connector_lib}/include",
17-
"--with-mysql-lib=#{connector_lib}/lib"
18-
]
8+
# Expand the path because the build dir is 3-4 levels deep in tmp/platform/version/
9+
connector_dir = File.expand_path("../../vendor/#{CONNECTOR_DIR}", __FILE__)
10+
windows_options = [ "--with-mysql-dir=#{connector_dir}" ]
1911

2012
# automatically add build options to avoid need of manual input
2113
if RUBY_PLATFORM =~ /mswin|mingw/ then
@@ -39,7 +31,7 @@ Rake::ExtensionTask.new("mysql2", gemspec) do |ext|
3931
At the time of building this gem, the necessary DLL files where available
4032
in the following download:
4133
42-
http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32.zip/from/pick
34+
http://dev.mysql.com/get/Downloads/Connector-C/#{CONNECTOR_ZIP}/from/pick
4335
4436
And put lib\\libmysql.dll file in your Ruby bin directory, for example C:\\Ruby\\bin
4537
@@ -69,3 +61,21 @@ end
6961
if Rake::Task.task_defined?(:cross)
7062
Rake::Task[:cross].prerequisites << "lib/mysql2/mysql2.rb"
7163
end
64+
65+
# DevKit task following the example of Luis Lavena's test-ruby-c-extension
66+
task :devkit do
67+
begin
68+
require "devkit"
69+
rescue LoadError => e
70+
abort "Failed to activate RubyInstaller's DevKit required for compilation."
71+
end
72+
end
73+
74+
if RUBY_PLATFORM =~ /mingw|mswin/ then
75+
Rake::Task['compile'].prerequisites.unshift 'vendor:mysql'
76+
Rake::Task['compile'].prerequisites.unshift 'devkit'
77+
else
78+
if Rake::Task.tasks.map {|t| t.name }.include? 'cross'
79+
Rake::Task['cross'].prerequisites.unshift 'vendor:mysql'
80+
end
81+
end

tasks/vendor_mysql.rake

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,36 @@
11
require 'rake/clean'
22
require 'rake/extensioncompiler'
33

4+
CONNECTOR_VERSION = "6.1.5" #"mysql-connector-c-6.1.5-win32.zip"
5+
CONNECTOR_PLATFORM = RUBY_PLATFORM =~ /x64/ ? "winx64" : "win32"
6+
CONNECTOR_DIR = "mysql-connector-c-#{CONNECTOR_VERSION}-#{CONNECTOR_PLATFORM}"
7+
CONNECTOR_ZIP = "mysql-connector-c-#{CONNECTOR_VERSION}-#{CONNECTOR_PLATFORM}.zip"
8+
49
# download mysql library and headers
510
directory "vendor"
611

7-
file "vendor/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32.zip" => ["vendor"] do |t|
8-
url = "http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32.zip/from/#{CONNECTOR_MIRROR}/"
12+
file "vendor/#{CONNECTOR_ZIP}" => ["vendor"] do |t|
13+
url = "http://cdn.mysql.com/Downloads/Connector-C/#{CONNECTOR_ZIP}"
914
when_writing "downloading #{t.name}" do
1015
cd File.dirname(t.name) do
11-
sh "wget -c #{url} || curl -C - -O #{url}"
16+
sh "curl -C - -O #{url} || wget -c #{url}"
1217
end
1318
end
1419
end
1520

16-
file "vendor/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32/include/mysql.h" => ["vendor/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32.zip"] do |t|
21+
file "vendor/#{CONNECTOR_DIR}/include/mysql.h" => ["vendor/#{CONNECTOR_ZIP}"] do |t|
1722
full_file = File.expand_path(t.prerequisites.last)
1823
when_writing "creating #{t.name}" do
1924
cd "vendor" do
20-
sh "unzip #{full_file} mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32/bin/** mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32/include/** mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32/lib/**"
25+
sh "unzip #{full_file} #{CONNECTOR_DIR}/bin/** #{CONNECTOR_DIR}/include/** #{CONNECTOR_DIR}/lib/**"
2126
end
2227
# update file timestamp to avoid Rake perform this extraction again.
2328
touch t.name
2429
end
2530
end
2631

2732
# clobber expanded packages
28-
CLOBBER.include("vendor/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32")
33+
CLOBBER.include("vendor/#{CONNECTOR_DIR}")
2934

3035
# vendor:mysql
31-
task 'vendor:mysql' => ["vendor/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32/include/mysql.h"]
32-
33-
# hook into cross compilation vendored mysql dependency
34-
if RUBY_PLATFORM =~ /mingw|mswin/ then
35-
Rake::Task['compile'].prerequisites.unshift 'vendor:mysql'
36-
else
37-
if Rake::Task.tasks.map {|t| t.name }.include? 'cross'
38-
Rake::Task['cross'].prerequisites.unshift 'vendor:mysql'
39-
end
40-
end
36+
task 'vendor:mysql' => "vendor/#{CONNECTOR_DIR}/include/mysql.h"

0 commit comments

Comments
 (0)