From 7033c539798cfcb23f17d10b41b12332c83099f2 Mon Sep 17 00:00:00 2001 From: Watson Date: Sat, 25 Nov 2023 15:51:22 +0900 Subject: [PATCH] Install pre-built package --- dockerfiles/alt-linux.dockerfile | 17 ++++ dockerfiles/arch-linux.dockerfile | 16 ++++ dockerfiles/docker-build | 7 ++ dockerfiles/docker-launch | 7 ++ dockerfiles/fedora.dockerfile | 18 +++++ dockerfiles/ubuntu.dockerfile | 17 ++++ ext/ilios/extconf.rb | 125 +++++++++++++++++++++--------- ilios.gemspec | 1 + 8 files changed, 170 insertions(+), 38 deletions(-) create mode 100644 dockerfiles/alt-linux.dockerfile create mode 100644 dockerfiles/arch-linux.dockerfile create mode 100755 dockerfiles/docker-build create mode 100755 dockerfiles/docker-launch create mode 100644 dockerfiles/fedora.dockerfile create mode 100644 dockerfiles/ubuntu.dockerfile diff --git a/dockerfiles/alt-linux.dockerfile b/dockerfiles/alt-linux.dockerfile new file mode 100644 index 0000000..78fbdab --- /dev/null +++ b/dockerfiles/alt-linux.dockerfile @@ -0,0 +1,17 @@ +FROM alt + +RUN \ + apt-get update && \ + apt-get install -y \ + gcc \ + libruby-devel \ + libpcre-devel \ + cmake \ + make \ + ruby \ + openssl \ + zlib \ + sudo \ + which + +WORKDIR /opt/ilios diff --git a/dockerfiles/arch-linux.dockerfile b/dockerfiles/arch-linux.dockerfile new file mode 100644 index 0000000..985b883 --- /dev/null +++ b/dockerfiles/arch-linux.dockerfile @@ -0,0 +1,16 @@ +FROM archlinux + +RUN \ + pacman --sync --noconfirm --refresh --sysupgrade && \ + pacman --sync --noconfirm \ + git \ + gcc \ + cmake \ + make \ + ruby \ + openssl \ + zlib \ + sudo \ + which + +WORKDIR /opt/ilios diff --git a/dockerfiles/docker-build b/dockerfiles/docker-build new file mode 100755 index 0000000..e92ffac --- /dev/null +++ b/dockerfiles/docker-build @@ -0,0 +1,7 @@ +#!/bin/bash + +script_dir=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd) +platform="$1" +dockerfile="${platform}.dockerfile" + +docker build -t "ilios-${platform}" -f ${dockerfile} ${script_dir} diff --git a/dockerfiles/docker-launch b/dockerfiles/docker-launch new file mode 100755 index 0000000..7cea6f0 --- /dev/null +++ b/dockerfiles/docker-launch @@ -0,0 +1,7 @@ +#!/bin/bash + +prject_dir="$(cd $(dirname ${BASH_SOURCE:-$0}); pwd)/.." +platform="$1" +dockerfile="${platform}.dockerfile" + +docker run -v $prject_dir:/opt/ilios --rm -it "ilios-${platform}" bash diff --git a/dockerfiles/fedora.dockerfile b/dockerfiles/fedora.dockerfile new file mode 100644 index 0000000..61398ef --- /dev/null +++ b/dockerfiles/fedora.dockerfile @@ -0,0 +1,18 @@ +FROM fedora + +RUN \ + dnf install -y \ + git \ + gcc \ + g++ \ + cmake \ + make \ + redhat-rpm-config \ + ruby-devel \ + openssl-devel \ + zlib-devel \ + sudo \ + which && \ + dnf clean all + +WORKDIR /opt/ilios diff --git a/dockerfiles/ubuntu.dockerfile b/dockerfiles/ubuntu.dockerfile new file mode 100644 index 0000000..1df0070 --- /dev/null +++ b/dockerfiles/ubuntu.dockerfile @@ -0,0 +1,17 @@ +FROM ubuntu + +RUN \ + apt-get update && \ + apt-get install -y \ + git \ + gcc \ + g++ \ + cmake \ + make \ + ruby-bundler \ + ruby-dev \ + zlib1g-dev \ + libssl-dev \ + sudo + +WORKDIR /opt/ilios diff --git a/ext/ilios/extconf.rb b/ext/ilios/extconf.rb index c08a462..6eecd3e 100644 --- a/ext/ilios/extconf.rb +++ b/ext/ilios/extconf.rb @@ -4,12 +4,17 @@ 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') +unless find_executable('cmake') + puts '--------------------------------------------------' + puts 'Error: cmake is required to build this gem' + puts '--------------------------------------------------' + raise +end def num_cpu_cores cores = @@ -25,63 +30,107 @@ def num_cpu_cores cores.positive? ? cores : 1 end -unless find_executable('cmake') - puts '--------------------------------------------------' - puts 'Error: cmake is required to build this gem' - puts '--------------------------------------------------' - raise -end +module LibuvInstaller + LIBUV_INSTALL_PATH = File.expand_path('libuv') -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 + def self.install + return if install_from_package + + install_from_source + end + + def self.install_from_package + NativePackageInstaller.install( + arch_linux: 'libuv', + alt_linux: 'libuv', + debian: 'libuv1-dev', + freebsd: 'libuv', + gentoo_linux: 'libuv', + homebrew: 'libuv', + macports: 'libuv', + redhat: 'libuv-devel' + ) + end + + def self.install_from_source + unless File.exist?(LIBUV_INSTALL_PATH) + 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 end - xsystem("install_name_tool -id #{LIBUV_INSTALL_PATH}/lib/libuv.1.dylib #{LIBUV_INSTALL_PATH}/lib/libuv.1.dylib") + + $CPPFLAGS += " -I#{LIBUV_INSTALL_PATH}/include" + $LDFLAGS += " -L#{LIBUV_INSTALL_PATH}/lib -Wl,-rpath,#{LIBUV_INSTALL_PATH}/lib -luv" end 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 +module CassandraDriverInstaller + CASSANDRA_CPP_DRIVER_INSTALL_PATH = File.expand_path('cpp-driver') + class CassandraRecipe < MiniPortileCMake def configure_prefix "-DCMAKE_INSTALL_PREFIX=#{CASSANDRA_CPP_DRIVER_INSTALL_PATH}" end end - cassandra_recipe = CassandraRecipe.new('cpp-driver', Ilios::CASSANDRA_CPP_DRIVER_VERSION, make_command: "make -j #{num_cpu_cores}") - cassandra_recipe.files << { - url: "https://github.com/datastax/cpp-driver/archive/#{Ilios::CASSANDRA_CPP_DRIVER_VERSION}.tar.gz" - } - cassandra_recipe.cook - if RUBY_PLATFORM.include?('darwin') - xsystem("install_name_tool -id #{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/lib/libcassandra.2.dylib #{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/lib/libcassandra.2.dylib") + def self.install + return if install_from_package + + install_from_source + end + + def self.install_from_package + # Install Cassandra C/C++ driver via MiniPortile2. + # It doesn't provide pre-built package in some official repository. + NativePackageInstaller.install( + homebrew: 'cassandra-cpp-driver', + redhat: 'cassandra-cpp-driver' + ) + end + + def self.install_from_source + unless File.exist?(CASSANDRA_CPP_DRIVER_INSTALL_PATH) + cassandra_recipe = CassandraRecipe.new('cpp-driver', Ilios::CASSANDRA_CPP_DRIVER_VERSION, make_command: "make -j #{num_cpu_cores}") + cassandra_recipe.files << { + url: "https://github.com/datastax/cpp-driver/archive/#{Ilios::CASSANDRA_CPP_DRIVER_VERSION}.tar.gz" + } + cassandra_recipe.cook + if RUBY_PLATFORM.include?('darwin') + xsystem( + "install_name_tool -id #{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/lib/libcassandra.2.dylib #{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/lib/libcassandra.2.dylib" + ) + end + end + + $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" end end +LibuvInstaller.install +CassandraDriverInstaller.install + + FileUtils.rm_rf('ports') FileUtils.rm_rf('tmp') -$CPPFLAGS += " -I#{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/include -I#{LIBUV_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