From a799975828c54dc9d80b6d39d9536652acbaf0f7 Mon Sep 17 00:00:00 2001 From: Watson Date: Sat, 25 Nov 2023 02:50:39 +0900 Subject: [PATCH] Install pre-built libuv package --- ext/ilios/extconf.rb | 45 +++++++++++++++++--------------------------- ilios.gemspec | 1 + lib/ilios/version.rb | 3 --- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/ext/ilios/extconf.rb b/ext/ilios/extconf.rb index c08a462..6a5c2d6 100644 --- a/ext/ilios/extconf.rb +++ b/ext/ilios/extconf.rb @@ -4,12 +4,12 @@ require 'fileutils' require 'mini_portile2' require 'mkmf' +require 'native-package-installer' have_func('malloc_usable_size') have_func('malloc_size') CASSANDRA_CPP_DRIVER_INSTALL_PATH = File.expand_path('cpp-driver') -LIBUV_INSTALL_PATH = File.expand_path('libuv') def num_cpu_cores cores = @@ -32,36 +32,26 @@ def num_cpu_cores raise end -unless File.exist?(LIBUV_INSTALL_PATH) - class LibuvRecipe < MiniPortileCMake - def configure_prefix - "-DCMAKE_INSTALL_PREFIX=#{LIBUV_INSTALL_PATH}" - end - end +unless NativePackageInstaller.install( + arch_linux: 'libuv', + alt_linux: 'libuv', + debian: 'libuv1-dev', + freebsd: 'libuv', + gentoo_linux: 'libuv', + homebrew: 'libuv', + macports: 'libuv', + redhat: 'libuv' +) - libuv_recipe = LibuvRecipe.new('libuv', Ilios::LIBUV_VERSION, make_command: "make -j #{num_cpu_cores}") - libuv_recipe.files << { - url: "https://github.com/libuv/libuv/archive/v#{Ilios::LIBUV_VERSION}.tar.gz" - } - libuv_recipe.cook - if RUBY_PLATFORM.include?('darwin') - unless find_executable('install_name_tool') - puts '------------------------------------------------------' - puts 'Error: install_name_tool is required to build this gem' - puts '------------------------------------------------------' - raise - end - xsystem("install_name_tool -id #{LIBUV_INSTALL_PATH}/lib/libuv.1.dylib #{LIBUV_INSTALL_PATH}/lib/libuv.1.dylib") - end + raise 'Failed to install libuv' end unless File.exist?(CASSANDRA_CPP_DRIVER_INSTALL_PATH) - class CassandraRecipe < MiniPortileCMake - def initialize(name, version, **kwargs) - ENV['LIBUV_ROOT_DIR'] = LIBUV_INSTALL_PATH - super(name, version, **kwargs) - end + # Install Cassandra C/C++ driver via MiniPortile2. + # It doesn't provide pre-built package in official repository at the each distributions, + # so we need to build it from source. + class CassandraRecipe < MiniPortileCMake def configure_prefix "-DCMAKE_INSTALL_PREFIX=#{CASSANDRA_CPP_DRIVER_INSTALL_PATH}" end @@ -80,8 +70,7 @@ def configure_prefix FileUtils.rm_rf('ports') FileUtils.rm_rf('tmp') -$CPPFLAGS += " -I#{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/include -I#{LIBUV_INSTALL_PATH}/include" +$CPPFLAGS += " -I#{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/include" $LDFLAGS += " -L#{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/lib -Wl,-rpath,#{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/lib -lcassandra" -$LDFLAGS += " -L#{LIBUV_INSTALL_PATH}/lib -Wl,-rpath,#{LIBUV_INSTALL_PATH}/lib -luv" create_makefile('ilios') diff --git a/ilios.gemspec b/ilios.gemspec index da35ff5..a5bfb98 100644 --- a/ilios.gemspec +++ b/ilios.gemspec @@ -35,4 +35,5 @@ Gem::Specification.new do |spec| spec.extensions << 'ext/ilios/extconf.rb' spec.add_runtime_dependency('mini_portile2', '~> 2.8') + spec.add_runtime_dependency('native-package-installer', '~> 1.1') end diff --git a/lib/ilios/version.rb b/lib/ilios/version.rb index 8895ec4..73703aa 100644 --- a/lib/ilios/version.rb +++ b/lib/ilios/version.rb @@ -6,7 +6,4 @@ module Ilios CASSANDRA_CPP_DRIVER_VERSION = '2.17.1' public_constant :CASSANDRA_CPP_DRIVER_VERSION - - LIBUV_VERSION = '1.47.0' - public_constant :LIBUV_VERSION end