From 81a82141a841b88899cdadce53e2ca2663e8c392 Mon Sep 17 00:00:00 2001 From: Watson Date: Sat, 25 Nov 2023 15:51:22 +0900 Subject: [PATCH] WIP --- 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 | 150 ++++++++++++++++++++++-------- 7 files changed, 194 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 d4aafb1..919e938 100644 --- a/ext/ilios/extconf.rb +++ b/ext/ilios/extconf.rb @@ -18,59 +18,133 @@ raise end -unless NativePackageInstaller.install( - arch_linux: 'libuv', - alt_linux: 'libuv', - debian: 'libuv1-dev', - freebsd: 'libuv', - gentoo_linux: 'libuv', - homebrew: 'libuv', - macports: 'libuv', - redhat: 'libuv-devel' -) - - raise 'Failed to install libuv' +def num_cpu_cores + cores = + begin + if RUBY_PLATFORM.include?('darwin') + Integer(`sysctl -n hw.ncpu`, 10) - 1 + else + Integer(`nproc`, 10) - 1 + end + rescue StandardError + 2 + end + cores.positive? ? cores : 1 end -unless File.exist?(CASSANDRA_CPP_DRIVER_INSTALL_PATH) - # 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. +module LibuvInstaller + class LibuvRecipe < MiniPortileCMake + def configure_prefix + "-DCMAKE_INSTALL_PREFIX=#{LIBUV_INSTALL_PATH}" + end + end + + def self.install + return unless install_from_package - class CassandraRecipe < MiniPortileCMake - def self.num_cpu_cores - cores = - begin - if RUBY_PLATFORM.include?('darwin') - Integer(`sysctl -n hw.ncpu`, 10) - 1 - else - Integer(`nproc`, 10) - 1 - end - rescue StandardError - 2 + install_from_source + end + + def self.install_from_package + unless NativePackageInstaller.install( + arch_linux: 'libuv', + alt_linux: 'libuv', + debian: 'libuv1-dev', + freebsd: 'libuv', + gentoo_linux: 'libuv', + homebrew: 'libuv', + macports: 'libuv', + redhat: 'libuv-devel' + ) + + return false + end + + true + end + + LIBUV_INSTALL_PATH = File.expand_path('libuv') + private_constant :LIBUV_INSTALL_PATH + + 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 - cores.positive? ? cores : 1 + xsystem( + "install_name_tool -id #{LIBUV_INSTALL_PATH}/lib/libuv.1.dylib #{LIBUV_INSTALL_PATH}/lib/libuv.1.dylib" + ) + end end + $CPPFLAGS += " -I#{LIBUV_INSTALL_PATH}/include" + $LDFLAGS += " -L#{LIBUV_INSTALL_PATH}/lib -Wl,-rpath,#{LIBUV_INSTALL_PATH}/lib -luv" + true + end +end + +module CassandraDriverInstaller + 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 #{CassandraRecipe.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 unless 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. + unless NativePackageInstaller.install( + arch_linux: 'cassandra-cpp-driver', + homebrew: 'cassandra-cpp-driver', + redhat: 'cassandra-cpp-driver' + ) + + return false + end + + true + 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" + + true end end +LibuvInstaller.install +CassandraDriverInstaller.install + + FileUtils.rm_rf('ports') FileUtils.rm_rf('tmp') -$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" - create_makefile('ilios')