From 323042afc8b64acb79d2da20854ddc3ca2f15529 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 | 43 ++++++++++++++----------------------------- ilios.gemspec | 1 + lib/ilios/version.rb | 3 --- 3 files changed, 15 insertions(+), 32 deletions(-) diff --git a/ext/ilios/extconf.rb b/ext/ilios/extconf.rb index c08a462..a9341af 100644 --- a/ext/ilios/extconf.rb +++ b/ext/ilios/extconf.rb @@ -3,13 +3,13 @@ require File.expand_path('../../lib/ilios/version', __dir__) require 'fileutils' require 'mini_portile2' +require 'native-package-installer' require 'mkmf' 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,22 @@ 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 - - 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 +unless NativePackageInstaller.install(arch_linux: 'libuv', + debian: 'libuv1', + freebsd: 'libuv', + homebrew: 'libuv', + macports: 'libuv', + redhat: 'libuv', + fedora: 'libuv') + 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 +66,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