From ca35e76a2d5b8c115cc70ada1da830849a4051dc Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Wed, 18 Jun 2025 20:26:43 +0900 Subject: [PATCH 1/7] Add Apple frameworks to $LDFLAGS when needed --- bindings/ruby/ext/options.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bindings/ruby/ext/options.rb b/bindings/ruby/ext/options.rb index 03648fbf846..dd2aabe26a3 100644 --- a/bindings/ruby/ext/options.rb +++ b/bindings/ruby/ext/options.rb @@ -43,9 +43,31 @@ def configure @options[name] = [type, value] end + configure_accelerate + configure_metal configure_coreml end + # See ggml/src/ggml-cpu/CMakeLists.txt + def configure_accelerate + use_accelerate = if @options["GGML_ACCELERATE"][1].nil? + cmake_options["GGML_ACCELERATE"][1] + else + @options["GGML_ACCELERATE"][1] + end + $LDFLAGS << " -framework Accelerate" if use_accelerate + end + + # See ggml/src/ggml-metal/CMakeLists.txt + def configure_metal + use_metal = if @options["GGML_METAL"][1].nil? + cmake_options["GGML_METAL"][1] + else + @options["GGML_METAL"][1] + end + $LDFLAGS << " -framework Foundation -framework Metal -framework MetalKit" if use_metal + end + def configure_coreml use_coreml = if @options["WHISPER_COREML"][1].nil? cmake_options["WHISPER_COREML"][1] From 123d30ccb93f646c2d982dd2ba68514665b5ab1d Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Wed, 18 Jun 2025 20:41:03 +0900 Subject: [PATCH 2/7] Add utility method to Options --- bindings/ruby/ext/options.rb | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/bindings/ruby/ext/options.rb b/bindings/ruby/ext/options.rb index dd2aabe26a3..3ebad980b55 100644 --- a/bindings/ruby/ext/options.rb +++ b/bindings/ruby/ext/options.rb @@ -50,34 +50,27 @@ def configure # See ggml/src/ggml-cpu/CMakeLists.txt def configure_accelerate - use_accelerate = if @options["GGML_ACCELERATE"][1].nil? - cmake_options["GGML_ACCELERATE"][1] - else - @options["GGML_ACCELERATE"][1] - end - $LDFLAGS << " -framework Accelerate" if use_accelerate + $LDFLAGS << " -framework Accelerate" if enabled?("GGML_ACCELERATE") end # See ggml/src/ggml-metal/CMakeLists.txt def configure_metal - use_metal = if @options["GGML_METAL"][1].nil? - cmake_options["GGML_METAL"][1] - else - @options["GGML_METAL"][1] - end - $LDFLAGS << " -framework Foundation -framework Metal -framework MetalKit" if use_metal + $LDFLAGS << " -framework Foundation -framework Metal -framework MetalKit" if enabled?("GGML_METAL") end def configure_coreml - use_coreml = if @options["WHISPER_COREML"][1].nil? - cmake_options["WHISPER_COREML"][1] - else - @options["WHISPER_COREML"][1] - end - $CPPFLAGS << " -DRUBY_WHISPER_USE_COREML" if use_coreml + $CPPFLAGS << " -DRUBY_WHISPER_USE_COREML" if enabled?("WHISPER_COREML") end def option_name(name) name.downcase.gsub("_", "-") end + + def enabled?(option) + if @options[option][1].nil? + cmake_options[option][1] + else + @options[option][1] + end + end end From e2960e7c4d73de29375508a5b2e5c0034a4c910b Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 19 Jun 2025 03:09:37 +0900 Subject: [PATCH 3/7] Remove unnecessary propaty date from gemspec --- bindings/ruby/whispercpp.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/bindings/ruby/whispercpp.gemspec b/bindings/ruby/whispercpp.gemspec index 0a2a0c5fdab..c6e88dff7bd 100644 --- a/bindings/ruby/whispercpp.gemspec +++ b/bindings/ruby/whispercpp.gemspec @@ -4,7 +4,6 @@ Gem::Specification.new do |s| s.name = "whispercpp" s.authors = ["Georgi Gerganov", "Todd A. Fisher"] s.version = '1.3.3' - s.date = '2025-06-10' s.description = %q{High-performance inference of OpenAI's Whisper automatic speech recognition (ASR) model via Ruby} s.email = 'todd.fisher@gmail.com' s.extra_rdoc_files = ['LICENSE', 'README.md'] From 4116334ae5284fe8809ae69f6cf2c8bb8315a356 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Fri, 20 Jun 2025 11:39:40 +0900 Subject: [PATCH 4/7] Add Apple frameworks for CoreML build --- bindings/ruby/ext/options.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bindings/ruby/ext/options.rb b/bindings/ruby/ext/options.rb index 3ebad980b55..bb93fe86862 100644 --- a/bindings/ruby/ext/options.rb +++ b/bindings/ruby/ext/options.rb @@ -58,8 +58,12 @@ def configure_metal $LDFLAGS << " -framework Foundation -framework Metal -framework MetalKit" if enabled?("GGML_METAL") end + # See src/CmakeLists.txt def configure_coreml - $CPPFLAGS << " -DRUBY_WHISPER_USE_COREML" if enabled?("WHISPER_COREML") + if enabled?("WHISPER_COREML") + $LDFLAGS << " -framework Foundation -framework CoreML" + $CPPFLAGS << " -DRUBY_WHISPER_USE_COREML" + end end def option_name(name) From c624f220e1255739e37b9401cbd1f62173fea303 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Fri, 20 Jun 2025 12:33:31 +0900 Subject: [PATCH 5/7] Add Accelerate framework only for Apple platform --- bindings/ruby/ext/options.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bindings/ruby/ext/options.rb b/bindings/ruby/ext/options.rb index bb93fe86862..30cda0f8018 100644 --- a/bindings/ruby/ext/options.rb +++ b/bindings/ruby/ext/options.rb @@ -50,7 +50,9 @@ def configure # See ggml/src/ggml-cpu/CMakeLists.txt def configure_accelerate - $LDFLAGS << " -framework Accelerate" if enabled?("GGML_ACCELERATE") + if RUBY_PLATFORM.match?(/darwin/) && enabled?("GGML_ACCELERATE") + $LDFLAGS << " -framework Accelerate" + end end # See ggml/src/ggml-metal/CMakeLists.txt From e24288aa8087ee057d6485b45d4b2cc3f9052bf9 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sat, 21 Jun 2025 13:13:52 +0900 Subject: [PATCH 6/7] Fix ZipURI#cache signature --- bindings/ruby/lib/whisper/model/uri.rb | 4 ++-- bindings/ruby/sig/whisper.rbs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/ruby/lib/whisper/model/uri.rb b/bindings/ruby/lib/whisper/model/uri.rb index 31b608ac5fb..5bf5a098624 100644 --- a/bindings/ruby/lib/whisper/model/uri.rb +++ b/bindings/ruby/lib/whisper/model/uri.rb @@ -132,13 +132,13 @@ def format_bytesize(bytesize) class ZipURI < URI def cache - zip_path = Pathname(super) + zip_path = super dest = unzipped_path return if dest.exist? && dest.mtime >= zip_path.mtime escaping dest do system "unzip", "-q", "-d", zip_path.dirname.to_path, zip_path.to_path, exception: true end - zip_path.to_path + zip_path end def clear_cache diff --git a/bindings/ruby/sig/whisper.rbs b/bindings/ruby/sig/whisper.rbs index c73e6ad6c74..e6c0e139492 100644 --- a/bindings/ruby/sig/whisper.rbs +++ b/bindings/ruby/sig/whisper.rbs @@ -412,7 +412,7 @@ module Whisper end class ZipURI < URI - def cache: () -> String + def cache: () -> Pathname def clear_cache: () -> void end end From 0468074440b0590782e11a30500c958a1d743389 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sat, 21 Jun 2025 13:14:04 +0900 Subject: [PATCH 7/7] Download test fixtures if needed --- bindings/ruby/.gitignore | 1 + bindings/ruby/Rakefile | 19 +++++++++++++++++-- bindings/ruby/test/helper.rb | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/bindings/ruby/.gitignore b/bindings/ruby/.gitignore index 4bafb2220d3..54e3a2ac184 100644 --- a/bindings/ruby/.gitignore +++ b/bindings/ruby/.gitignore @@ -6,3 +6,4 @@ ext/ggml/ ext/include/ ext/scripts/ ext/src/ +test/fixtures/ diff --git a/bindings/ruby/Rakefile b/bindings/ruby/Rakefile index 08a2312a551..d9a66030de4 100644 --- a/bindings/ruby/Rakefile +++ b/bindings/ruby/Rakefile @@ -69,6 +69,21 @@ CLEAN.include LIB_FILE Rake::TestTask.new +TEST_FIXTURE_AUDIO = "test/fixtures/jfk.wav" +TEST_FIXTURE_AUDIO_SRC = File.expand_path(File.join(__dir__, "..", "..", "samples", "jfk.wav")) +TEST_FIXTURE_AUDIO_DIR = TEST_FIXTURE_AUDIO.pathmap("%d") +directory TEST_FIXTURE_AUDIO_DIR +if File.exist? TEST_FIXTURE_AUDIO_SRC + file TEST_FIXTURE_AUDIO => [TEST_FIXTURE_AUDIO_SRC, TEST_FIXTURE_AUDIO_DIR] do |t| + symlink t.source, t.name + end +else + require "open-uri" + file TEST_FIXTURE_AUDIO => TEST_FIXTURE_AUDIO_DIR do |t| + File.write t.name, URI("https://github.com/ggml-org/whisper.cpp/raw/refs/heads/master/samples/jfk.wav").read + end +end + TEST_MEMORY_VIEW = "test/jfk_reader/jfk_reader.#{RbConfig::CONFIG['DLEXT']}" file TEST_MEMORY_VIEW => "test/jfk_reader/jfk_reader.c" do |t| chdir "test/jfk_reader" do @@ -76,6 +91,6 @@ file TEST_MEMORY_VIEW => "test/jfk_reader/jfk_reader.c" do |t| sh "make" end end -CLEAN.include "test/jfk_reader/jfk_reader.{o,#{RbConfig::CONFIG['DLEXT']}}" +CLEAN.include TEST_MEMORY_VIEW -task test: [LIB_FILE, TEST_MEMORY_VIEW] +task test: [LIB_FILE, TEST_MEMORY_VIEW, TEST_FIXTURE_AUDIO] diff --git a/bindings/ruby/test/helper.rb b/bindings/ruby/test/helper.rb index 389e15c9c15..56cd3849fdd 100644 --- a/bindings/ruby/test/helper.rb +++ b/bindings/ruby/test/helper.rb @@ -3,7 +3,7 @@ require_relative "jfk_reader/jfk_reader" class TestBase < Test::Unit::TestCase - AUDIO = File.join(__dir__, "..", "..", "..", "samples", "jfk.wav") + AUDIO = File.join(__dir__, "fixtures", "jfk.wav") class << self def whisper