Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Wrap vendor:mysql tasks with a platform argument
  • Loading branch information
sodabrew committed Jan 8, 2015
1 parent 0eade9f commit df58a81
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 32 deletions.
13 changes: 7 additions & 6 deletions tasks/compile.rake
Expand Up @@ -14,20 +14,21 @@ Rake::ExtensionTask.new("mysql2", gemspec) do |ext|
if RUBY_PLATFORM =~ /mswin|mingw/ then
Rake::Task['vendor:mysql'].invoke
# Expand the path because the build dir is 3-4 levels deep in tmp/platform/version/
connector_dir = File.expand_path("../../vendor/#{CONNECTOR_DIR}", __FILE__)
connector_dir = File.expand_path("../../vendor/#{vendor_mysql_dir}", __FILE__)
ext.config_options = [ "--with-mysql-dir=#{connector_dir}" ]
else
Rake::Task['vendor:mysql'].invoke('x86')
Rake::Task['vendor:mysql'].invoke('x64')
ext.cross_compile = true
ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60', 'x64-mingw32']
ext.cross_config_options = {
'x86-mingw32' => [ "--with-mysql-dir=" + File.expand_path("../../vendor/mysql-connector-c-#{CONNECTOR_VERSION}-win32", __FILE__) ],
'x86-mswin32-60' => [ "--with-mysql-dir=" + File.expand_path("../../vendor/mysql-connector-c-#{CONNECTOR_VERSION}-win32", __FILE__) ],
'x64-mingw32' => [ "--with-mysql-dir=" + File.expand_path("../../vendor/mysql-connector-c-#{CONNECTOR_VERSION}-winx64", __FILE__) ],
'x86-mingw32' => [ "--with-mysql-dir=" + File.expand_path("../../vendor/#{vendor_mysql_dir('x86')}", __FILE__) ],
'x86-mswin32-60' => [ "--with-mysql-dir=" + File.expand_path("../../vendor/#{vendor_mysql_dir('x86')}", __FILE__) ],
'x64-mingw32' => [ "--with-mysql-dir=" + File.expand_path("../../vendor/#{vendor_mysql_dir('x64')}", __FILE__) ],
}

ext.cross_compiling do |spec|
Rake::Task['lib/mysql2/mysql2.rb'].invoke
Rake::Task['vendor:mysql'].invoke(spec.platform)
spec.files << 'lib/mysql2/mysql2.rb'
spec.files << 'vendor/libmysql.dll'
spec.post_install_message = <<-POST_INSTALL_MESSAGE
Expand All @@ -41,7 +42,7 @@ Rake::ExtensionTask.new("mysql2", gemspec) do |ext|
At the time of building this gem, the necessary DLL files were available
in the following download:
http://dev.mysql.com/get/Downloads/Connector-C/#{CONNECTOR_ZIP}/from/pick
#{vendor_mysql_url(spec.platform)}
And put lib\\libmysql.dll file in your Ruby bin directory, for example C:\\Ruby\\bin
Expand Down
76 changes: 50 additions & 26 deletions tasks/vendor_mysql.rake
@@ -1,36 +1,60 @@
require 'rake/clean'
require 'rake/extensioncompiler'

CONNECTOR_VERSION = "6.1.5" #"mysql-connector-c-6.1.5-win32.zip"
CONNECTOR_PLATFORM = RUBY_PLATFORM =~ /x64/ ? "winx64" : "win32"
CONNECTOR_DIR = "mysql-connector-c-#{CONNECTOR_VERSION}-#{CONNECTOR_PLATFORM}"
CONNECTOR_ZIP = "mysql-connector-c-#{CONNECTOR_VERSION}-#{CONNECTOR_PLATFORM}.zip"

# download mysql library and headers
directory "vendor"

file "vendor/#{CONNECTOR_ZIP}" => ["vendor"] do |t|
url = "http://cdn.mysql.com/Downloads/Connector-C/#{CONNECTOR_ZIP}"
when_writing "downloading #{t.name}" do
cd File.dirname(t.name) do
sh "curl -C - -O #{url} || wget -c #{url}"
CONNECTOR_VERSION = "6.1.5" # NOTE: Track the upstream version from time to time

def vendor_mysql_platform(platform=nil)
platform ||= RUBY_PLATFORM
platform =~ /x64/ ? "winx64" : "win32"
end

def vendor_mysql_dir(*args)
"mysql-connector-c-#{CONNECTOR_VERSION}-#{vendor_mysql_platform(*args)}"
end

def vendor_mysql_zip(*args)
"#{vendor_mysql_dir(*args)}.zip"
end

def vendor_mysql_url(*args)
"http://cdn.mysql.com/Downloads/Connector-C/#{vendor_mysql_zip(*args)}"
end

# vendor:mysql
task "vendor:mysql", [:platform] do |t, args|
puts "vendor:mysql for #{vendor_mysql_dir(args[:platform])}"

# download mysql library and headers
directory "vendor"

file "vendor/#{vendor_mysql_zip(args[:platform])}" => ["vendor"] do |t|
url = vendor_mysql_url(args[:platform])
when_writing "downloading #{t.name}" do
cd "vendor" do
sh "curl", "-C", "-", "-O", url do |ok, res|
sh "wget", "-c", url if ! ok
end
end
end
end
end

file "vendor/#{CONNECTOR_DIR}/include/mysql.h" => ["vendor/#{CONNECTOR_ZIP}"] do |t|
full_file = File.expand_path(t.prerequisites.last)
when_writing "creating #{t.name}" do
cd "vendor" do
sh "unzip -uq #{full_file} #{CONNECTOR_DIR}/bin/** #{CONNECTOR_DIR}/include/** #{CONNECTOR_DIR}/lib/**"
file "vendor/#{vendor_mysql_dir(args[:platform])}/include/mysql.h" => ["vendor/#{vendor_mysql_zip(args[:platform])}"] do |t|
full_file = File.expand_path(t.prerequisites.last)
when_writing "creating #{t.name}" do
cd "vendor" do
sh "unzip", "-uq", full_file,
"#{vendor_mysql_dir(args[:platform])}/bin/**",
"#{vendor_mysql_dir(args[:platform])}/include/**",
"#{vendor_mysql_dir(args[:platform])}/lib/**"
end
# update file timestamp to avoid Rake perform this extraction again.
touch t.name
end
# update file timestamp to avoid Rake perform this extraction again.
touch t.name
end
end

# clobber expanded packages
CLOBBER.include("vendor/#{CONNECTOR_DIR}")
# clobber expanded packages
CLOBBER.include("vendor/#{vendor_mysql_dir(args[:platform])}")

# vendor:mysql
task 'vendor:mysql' => "vendor/#{CONNECTOR_DIR}/include/mysql.h"
Rake::Task["vendor/#{vendor_mysql_dir(args[:platform])}/include/mysql.h"].invoke
Rake::Task["vendor:mysql"].reenable # allow task to be invoked again (with another platform)
end

0 comments on commit df58a81

Please sign in to comment.