Skip to content

Commit

Permalink
Install pre-built package
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Nov 25, 2023
1 parent ff0bf9b commit 7033c53
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 38 deletions.
17 changes: 17 additions & 0 deletions dockerfiles/alt-linux.dockerfile
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions dockerfiles/arch-linux.dockerfile
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions dockerfiles/docker-build
Original file line number Diff line number Diff line change
@@ -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}
7 changes: 7 additions & 0 deletions dockerfiles/docker-launch
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions dockerfiles/fedora.dockerfile
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions dockerfiles/ubuntu.dockerfile
Original file line number Diff line number Diff line change
@@ -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
125 changes: 87 additions & 38 deletions ext/ilios/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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')
1 change: 1 addition & 0 deletions ilios.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7033c53

Please sign in to comment.