|
1 | 1 | require "mkmf" |
2 | | -require "tsort" |
3 | 2 | require_relative "options" |
| 3 | +require_relative "dependencies" |
4 | 4 |
|
5 | 5 | cmake = find_executable("cmake") || abort |
6 | 6 | options = Options.new |
7 | 7 | have_library("gomp") rescue nil |
8 | | - |
9 | | -prefix = File.join("build", "whisper.cpp.dot") |
10 | | -system cmake, "-S", "sources", "-B", "build", "--graphviz", prefix, "-D", "BUILD_SHARED_LIBS=OFF", options.to_s, exception: true |
11 | | - |
12 | | -static_lib_shape = nil |
13 | | -nodes = {} |
14 | | -depends = {} |
15 | | -class << depends |
16 | | - include TSort |
17 | | - alias tsort_each_node each_key |
18 | | - def tsort_each_child(node, &block) |
19 | | - fetch(node, []).each(&block) |
20 | | - end |
21 | | -end |
22 | | -File.open(File.join("build", "whisper.cpp.dot")).each_line do |line| |
23 | | - case line |
24 | | - when /\[\s*label\s*=\s*"Static Library"\s*,\s*shape\s*=\s*(?<shape>\w+)\s*\]/ |
25 | | - static_lib_shape = $~[:shape] |
26 | | - when /\A\s*"(?<node>\w+)"\s*\[\s*label\s*=\s*"(?<label>\S+)"\s*,\s*shape\s*=\s*(?<shape>\w+)\s*\]\s*;\s*\z/ |
27 | | - node = $~[:node] |
28 | | - label = $~[:label] |
29 | | - shape = $~[:shape] |
30 | | - nodes[node] = [label, shape] |
31 | | - when /\A\s*"(?<depender>\w+)"\s*->\s*"(?<dependee>\w+)"/ |
32 | | - depender = $~[:depender] |
33 | | - dependee = $~[:dependee] |
34 | | - depends[depender] ||= [] |
35 | | - depends[depender] << dependee |
36 | | - end |
37 | | -end |
38 | | -libs = depends.tsort.filter_map {|node| |
39 | | - label, shape = nodes[node] |
40 | | - shape == static_lib_shape ? label : nil |
41 | | -}.collect {|lib| "lib#{lib}.a"} |
42 | | - .reverse |
43 | | - .join(" ") |
| 8 | +libs = Dependencies.new(cmake, options) |
44 | 9 |
|
45 | 10 | $INCFLAGS << " -Isources/include -Isources/ggml/include -Isources/examples" |
46 | 11 | $LOCAL_LIBS << " #{libs}" |
|
0 commit comments