Skip to content

Commit

Permalink
Use MySQL Connector/C instead of MySQL binaries
Browse files Browse the repository at this point in the history
- It reduces the amount of time it takes to download the binaries
- It is independent on the MySQL version installed
- Add instructions for download of DLL
  • Loading branch information
luislavena committed Apr 2, 2011
1 parent 1eee4ec commit 7a14c42
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
28 changes: 23 additions & 5 deletions tasks/compile.rake
@@ -1,20 +1,20 @@
require "rake/extensiontask" require "rake/extensiontask"


MYSQL_VERSION = "5.1.51" CONNECTOR_VERSION = "6.0.2" #"mysql-connector-c-noinstall-6.0.2-win32.zip"
MYSQL_MIRROR = ENV['MYSQL_MIRROR'] || "http://mysql.he.net/" CONNECTOR_MIRROR = ENV['CONNECTOR_MIRROR'] || ENV['MYSQL_MIRROR'] || "http://mysql.he.net/"


def gemspec def gemspec
@clean_gemspec ||= eval(File.read(File.expand_path('../../mysql2.gemspec', __FILE__))) @clean_gemspec ||= eval(File.read(File.expand_path('../../mysql2.gemspec', __FILE__)))
end end


Rake::ExtensionTask.new("mysql2", gemspec) do |ext| Rake::ExtensionTask.new("mysql2", gemspec) do |ext|
# reference where the vendored MySQL got extracted # reference where the vendored MySQL got extracted
mysql_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', "mysql-#{MYSQL_VERSION}-win32")) connector_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', "mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32"))


# DRY options feed into compile or cross-compile process # DRY options feed into compile or cross-compile process
windows_options = [ windows_options = [
"--with-mysql-include=#{mysql_lib}/include", "--with-mysql-include=#{connector_lib}/include",
"--with-mysql-lib=#{mysql_lib}/lib/opt" "--with-mysql-lib=#{connector_lib}/lib"
] ]


# automatically add build options to avoid need of manual input # automatically add build options to avoid need of manual input
Expand All @@ -28,6 +28,24 @@ Rake::ExtensionTask.new("mysql2", gemspec) do |ext|
# inject 1.8/1.9 pure-ruby entry point when cross compiling only # inject 1.8/1.9 pure-ruby entry point when cross compiling only
ext.cross_compiling do |spec| ext.cross_compiling do |spec|
spec.files << 'lib/mysql2/mysql2.rb' spec.files << 'lib/mysql2/mysql2.rb'
spec.post_install_message = <<-POST_INSTALL_MESSAGE
======================================================================================================
You've installed the binary version of #{spec.name}.
It was built using MySQL Connector/C version #{CONNECTOR_VERSION}.
It's recommended to use the exact same version to avoid potential issues.
At the time of building this gem, the necessary DLL files where available
in the following download:
http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32.zip/from/pick
And put lib\\libmysql.dll file in your Ruby bin directory, for example C:\\Ruby\\bin
======================================================================================================
POST_INSTALL_MESSAGE
end end
end end


Expand Down
13 changes: 6 additions & 7 deletions tasks/vendor_mysql.rake
Expand Up @@ -4,32 +4,31 @@ require 'rake/extensioncompiler'
# download mysql library and headers # download mysql library and headers
directory "vendor" directory "vendor"


file "vendor/mysql-noinstall-#{MYSQL_VERSION}-win32.zip" => ['vendor'] do |t| file "vendor/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32.zip" => ["vendor"] do |t|
base_version = MYSQL_VERSION.gsub(/\.[0-9]+$/, '') url = "http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32.zip/from/#{CONNECTOR_MIRROR}/"
url = "http://dev.mysql.com/get/Downloads/MySQL-#{base_version}/#{File.basename(t.name)}/from/#{MYSQL_MIRROR}/"
when_writing "downloading #{t.name}" do when_writing "downloading #{t.name}" do
cd File.dirname(t.name) do cd File.dirname(t.name) do
sh "wget -c #{url} || curl -C - -O #{url}" sh "wget -c #{url} || curl -C - -O #{url}"
end end
end end
end end


file "vendor/mysql-#{MYSQL_VERSION}-win32/include/mysql.h" => ["vendor/mysql-noinstall-#{MYSQL_VERSION}-win32.zip"] do |t| file "vendor/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32/include/mysql.h" => ["vendor/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32.zip"] do |t|
full_file = File.expand_path(t.prerequisites.last) full_file = File.expand_path(t.prerequisites.last)
when_writing "creating #{t.name}" do when_writing "creating #{t.name}" do
cd "vendor" do cd "vendor" do
sh "unzip #{full_file} mysql-#{MYSQL_VERSION}-win32/bin/** mysql-#{MYSQL_VERSION}-win32/include/** mysql-#{MYSQL_VERSION}-win32/lib/**" 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/**"
end end
# update file timestamp to avoid Rake perform this extraction again. # update file timestamp to avoid Rake perform this extraction again.
touch t.name touch t.name
end end
end end


# clobber expanded packages # clobber expanded packages
CLOBBER.include("vendor/mysql-#{MYSQL_VERSION}-win32") CLOBBER.include("vendor/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32")


# vendor:mysql # vendor:mysql
task 'vendor:mysql' => ["vendor/mysql-#{MYSQL_VERSION}-win32/include/mysql.h"] task 'vendor:mysql' => ["vendor/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32/include/mysql.h"]


# hook into cross compilation vendored mysql dependency # hook into cross compilation vendored mysql dependency
if RUBY_PLATFORM =~ /mingw|mswin/ then if RUBY_PLATFORM =~ /mingw|mswin/ then
Expand Down

0 comments on commit 7a14c42

Please sign in to comment.