diff --git a/bindings/ruby/README.md b/bindings/ruby/README.md index 208a89f3..6de00fb2 100644 --- a/bindings/ruby/README.md +++ b/bindings/ruby/README.md @@ -24,7 +24,21 @@ or, $ gem install whispercpp -- --enable-ggml-cuda -See whisper.cpp's [README](https://github.com/ggml-org/whisper.cpp/blob/master/README.md) for available options. You need convert options present the README to Ruby-style options. +See whisper.cpp's [README](https://github.com/ggml-org/whisper.cpp/blob/master/README.md) for available options. You need convert options present the README to Ruby-style options, for example: + +Boolean options: + +* `-DGGML_BLAS=1` -> `--enable-ggml-blas` +* `-DWHISER_COREML=OFF` -> `--disable-whisper-coreml` + +Argument options: + +* `-DGGML_CUDA_COMPRESSION_MODE=size` -> `--ggml-cuda-compression-mode=size` + +Combination: + +* `-DGGML_CUDA=1 -DCMAKE_CUDA_ARCHITECTURES="86"` -> `--enable-ggml-cuda --cmake_cuda-architectures="86"` + For boolean options like `GGML_CUDA`, the README says `-DGGML_CUDA=1`. You need strip `-D`, prepend `--enable-` for `1` or `ON` (`--disable-` for `0` or `OFF`) and make it kebab-case: `--enable-ggml-cuda`. For options which require arguments like `CMAKE_CUDA_ARCHITECTURES`, the README says `-DCMAKE_CUDA_ARCHITECTURES="86"`. You need strip `-D`, prepend `--`, make it kebab-case, append `=` and append argument: `--cmake-cuda-architectures="86"`. diff --git a/bindings/ruby/ext/dependencies.rb b/bindings/ruby/ext/dependencies.rb index 9beb128c..79e325c9 100644 --- a/bindings/ruby/ext/dependencies.rb +++ b/bindings/ruby/ext/dependencies.rb @@ -1,16 +1,28 @@ require "tsort" class Dependencies + include TSort + def initialize(cmake, options) @cmake = cmake @options = options + @static_lib_shape = nil + @nodes = {} + @graph = Hash.new {|h, k| h[k] = []} generate_dot - @libs = parse_dot + parse_dot + end + + def libs + tsort.filter_map {|node| + label, shape = @nodes[node] + shape == @static_lib_shape ? label : nil + }.reverse.collect {|lib| "lib#{lib}.a"} end def to_s - @libs.join(" ") + libs.join(" ") end private @@ -20,42 +32,38 @@ class Dependencies end def generate_dot - system @cmake, "-S", "sources", "-B", "build", "--graphviz", dot_path, "-D", "BUILD_SHARED_LIBS=OFF", @options.to_s, exception: true + args = ["-S", "sources", "-B", "build", "--graphviz", dot_path, "-D", "BUILD_SHARED_LIBS=OFF"] + args << @options.to_s unless @options.to_s.empty? + system @cmake, *args, exception: true end def parse_dot - static_lib_shape = nil - nodes = {} - depends = Hash.new {|h, k| h[k] = []} - - class << depends - include TSort - alias tsort_each_node each_key - def tsort_each_child(node, &block) - fetch(node, []).each(&block) - end - end - File.open(dot_path).each_line do |line| case line when /\[\s*label\s*=\s*"Static Library"\s*,\s*shape\s*=\s*(?\w+)\s*\]/ - static_lib_shape = $~[:shape] + @static_lib_shape = $~[:shape] when /\A\s*"(?\w+)"\s*\[\s*label\s*=\s*"(?