From d7f5b559f154e2619622fded7f705469a323e946 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Mon, 31 Jul 2017 17:57:56 +0200 Subject: [PATCH] Fix compat with RubyInstaller-2.4 on Windows Since RubyInstaller-2.4+ is bundled with MSYS2 and the libmariadbclient can be installed per gemspec library dependency, it is easy to build the mysql2 gem in Windows. The MSYS2/MINGW dependency feature is documented here: https://github.com/oneclick/rubyinstaller2/wiki/For-gem-developers#msys2-library-dependency This also adds ruby-2.4 binaries, so that the mysql2 is still usabel as a binary gem. Fixes #861 The change in the spec is required for mariadbclient. It throws an error if no query was executed. Due to the stdcall convention on i686, the mysql_query() function check fails, so that it is omitted, now. --- Gemfile | 4 ++-- appveyor.yml | 11 ++++++++--- ext/mysql2/extconf.rb | 4 ++-- lib/mysql2.rb | 14 +++++++++----- mysql2.gemspec | 2 ++ spec/mysql2/statement_spec.rb | 1 - tasks/compile.rake | 4 ++-- 7 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Gemfile b/Gemfile index 86a7ddb11..16303429b 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 4fe27562c..e3795f799 100644 --- a/ext/mysql2/extconf.rb +++ b/ext/mysql2/extconf.rb @@ -92,7 +92,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 @@ -177,7 +177,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 a45cace3a..1d8aac05d 100644 --- a/lib/mysql2.rb +++ b/lib/mysql2.rb @@ -13,16 +13,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 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 8596b5eec..17697fece 100644 --- a/mysql2.gemspec +++ b/mysql2.gemspec @@ -13,4 +13,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 8b4a714fd..c564204a9 100644 --- a/spec/mysql2/statement_spec.rb +++ b/spec/mysql2/statement_spec.rb @@ -712,7 +712,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 ce610cdad..04c30289e 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}"] @@ -77,7 +77,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'