Skip to content

Commit

Permalink
Support macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
kojix2 committed Aug 23, 2024
1 parent 98d5fc9 commit 716387c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 56 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ${{ matrix.os }}-latest
strategy:
matrix:
os: ["ubuntu"]
os: ["ubuntu", "macos"]
ruby: ["3.3"]
steps:
- uses: actions/checkout@v4
Expand All @@ -17,12 +17,14 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- if: matrix.os == 'ubuntu'
run: sudo apt-get update -yq && sudo apt upgrade -yq && sudo apt-get upgrade # libjemalloc-dev
run: sudo apt-get update -yq && sudo apt upgrade -yq # && sudo apt-get upgrade libjemalloc-dev
- if: matrix.os == 'macos'
run: brew update && brew install jemalloc
run: brew update && brew install llvm libomp #jemalloc
- if: matrix.os == 'ubuntu'
run: bundle exec rake jemalloc:build && bundle exec rake odgi:build
- if: matrix.os == 'macos'
run: CC=/opt/homebrew/opt/llvm/bin/clang CXX=/opt/homebrew/opt/llvm/bin/clang++ LDFLAGS=-L/opt/homebrew/lib bundle exec rake odgi:build
run: |
CC=$(brew --prefix llvm)/bin/clang CXX=$(brew --prefix llvm)/bin/clang++ LDFLAGS=-L/opt/homebrew/lib bundle exec rake jemalloc:build
CC=$(brew --prefix llvm)/bin/clang CXX=$(brew --prefix llvm)/bin/clang++ LDFLAGS=-L/opt/homebrew/lib bundle exec rake jemalloc:build
- run: bundle exec rake compile
- run: bundle exec rake test
30 changes: 15 additions & 15 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
require "bundler/gem_tasks"
require "rake/testtask"
require 'bundler/gem_tasks'
require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
end

require "rake/extensiontask"
require 'rake/extensiontask'

task build: :compile

Rake::ExtensionTask.new("odgi") do |ext|
ext.lib_dir = "lib/odgi"
Rake::ExtensionTask.new('odgi') do |ext|
ext.lib_dir = 'lib/odgi'
end

namespace :jemalloc do
desc "Building jemalloc"
desc 'Building jemalloc'
task :build do
Dir.chdir("jemalloc") do
sh "./autogen.sh"
sh "./configure --disable-initial-exec-tls"
Dir.chdir('jemalloc') do
sh './autogen.sh'
sh './configure --disable-initial-exec-tls'
sh "make -j #{Etc.nprocessors}"
end
end
end

namespace :odgi do
desc "Building odgi"
desc 'Building odgi'
task :build do
jemalloc_lib_dir = File.expand_path("jemalloc/lib", __dir__)
Dir.chdir("odgi") do
jemalloc_lib_dir = File.expand_path('jemalloc/lib', __dir__)
Dir.chdir('odgi') do
sh "cmake -H. -Bbuild -DJEMALLOC_LIBRARY=#{jemalloc_lib_dir}"
sh "cmake --build build -- -j #{Etc.nprocessors}"
end
Expand Down
84 changes: 51 additions & 33 deletions ext/odgi/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,57 @@

require 'mkmf-rice'

handlegraph_include_dir = File.expand_path('../../odgi/deps/libhandlegraph/src/include', __dir__)
hopscotchmap_include_dir = File.expand_path('../../odgi/deps/hopscotch-map/include', __dir__)
dynamic_include_dir = File.expand_path('../../odgi/deps/DYNAMIC/include', __dir__)
sparsepp_include_dir = File.expand_path('../../odgi/deps/sparsepp/sparsepp', __dir__)
flat_hash_map_include_dir = File.expand_path('../../odgi/deps/flat_hash_map', __dir__)
atomicbitvector_include_dir = File.expand_path('../../odgi/deps/atomicbitvector/include', __dir__)

odgi_include_dir = File.expand_path('../../odgi/src', __dir__)
odgi_library_dir = File.expand_path('../../odgi/lib', __dir__)

find_header('handlegraph/types.hpp', handlegraph_include_dir)
find_header('handlegraph/iteratee.hpp', handlegraph_include_dir)
find_header('handlegraph/util.hpp', handlegraph_include_dir)
find_header('handlegraph/handle_graph.hpp', handlegraph_include_dir)
find_header('handlegraph/path_handle_graph.hpp', handlegraph_include_dir)
find_header('handlegraph/mutable_handle_graph.hpp', handlegraph_include_dir)
find_header('handlegraph/mutable_path_handle_graph.hpp', handlegraph_include_dir)
find_header('handlegraph/mutable_path_mutable_handle_graph.hpp', handlegraph_include_dir)
find_header('handlegraph/deletable_handle_graph.hpp', handlegraph_include_dir)
find_header('handlegraph/mutable_path_deletable_handle_graph.hpp', handlegraph_include_dir)
find_header('handlegraph/serializable_handle_graph.hpp', handlegraph_include_dir)

find_header('tsl/hopscotch_map.h', hopscotchmap_include_dir)

find_header('dynamic.hpp', dynamic_include_dir)

find_header('spp.h', sparsepp_include_dir)

find_header('bytell_hash_map.hpp', flat_hash_map_include_dir)

find_header('atomic_bitvector.hpp', atomicbitvector_include_dir)

find_header('odgi-api.h', odgi_include_dir)
ODGI_DIR = Pathname(__dir__) / '../../odgi'
odgi_library_dir = (ODGI_DIR / 'lib').to_s

# if macOS
if RUBY_PLATFORM =~ /darwin/
(`brew --prefix libomp`.strip + '/include').tap do |dir|
find_header 'omp.h', dir
end
end

(ODGI_DIR / 'deps/libhandlegraph/src/include').tap do |dir|
find_header 'handlegraph/types.hpp', dir
find_header 'handlegraph/iteratee.hpp', dir
find_header 'handlegraph/util.hpp', dir
find_header 'handlegraph/handle_graph.hpp', dir
find_header 'handlegraph/path_handle_graph.hpp', dir
find_header 'handlegraph/mutable_handle_graph.hpp', dir
find_header 'handlegraph/mutable_path_handle_graph.hpp', dir
find_header 'handlegraph/mutable_path_mutable_handle_graph.hpp', dir
find_header 'handlegraph/deletable_handle_graph.hpp', dir
find_header 'handlegraph/mutable_path_deletable_handle_graph.hpp', dir
find_header 'handlegraph/serializable_handle_graph.hpp', dir
end

(ODGI_DIR / 'deps/hopscotch-map/include').tap do |dir|
find_header 'tsl/hopscotch_map.h', dir
end

(ODGI_DIR / 'deps/DYNAMIC/include').tap do |dir|
find_header 'dynamic.hpp', dir
end

(ODGI_DIR / 'src').tap do |dir|
find_header 'atomic_bitvector.hpp', dir
end

(ODGI_DIR / 'deps/sparsepp/sparsepp').tap do |dir|
find_header 'spp.h', dir
end

(ODGI_DIR / 'deps/flat_hash_map').tap do |dir|
find_header 'bytell_hash_map.hpp', dir
end

(ODGI_DIR / 'deps/atomicbitvector/include').tap do |dir|
find_header 'atomic_bitvector.hpp', dir
end

(ODGI_DIR / 'src').tap do |dir|
find_header 'odgi-api.h', dir
end

find_library('odgi', nil, odgi_library_dir)

Expand Down
8 changes: 4 additions & 4 deletions test/odgi_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative "test_helper"
require_relative 'test_helper'

class OdgiTest < Minitest::Test
def test_that_it_has_a_version_number
Expand All @@ -10,9 +10,9 @@ def test_odgi_version
end

def test_odgi_load_graph
graph = ODGI::FFI.odgi_load_graph(
File.join(File.dirname(__dir__), "odgi", "test", "DRB1-3123_sorted.og")
)
graph = ODGI::FFI.odgi_load_graph(
File.join(File.dirname(__dir__), 'odgi', 'test', 'DRB1-3123_sorted.og')
)
assert_kind_of ODGI::FFI::Graph, graph
end
end

0 comments on commit 716387c

Please sign in to comment.