@@ -15,40 +15,106 @@ 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__ )
19+
20+ file jemalloc_lib do
21+ Dir . chdir ( 'jemalloc' ) do
22+ sh './autogen.sh'
23+ sh './configure --disable-initial-exec-tls --with-pic'
24+ sh "make -j #{ Etc . nprocessors } "
25+ end
26+ end
27+
1828namespace :jemalloc do
19- desc 'Building jemalloc'
20- task :build do
21- Dir . chdir ( 'jemalloc' ) do
22- sh './autogen.sh'
23- sh './configure --disable-initial-exec-tls'
24- sh "make -j #{ Etc . nprocessors } "
25- end
29+ desc 'Build jemalloc if needed'
30+ task build : jemalloc_lib
31+ end
32+
33+ def find_cmake_files
34+ require 'find'
35+ files = [ ]
36+ Find . find ( 'odgi' ) do |path |
37+ files << path if path =~ /CMakeLists\. txt$/ || path =~ /\. cmake$/
38+ end
39+ files
40+ end
41+
42+ def patch_cmake_static_jemalloc
43+ file = 'odgi/CMakeLists.txt'
44+ return unless File . file? ( file )
45+
46+ orig = "#{ file } .orig"
47+ return 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 ) )
60+ File . write ( file , content )
61+ puts "Inserted static jemalloc declaration into: #{ file } "
62+ end
63+
64+ def patch_cmake_versions
65+ find_cmake_files . each do |file |
66+ next unless File . file? ( file )
67+
68+ orig = "#{ file } .orig"
69+ next if File . exist? ( orig )
70+
71+ content = File . read ( file )
72+ patched = content . gsub ( /cmake_minimum_required\s *\( \s *VERSION\s +[^)]+\) /i , 'cmake_minimum_required(VERSION 3.5)' )
73+ next unless content != patched
74+
75+ File . write ( orig , content )
76+ File . write ( file , patched )
77+ puts "Patched: #{ file } "
78+ end
79+ end
80+
81+ def restore_cmake_versions
82+ find_cmake_files . each do |file |
83+ orig = "#{ file } .orig"
84+ next unless File . exist? ( orig )
85+
86+ File . write ( file , File . read ( orig ) )
87+ File . delete ( orig )
88+ puts "Restored: #{ file } "
2689 end
2790end
2891
2992namespace :odgi do
93+ task :patch_cmake do
94+ patch_cmake_versions
95+ end
96+
97+ task :restore_cmake do
98+ restore_cmake_versions
99+ end
100+
101+ task :patch_cmake_static_jemalloc do
102+ patch_cmake_static_jemalloc
103+ end
104+
30105 desc 'Building odgi'
31- task :build do
32- # Fix sdsl-lite louds_tree.hpp for macOS/Clang compatibility
33- louds_tree_file = 'deps/sdsl-lite/include/sdsl/louds_tree.hpp'
34- if File . exist? ( louds_tree_file )
35- content = File . read ( louds_tree_file )
36- content . gsub! ( 'tree.m_select1' , 'tree.m_bv_select1' )
37- content . gsub! ( 'tree.m_select0' , 'tree.m_bv_select0' )
38- File . write ( louds_tree_file , content )
39- end
40-
106+ task build : [ 'jemalloc:build' , :patch_cmake , :patch_cmake_static_jemalloc ] do
41107 jemalloc_root_dir = File . expand_path ( 'jemalloc' , __dir__ )
42108 jemalloc_lib_dir = File . join ( jemalloc_root_dir , 'lib' )
43- jemalloc_include_dir = File . join ( jemalloc_root_dir , 'include' )
109+ jemalloc_include_dir = File . join ( jemalloc_root_dir , 'include/jemalloc ' )
44110 jemalloc_lib_file = File . join ( jemalloc_lib_dir , 'libjemalloc.a' )
45-
46- puts "DEBUG: jemalloc_lib_file = #{ jemalloc_lib_file } "
47- puts "DEBUG: File exists? #{ File . exist? ( jemalloc_lib_file ) } "
48-
111+
49112 Dir . chdir ( 'odgi' ) do
50113 sh "cmake -H. -Bbuild -DJEMALLOC_LIBRARY=#{ jemalloc_lib_file } -DJEMALLOC_INCLUDE_DIR=#{ jemalloc_include_dir } "
51114 sh "cmake --build build -- -j #{ Etc . nprocessors } "
52115 end
53116 end
54117end
118+
119+ task compile : 'odgi:build'
120+ task test : :compile
0 commit comments