@@ -15,7 +15,8 @@ Rake::ExtensionTask.new('odgi') do |ext|
1515 ext . lib_dir = 'lib/odgi'
1616end
1717
18- jemalloc_lib = File . expand_path ( 'jemalloc/lib/libjemalloc.a' , __dir__ )
18+ jemalloc_shared_lib_ext = RUBY_PLATFORM =~ /darwin/ ? 'dylib' : 'so'
19+ jemalloc_lib = File . expand_path ( "jemalloc/lib/libjemalloc.#{ jemalloc_shared_lib_ext } " , __dir__ )
1920
2021file jemalloc_lib do
2122 Dir . chdir ( 'jemalloc' ) do
@@ -39,28 +40,6 @@ def find_cmake_files
3940 files
4041end
4142
42- def patch_cmake_static_jemalloc
43- file = 'odgi/CMakeLists.txt'
44- return unless File . file? ( file )
45-
46- orig = "#{ file } .orig"
47- orig = nil if File . exist? ( orig )
48-
49- content = File . read ( file )
50-
51- jemalloc_declaration = <<~CMAKE
52- add_library(jemalloc STATIC IMPORTED)
53- set_target_properties(jemalloc PROPERTIES IMPORTED_LOCATION "${JEMALLOC_LIBRARY}")
54- CMAKE
55-
56- return if content . include? ( 'add_library(jemalloc STATIC IMPORTED)' )
57-
58- content = jemalloc_declaration + "\n " + content
59- File . write ( orig , File . read ( file ) ) if orig
60- File . write ( file , content )
61- puts "Inserted static jemalloc declaration into: #{ file } "
62- end
63-
6443def patch_cmake_versions
6544 find_cmake_files . each do |file |
6645 next unless File . file? ( file )
@@ -89,6 +68,25 @@ def restore_cmake_versions
8968 end
9069end
9170
71+ # Define odgi shared library as a file task (platform-specific extension)
72+ shared_lib_ext = RUBY_PLATFORM =~ /darwin/ ? 'dylib' : 'so'
73+ odgi_shared_lib = File . expand_path ( "odgi/lib/libodgi.#{ shared_lib_ext } " , __dir__ )
74+
75+ file odgi_shared_lib => [ jemalloc_lib ] do
76+ patch_cmake_versions
77+
78+ jemalloc_root_dir = File . expand_path ( 'jemalloc' , __dir__ )
79+ jemalloc_lib_dir = File . join ( jemalloc_root_dir , 'lib' )
80+ jemalloc_include_dir = File . join ( jemalloc_root_dir , 'include/jemalloc' )
81+ jemalloc_shared_lib_ext = RUBY_PLATFORM =~ /darwin/ ? 'dylib' : 'so'
82+ jemalloc_lib_file = File . join ( jemalloc_lib_dir , "libjemalloc.#{ jemalloc_shared_lib_ext } " )
83+
84+ Dir . chdir ( 'odgi' ) do
85+ sh "cmake -H. -Bbuild -DJEMALLOC_LIBRARY=#{ jemalloc_lib_file } -DJEMALLOC_INCLUDE_DIR=#{ jemalloc_include_dir } "
86+ sh "cmake --build build -- -j #{ Etc . nprocessors } "
87+ end
88+ end
89+
9290namespace :odgi do
9391 task :patch_cmake do
9492 patch_cmake_versions
@@ -98,22 +96,8 @@ namespace :odgi do
9896 restore_cmake_versions
9997 end
10098
101- task :patch_cmake_static_jemalloc do
102- patch_cmake_static_jemalloc
103- end
104-
10599 desc 'Building odgi'
106- task build : [ 'jemalloc:build' , :patch_cmake , :patch_cmake_static_jemalloc ] do
107- jemalloc_root_dir = File . expand_path ( 'jemalloc' , __dir__ )
108- jemalloc_lib_dir = File . join ( jemalloc_root_dir , 'lib' )
109- jemalloc_include_dir = File . join ( jemalloc_root_dir , 'include/jemalloc' )
110- jemalloc_lib_file = File . join ( jemalloc_lib_dir , 'libjemalloc.a' )
111-
112- Dir . chdir ( 'odgi' ) do
113- sh "cmake -H. -Bbuild -DJEMALLOC_LIBRARY=#{ jemalloc_lib_file } -DJEMALLOC_INCLUDE_DIR=#{ jemalloc_include_dir } "
114- sh "cmake --build build -- -j #{ Etc . nprocessors } "
115- end
116- end
100+ task build : odgi_shared_lib
117101end
118102
119103task compile : 'odgi:build'
0 commit comments