1
1
require "rake/extensiontask"
2
2
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
-
6
3
def gemspec
7
4
@clean_gemspec ||= eval ( File . read ( File . expand_path ( '../../mysql2.gemspec' , __FILE__ ) ) )
8
5
end
9
6
10
7
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 } " ]
19
11
20
12
# automatically add build options to avoid need of manual input
21
13
if RUBY_PLATFORM =~ /mswin|mingw/ then
@@ -39,7 +31,7 @@ Rake::ExtensionTask.new("mysql2", gemspec) do |ext|
39
31
At the time of building this gem, the necessary DLL files where available
40
32
in the following download:
41
33
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
43
35
44
36
And put lib\\ libmysql.dll file in your Ruby bin directory, for example C:\\ Ruby\\ bin
45
37
69
61
if Rake ::Task . task_defined? ( :cross )
70
62
Rake ::Task [ :cross ] . prerequisites << "lib/mysql2/mysql2.rb"
71
63
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
0 commit comments