Skip to content

Commit 46bdf92

Browse files
committed
Make gem install accept build options for whisper.cpp
1 parent cbe416d commit 46bdf92

File tree

2 files changed

+190
-5
lines changed

2 files changed

+190
-5
lines changed

bindings/ruby/ext/extconf.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
require "mkmf"
22
require "tsort"
3-
4-
# TODO: options such as CoreML
3+
require_relative "options"
54

65
cmake = find_executable("cmake") || abort
7-
6+
options = Options.new
87
have_library("gomp") rescue nil
98

109
prefix = File.join("build", "whisper.cpp.dot")
11-
system cmake, "-S", "sources", "-B", "build", "--graphviz", prefix, "-D", "BUILD_SHARED_LIBS=OFF", exception: true
10+
system cmake, "-S", "sources", "-B", "build", "--graphviz", prefix, "-D", "BUILD_SHARED_LIBS=OFF", options.to_s, exception: true
1211

1312
static_lib_shape = nil
1413
nodes = {}
@@ -52,7 +51,7 @@ def tsort_each_child(node, &block)
5251
$(TARGET_SO): #{libs}
5352
#{libs}: cmake-targets
5453
cmake-targets:
55-
#{"\t"}#{cmake} -S sources -B build -D BUILD_SHARED_LIBS=OFF -D CMAKE_ARCHIVE_OUTPUT_DIRECTORY=#{__dir__} -D CMAKE_POSITION_INDEPENDENT_CODE=ON
54+
#{"\t"}#{cmake} -S sources -B build -D BUILD_SHARED_LIBS=OFF -D CMAKE_ARCHIVE_OUTPUT_DIRECTORY=#{__dir__} -D CMAKE_POSITION_INDEPENDENT_CODE=ON #{options}
5655
#{"\t"}#{cmake} --build build --config Release --target common whisper
5756
EOF
5857
end

bindings/ruby/ext/options.rb

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
class Options
2+
attr_reader :configs
3+
4+
def initialize
5+
@configs = {}
6+
7+
configure
8+
end
9+
10+
def help
11+
@configs
12+
.collect_concat {|name, (type, value)|
13+
option = option_name(name)
14+
if type == :bool
15+
["--enable-#{option}", "--disable-#{option}"]
16+
else
17+
"--#{option}=#{type.upcase}"
18+
end
19+
}
20+
.join($/)
21+
end
22+
23+
def to_s
24+
@configs
25+
.reject {|name, (type, value)| value.nil?}
26+
.collect {|name, (type, value)| "-D #{name}=#{value == true ? "ON" : value == false ? "OFF" : value.shellescape}"}
27+
.join(" ")
28+
end
29+
30+
private
31+
32+
def configure
33+
filepath "ACCELERATE_FRAMEWORK"
34+
ignored "BUILD_SHARED_LIBS"
35+
ignored "BUILD_TESTING"
36+
ignored "CMAKE_BUILD_TYPE"
37+
ignored "CMAKE_INSTALL_PREFIX"
38+
string "CMAKE_OSX_ARCHITECTURES"
39+
ignored "CMAKE_OSX_DEPLOYMENT_TARGET"
40+
string "CMAKE_OSX_SYSROOT"
41+
filepath "FOUNDATION_LIBRARY"
42+
bool "GGML_ACCELERATE"
43+
bool "GGML_ALL_WARNINGS_3RD_PARTY"
44+
bool "GGML_AMX_BF16"
45+
bool "GGML_AMX_INT8"
46+
bool "GGML_AMX_TILE"
47+
bool "GGML_AVX"
48+
bool "GGML_AVX2"
49+
bool "GGML_AVX512"
50+
bool "GGML_AVX512_BF16"
51+
bool "GGML_AVX512_VBMI"
52+
bool "GGML_AVX512_VNNI"
53+
bool "GGML_AVX_VNNI"
54+
ignored "GGML_BACKEND_DL"
55+
ignored "GGML_BIN_INSTALL_DIR"
56+
bool "GGML_BLAS"
57+
string "GGML_BLAS_VENDOR"
58+
bool "GGML_BMI2"
59+
ignored "GGML_BUILD_EXAMPLES"
60+
ignored "GGML_BUILD_TESTS"
61+
filepath "GGML_CCACHE_FOUND"
62+
bool "GGML_CPU"
63+
bool "GGML_CPU_AARCH64"
64+
ignored "GGML_CPU_ALL_VARIANTS"
65+
string "GGML_CPU_ARM_ARCH"
66+
bool "GGML_CPU_HBM"
67+
bool "GGML_CPU_KLEIDIAI"
68+
string "GGML_CPU_POWERPC_CPUTYPE"
69+
bool "GGML_CUDA"
70+
string "GGML_CUDA_COMPRESSION_MODE"
71+
bool "GGML_CUDA_F16"
72+
bool "GGML_CUDA_FA"
73+
bool "GGML_CUDA_FA_ALL_QUANTS"
74+
bool "GGML_CUDA_FORCE_CUBLAS"
75+
bool "GGML_CUDA_FORCE_MMQ"
76+
ignored "GGML_CUDA_GRAPHS"
77+
bool "GGML_CUDA_NO_PEER_COPY"
78+
bool "GGML_CUDA_NO_VMM"
79+
string "GGML_CUDA_PEER_MAX_BATCH_SIZE"
80+
bool "GGML_F16C"
81+
bool "GGML_FMA"
82+
bool "GGML_GPROF"
83+
bool "GGML_HIP"
84+
bool "GGML_HIP_GRAPHS"
85+
bool "GGML_HIP_NO_VMM"
86+
bool "GGML_HIP_ROCWMMA_FATTN"
87+
bool "GGML_HIP_UMA"
88+
ignored "GGML_INCLUDE_INSTALL_DIR"
89+
bool "GGML_KOMPUTE"
90+
bool "GGML_LASX"
91+
ignored "GGML_LIB_INSTALL_DIR"
92+
ignored "GGML_LLAMAFILE"
93+
bool "GGML_LSX"
94+
bool "GGML_LTO"
95+
bool "GGML_METAL"
96+
bool "GGML_METAL_EMBED_LIBRARY"
97+
string "GGML_METAL_MACOSX_VERSION_MIN"
98+
bool "GGML_METAL_NDEBUG"
99+
bool "GGML_METAL_SHADER_DEBUG"
100+
string "GGML_METAL_STD"
101+
bool "GGML_METAL_USE_BF16"
102+
bool "GGML_MUSA"
103+
bool "GGML_NATIVE"
104+
bool "GGML_OPENCL"
105+
bool "GGML_OPENCL_EMBED_KERNELS"
106+
bool "GGML_OPENCL_PROFILING"
107+
string "GGML_OPENCL_TARGET_VERSION"
108+
bool "GGML_OPENCL_USE_ADRENO_KERNELS"
109+
bool "GGML_OPENMP"
110+
bool "GGML_RPC"
111+
bool "GGML_RVV"
112+
bool "GGML_RV_ZFH"
113+
pending "GGML_SCCACHE_FOUND"
114+
string "GGML_SCHED_MAX_COPIES"
115+
ignored "GGML_STATIC"
116+
bool "GGML_SYCL"
117+
string "GGML_SYCL_DEVICE_ARCH"
118+
bool "GGML_SYCL_F16"
119+
bool "GGML_SYCL_GRAPH"
120+
string "GGML_SYCL_TARGET"
121+
bool "GGML_VULKAN"
122+
bool "GGML_VULKAN_CHECK_RESULTS"
123+
bool "GGML_VULKAN_DEBUG"
124+
bool "GGML_VULKAN_MEMORY_DEBUG"
125+
bool "GGML_VULKAN_PERF"
126+
ignored "GGML_VULKAN_RUN_TESTS"
127+
filepath "GGML_VULKAN_SHADERS_GEN_TOOLCHAIN"
128+
bool "GGML_VULKAN_SHADER_DEBUG_INFO"
129+
pending "GGML_VULKAN_VALIDATE"
130+
bool "GGML_VXE"
131+
filepath "GIT_EXE"
132+
filepath "MATH_LIBRARY"
133+
filepath "METALKIT_FRAMEWORK"
134+
filepath "METAL_FRAMEWORK"
135+
bool "WHISPER_ALL_WARNINGS"
136+
bool "WHISPER_ALL_WARNINGS_3RD_PARTY"
137+
ignored "WHISPER_BIN_INSTALL_DIR"
138+
ignored "WHISPER_BUILD_EXAMPLES"
139+
ignored "WHISPER_BUILD_SERVER"
140+
ignored"WHISPER_BUILD_TESTS"
141+
bool "WHISPER_CCACHE"
142+
bool "WHISPER_COREML"
143+
bool "WHISPER_COREML_ALLOW_FALLBACK"
144+
ignored"WHISPER_CURL"
145+
bool "WHISPER_FATAL_WARNINGS"
146+
ignored "WHISPER_INCLUDE_INSTALL_DIR"
147+
ignored "WHISPER_LIB_INSTALL_DIR"
148+
bool "WHISPER_OPENVINO"
149+
bool "WHISPER_SANITIZE_ADDRESS"
150+
bool "WHISPER_SANITIZE_THREAD"
151+
bool "WHISPER_SANITIZE_UNDEFINED"
152+
ignored "WHISPER_SDL2"
153+
pending "WHISPER_USE_SYSTEM_GGML"
154+
end
155+
156+
def option_name(name)
157+
name.downcase.gsub("_", "-")
158+
end
159+
160+
def bool(name)
161+
option = option_name(name)
162+
value = enable_config(option)
163+
@configs[name] = [:bool, value]
164+
end
165+
166+
def string(name, type=:string)
167+
option = "--#{option_name(name)}"
168+
value = arg_config(option)
169+
raise "String expected for #{option}" if value == true || value&.empty?
170+
@configs[name] = [type, value]
171+
end
172+
173+
def path(name)
174+
string(name, :path)
175+
end
176+
177+
def filepath(name)
178+
string(name, :filepath)
179+
end
180+
181+
def pending(name)
182+
end
183+
184+
def ignored(name)
185+
end
186+
end

0 commit comments

Comments
 (0)