From 716387c375f2a6065045e43084fb0a4b57be29dd Mon Sep 17 00:00:00 2001 From: kojix2 <2xijok@gmail.com> Date: Fri, 23 Aug 2024 10:46:13 +0900 Subject: [PATCH] Support macOS --- .github/workflows/ci.yml | 10 +++-- Rakefile | 30 +++++++------- ext/odgi/extconf.rb | 84 ++++++++++++++++++++++++---------------- test/odgi_test.rb | 8 ++-- 4 files changed, 76 insertions(+), 56 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4355a4f..343b508 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 diff --git a/Rakefile b/Rakefile index 23c3dc1..cdc1161 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/ext/odgi/extconf.rb b/ext/odgi/extconf.rb index 2c0c4fd..6837476 100644 --- a/ext/odgi/extconf.rb +++ b/ext/odgi/extconf.rb @@ -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) diff --git a/test/odgi_test.rb b/test/odgi_test.rb index 845c95b..5d98a37 100644 --- a/test/odgi_test.rb +++ b/test/odgi_test.rb @@ -1,4 +1,4 @@ -require_relative "test_helper" +require_relative 'test_helper' class OdgiTest < Minitest::Test def test_that_it_has_a_version_number @@ -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