Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install pre-built package #4

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,7 @@ jobs:
bundler-cache: true
- name: Prepare tests
run: bundle exec rake compile
- name: Wait until Cassandra is stable
run: sleep 30
- name: Run tests
run: bundle exec rake test
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
133 changes: 93 additions & 40 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,111 @@ 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")

FileUtils.rm_rf('ports')
FileUtils.rm_rf('tmp')

$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.
if NativePackageInstaller.install(homebrew: 'cassandra-cpp-driver')
path = `brew --prefix cassandra-cpp-driver`.strip
$CPPFLAGS += " -I#{path}/include"
$LDFLAGS += " -L#{path}/lib -Wl,-rpath,#{path}/lib -lcassandra"
return true
end
end
end

FileUtils.rm_rf('ports')
FileUtils.rm_rf('tmp')
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

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"
end
end

$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"
LibuvInstaller.install
CassandraDriverInstaller.install

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