Skip to content

Commit 2f894f4

Browse files
committed
Update the cross-compile task
1 parent e489942 commit 2f894f4

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

tasks/compile.rake

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,31 @@ def gemspec
55
end
66

77
Rake::ExtensionTask.new("mysql2", gemspec) do |ext|
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}" ]
8+
# put binaries into lib/mysql2/ or lib/mysql2/x.y/
9+
ext.lib_dir = File.join 'lib', 'mysql2'
10+
11+
# clean compiled extension
12+
CLEAN.include "#{ext.lib_dir}/*.#{RbConfig::CONFIG['DLEXT']}"
1113

12-
# automatically add build options to avoid need of manual input
1314
if RUBY_PLATFORM =~ /mswin|mingw/ then
14-
ext.config_options = windows_options
15+
Rake::Task['vendor:mysql'].invoke
16+
# Expand the path because the build dir is 3-4 levels deep in tmp/platform/version/
17+
connector_dir = File.expand_path("../../vendor/#{CONNECTOR_DIR}", __FILE__)
18+
ext.config_options = [ "--with-mysql-dir=#{connector_dir}" ]
1519
else
1620
ext.cross_compile = true
17-
ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60']
18-
ext.cross_config_options = windows_options
21+
ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60', 'x64-mingw32']
22+
ext.cross_config_options = {
23+
'x86-mingw32' => [ "--with-mysql-dir=" + File.expand_path("../../vendor/mysql-connector-c-#{CONNECTOR_VERSION}-win32", __FILE__) ],
24+
'x86-mswin32-60' => [ "--with-mysql-dir=" + File.expand_path("../../vendor/mysql-connector-c-#{CONNECTOR_VERSION}-win32", __FILE__) ],
25+
'x64-mingw32' => [ "--with-mysql-dir=" + File.expand_path("../../vendor/mysql-connector-c-#{CONNECTOR_VERSION}-winx64", __FILE__) ],
26+
}
1927

20-
# inject 1.8/1.9 pure-ruby entry point when cross compiling only
2128
ext.cross_compiling do |spec|
29+
Rake::Task['lib/mysql2/mysql2.rb'].invoke
30+
Rake::Task['vendor:mysql'].invoke(spec.platform)
2231
spec.files << 'lib/mysql2/mysql2.rb'
32+
spec.files << 'vendor/libmysql.dll'
2333
spec.post_install_message = <<-POST_INSTALL_MESSAGE
2434
2535
======================================================================================================
@@ -28,7 +38,7 @@ Rake::ExtensionTask.new("mysql2", gemspec) do |ext|
2838
It was built using MySQL Connector/C version #{CONNECTOR_VERSION}.
2939
It's recommended to use the exact same version to avoid potential issues.
3040
31-
At the time of building this gem, the necessary DLL files where available
41+
At the time of building this gem, the necessary DLL files were available
3242
in the following download:
3343
3444
http://dev.mysql.com/get/Downloads/Connector-C/#{CONNECTOR_ZIP}/from/pick
@@ -40,11 +50,6 @@ Rake::ExtensionTask.new("mysql2", gemspec) do |ext|
4050
POST_INSTALL_MESSAGE
4151
end
4252
end
43-
44-
ext.lib_dir = File.join 'lib', 'mysql2'
45-
46-
# clean compiled extension
47-
CLEAN.include "#{ext.lib_dir}/*.#{RbConfig::CONFIG['DLEXT']}"
4853
end
4954
Rake::Task[:spec].prerequisites << :compile
5055

@@ -58,10 +63,6 @@ require "#{name}/\#{$1}/#{name}"
5863
end
5964
end
6065

61-
if Rake::Task.task_defined?(:cross)
62-
Rake::Task[:cross].prerequisites << "lib/mysql2/mysql2.rb"
63-
end
64-
6566
# DevKit task following the example of Luis Lavena's test-ruby-c-extension
6667
task :devkit do
6768
begin
@@ -74,8 +75,4 @@ end
7475
if RUBY_PLATFORM =~ /mingw|mswin/ then
7576
Rake::Task['compile'].prerequisites.unshift 'vendor:mysql'
7677
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
8178
end

0 commit comments

Comments
 (0)