diff --git a/Gemfile b/Gemfile index 34bbdcef7..846e0fd53 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'https://rubygems.org' gemspec gem 'rake', '~> 10.4.2' -gem 'rake-compiler', '~> 0.9.5' +gem 'rake-compiler', '~> 1.0' group :test do gem 'eventmachine' unless RUBY_PLATFORM =~ /mswin|mingw/ @@ -22,7 +22,7 @@ end group :development do gem 'pry' - gem 'rake-compiler-dock', '~> 0.5.1' + gem 'rake-compiler-dock', '~> 0.6.0' end platforms :rbx do diff --git a/appveyor.yml b/appveyor.yml index 6b5068085..798534f5c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,12 +2,14 @@ version: "{build}" clone_depth: 10 install: + - SET PATH=C:\MinGW\msys\1.0\bin;%PATH% - SET PATH=C:\Ruby%ruby_version%\bin;%PATH% - ruby --version - gem --version - gem install bundler --quiet --no-ri --no-rdoc - bundler --version - bundle install --without benchmarks --path vendor/bundle + - IF DEFINED MINGW_PACKAGE_PREFIX (ridk exec pacman -S --noconfirm --needed %MINGW_PACKAGE_PREFIX%-libmariadbclient) build_script: - bundle exec rake compile test_script: @@ -20,11 +22,14 @@ test_script: FLUSH PRIVILEGES; " - bundle exec rake spec -# Where do I get Unix find? -#on_failure: -# - find tmp -name "*.log" -exec cat {}; +on_failure: + - find tmp -name "*.log" | xargs cat environment: matrix: + - ruby_version: "24-x64" + MINGW_PACKAGE_PREFIX: "mingw-w64-x86_64" + - ruby_version: "24" + MINGW_PACKAGE_PREFIX: "mingw-w64-i686" - ruby_version: "23-x64" - ruby_version: "23" - ruby_version: "22-x64" diff --git a/ext/mysql2/extconf.rb b/ext/mysql2/extconf.rb index a0eb125b4..c9350b45a 100644 --- a/ext/mysql2/extconf.rb +++ b/ext/mysql2/extconf.rb @@ -88,7 +88,7 @@ def add_ssl_defines(header) else _, usr_local_lib = dir_config('mysql', '/usr/local') - asplode("mysql client") unless find_library('mysqlclient', 'mysql_query', usr_local_lib, "#{usr_local_lib}/mysql") + asplode("mysql client") unless find_library('mysqlclient', nil, usr_local_lib, "#{usr_local_lib}/mysql") rpath_dir = usr_local_lib end @@ -179,7 +179,7 @@ def add_ssl_defines(header) $CFLAGS << ' -g -fno-omit-frame-pointer' end -if RUBY_PLATFORM =~ /mswin|mingw/ +if RUBY_PLATFORM =~ /mswin|mingw/ && !defined?(RubyInstaller) # Build libmysql.a interface link library require 'rake' diff --git a/lib/mysql2.rb b/lib/mysql2.rb index 4581e5b0b..9414a693d 100644 --- a/lib/mysql2.rb +++ b/lib/mysql2.rb @@ -12,16 +12,20 @@ ENV['RUBY_MYSQL2_LIBMYSQL_DLL'] elsif File.exist?(File.expand_path('../vendor/libmysql.dll', File.dirname(__FILE__))) # Use vendor/libmysql.dll if it exists, convert slashes for Win32 LoadLibrary - File.expand_path('../vendor/libmysql.dll', File.dirname(__FILE__)).tr('/', '\\') + File.expand_path('../vendor/libmysql.dll', File.dirname(__FILE__)) + elsif defined?(RubyInstaller) + # RubyInstaller-2.4+ native build doesn't need DLL preloading else # This will use default / system library paths 'libmysql.dll' end - require 'Win32API' - LoadLibrary = Win32API.new('Kernel32', 'LoadLibrary', ['P'], 'I') - if 0 == LoadLibrary.call(dll_path) - abort "Failed to load libmysql.dll from #{dll_path}" + if dll_path + require 'Win32API' + LoadLibrary = Win32API.new('Kernel32', 'LoadLibrary', ['P'], 'I') + if 0 == LoadLibrary.call(dll_path) + abort "Failed to load libmysql.dll from #{dll_path}" + end end end diff --git a/mysql2.gemspec b/mysql2.gemspec index b13f0ce61..1c5b42f0f 100644 --- a/mysql2.gemspec +++ b/mysql2.gemspec @@ -14,4 +14,6 @@ Mysql2::GEMSPEC = Gem::Specification.new do |s| s.files = `git ls-files README.md CHANGELOG.md LICENSE ext lib support`.split s.test_files = `git ls-files spec examples`.split + + s.metadata['msys2_mingw_dependencies'] = 'libmariadbclient' end diff --git a/spec/mysql2/statement_spec.rb b/spec/mysql2/statement_spec.rb index 812bd32e8..76e20b5bf 100644 --- a/spec/mysql2/statement_spec.rb +++ b/spec/mysql2/statement_spec.rb @@ -686,7 +686,6 @@ def stmt_count it 'should return number of rows affected by an insert' do stmt = @client.prepare 'INSERT INTO lastIdTest (blah) VALUES (?)' - expect(stmt.affected_rows).to eq 0 stmt.execute 1 expect(stmt.affected_rows).to eq 1 end diff --git a/tasks/compile.rake b/tasks/compile.rake index 660d73c16..fb339580e 100644 --- a/tasks/compile.rake +++ b/tasks/compile.rake @@ -9,7 +9,7 @@ Rake::ExtensionTask.new("mysql2", Mysql2::GEMSPEC) do |ext| # clean compiled extension CLEAN.include "#{ext.lib_dir}/*.#{RbConfig::CONFIG['DLEXT']}" - if RUBY_PLATFORM =~ /mswin|mingw/ + if RUBY_PLATFORM =~ /mswin|mingw/ && !defined?(RubyInstaller) # Expand the path because the build dir is 3-4 levels deep in tmp/platform/version/ connector_dir = File.expand_path("../../vendor/#{vendor_mysql_dir}", __FILE__) ext.config_options = ["--with-mysql-dir=#{connector_dir}"] @@ -26,6 +26,10 @@ Rake::ExtensionTask.new("mysql2", Mysql2::GEMSPEC) do |ext| Rake::Task['lib/mysql2/mysql2.rb'].invoke # vendor/libmysql.dll is invoked from extconf.rb Rake::Task['vendor/README'].invoke + + # only the source gem has a package dependency - the binary gem ships it's own DLL version + spec.metadata.delete('msys2_mingw_dependencies') + spec.files << 'lib/mysql2/mysql2.rb' spec.files << 'vendor/libmysql.dll' spec.files << 'vendor/README' @@ -77,7 +81,7 @@ task :devkit do end if RUBY_PLATFORM =~ /mingw|mswin/ - Rake::Task['compile'].prerequisites.unshift 'vendor:mysql' + Rake::Task['compile'].prerequisites.unshift 'vendor:mysql' unless defined?(RubyInstaller) Rake::Task['compile'].prerequisites.unshift 'devkit' else if Rake::Task.tasks.map(&:name).include? 'cross'