2024-05-22 20:02:52 +00:00
|
|
|
require 'rake/clean'
|
2024-10-16 15:44:04 +00:00
|
|
|
require "bundler/gem_tasks"
|
|
|
|
require "rake/testtask"
|
2024-11-21 15:04:29 +00:00
|
|
|
require_relative "extsources"
|
2024-10-16 15:44:04 +00:00
|
|
|
|
2024-10-28 13:43:27 +00:00
|
|
|
SOURCES = FileList[]
|
2024-11-21 15:04:29 +00:00
|
|
|
|
|
|
|
EXTSOURCES.each do |src|
|
2024-10-28 13:43:27 +00:00
|
|
|
basename = src.pathmap("%f")
|
2024-11-21 15:04:29 +00:00
|
|
|
dest = basename == "LICENSE" ? basename : src.pathmap("%{../..,ext}p")
|
|
|
|
dir = dest.pathmap("%d")
|
2024-10-28 13:43:27 +00:00
|
|
|
file src
|
2024-11-21 15:04:29 +00:00
|
|
|
directory dir
|
|
|
|
file dest => [src, dir] do |t|
|
2024-10-28 13:43:27 +00:00
|
|
|
cp t.source, t.name
|
2024-10-16 15:44:04 +00:00
|
|
|
end
|
2024-10-28 13:43:27 +00:00
|
|
|
SOURCES.include dest
|
2024-10-16 15:44:04 +00:00
|
|
|
end
|
2024-11-21 15:04:29 +00:00
|
|
|
|
2024-10-16 15:44:04 +00:00
|
|
|
CLEAN.include SOURCES
|
2024-12-09 11:17:50 +00:00
|
|
|
CLEAN.include FileList["ext/*.o", "ext/*.metal", "ext/whisper.{so,bundle,dll}"]
|
2024-10-16 15:44:04 +00:00
|
|
|
|
2024-12-09 11:17:50 +00:00
|
|
|
task build: ["ext/Makefile", "ext/ruby_whisper.h", "ext/ruby_whisper.cpp", "whispercpp.gemspec"]
|
2024-10-16 15:44:04 +00:00
|
|
|
|
|
|
|
directory "pkg"
|
|
|
|
CLOBBER.include "pkg"
|
|
|
|
|
|
|
|
LIB_NAME = "whisper".ext(RbConfig::CONFIG["DLEXT"])
|
2024-11-13 19:52:56 +00:00
|
|
|
SO_FILE = File.join("ext", LIB_NAME)
|
2024-10-16 15:44:04 +00:00
|
|
|
LIB_FILE = File.join("lib", LIB_NAME)
|
|
|
|
|
2024-11-13 19:52:56 +00:00
|
|
|
file "ext/Makefile" => ["ext/extconf.rb", "ext/ruby_whisper.h", "ext/ruby_whisper.cpp"] + SOURCES do |t|
|
|
|
|
Dir.chdir "ext" do
|
|
|
|
ruby "extconf.rb"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
file SO_FILE => "ext/Makefile" do |t|
|
2024-10-16 15:44:04 +00:00
|
|
|
Dir.chdir "ext" do
|
|
|
|
sh "make"
|
|
|
|
end
|
|
|
|
end
|
2024-12-18 09:00:50 +00:00
|
|
|
CLEAN.include SO_FILE
|
2024-10-16 15:44:04 +00:00
|
|
|
|
2024-11-13 19:52:56 +00:00
|
|
|
directory "lib"
|
|
|
|
file LIB_FILE => [SO_FILE, "lib"] do |t|
|
|
|
|
copy t.source, t.name
|
|
|
|
end
|
2024-12-18 09:00:50 +00:00
|
|
|
CLEAN.include LIB_FILE
|
2024-11-13 19:52:56 +00:00
|
|
|
|
2024-10-16 15:44:04 +00:00
|
|
|
Rake::TestTask.new do |t|
|
|
|
|
t.test_files = FileList["tests/test_*.rb"]
|
|
|
|
end
|
2024-11-28 08:33:07 +00:00
|
|
|
|
|
|
|
TEST_MEMORY_VIEW = "tests/jfk_reader/jfk_reader.#{RbConfig::CONFIG['DLEXT']}"
|
|
|
|
file TEST_MEMORY_VIEW => "tests/jfk_reader/jfk_reader.c" do |t|
|
|
|
|
Dir.chdir "tests/jfk_reader" do
|
|
|
|
ruby "extconf.rb"
|
|
|
|
sh "make"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
CLEAN.include "tests/jfk_reader/jfk_reader.{o,#{RbConfig::CONFIG['DLEXT']}}"
|
2024-12-18 09:00:50 +00:00
|
|
|
|
|
|
|
task test: [LIB_FILE, TEST_MEMORY_VIEW]
|