Permalink
Browse files

Use MySQL Connector/C instead of MySQL binaries

- 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...
1 parent 1eee4ec commit 7a14c42b5aadb3a91e00d7ce0adecac9c1efcaf8 @luislavena luislavena committed Apr 2, 2011
Showing with 29 additions and 12 deletions.
  1. +23 −5 tasks/compile.rake
  2. +6 −7 tasks/vendor_mysql.rake
View
@@ -1,20 +1,20 @@
require "rake/extensiontask"
-MYSQL_VERSION = "5.1.51"
-MYSQL_MIRROR = ENV['MYSQL_MIRROR'] || "http://mysql.he.net/"
+CONNECTOR_VERSION = "6.0.2" #"mysql-connector-c-noinstall-6.0.2-win32.zip"
+CONNECTOR_MIRROR = ENV['CONNECTOR_MIRROR'] || ENV['MYSQL_MIRROR'] || "http://mysql.he.net/"
def gemspec
@clean_gemspec ||= eval(File.read(File.expand_path('../../mysql2.gemspec', __FILE__)))
end
Rake::ExtensionTask.new("mysql2", gemspec) do |ext|
# 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
windows_options = [
- "--with-mysql-include=#{mysql_lib}/include",
- "--with-mysql-lib=#{mysql_lib}/lib/opt"
+ "--with-mysql-include=#{connector_lib}/include",
+ "--with-mysql-lib=#{connector_lib}/lib"
]
# automatically add build options to avoid need of manual input
@@ -28,6 +28,24 @@ Rake::ExtensionTask.new("mysql2", gemspec) do |ext|
# inject 1.8/1.9 pure-ruby entry point when cross compiling only
ext.cross_compiling do |spec|
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
View
@@ -4,32 +4,31 @@ require 'rake/extensioncompiler'
# download mysql library and headers
directory "vendor"
-file "vendor/mysql-noinstall-#{MYSQL_VERSION}-win32.zip" => ['vendor'] do |t|
- base_version = MYSQL_VERSION.gsub(/\.[0-9]+$/, '')
- url = "http://dev.mysql.com/get/Downloads/MySQL-#{base_version}/#{File.basename(t.name)}/from/#{MYSQL_MIRROR}/"
+file "vendor/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32.zip" => ["vendor"] do |t|
+ url = "http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32.zip/from/#{CONNECTOR_MIRROR}/"
when_writing "downloading #{t.name}" do
cd File.dirname(t.name) do
sh "wget -c #{url} || curl -C - -O #{url}"
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)
when_writing "creating #{t.name}" 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
# update file timestamp to avoid Rake perform this extraction again.
touch t.name
end
end
# clobber expanded packages
-CLOBBER.include("vendor/mysql-#{MYSQL_VERSION}-win32")
+CLOBBER.include("vendor/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32")
# 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
if RUBY_PLATFORM =~ /mingw|mswin/ then

0 comments on commit 7a14c42

Please sign in to comment.