Skip to content

Commit 5b9997c

Browse files
committed
Follow whisper.cpp source tree change
1 parent 37c8802 commit 5b9997c

File tree

9 files changed

+85
-100
lines changed

9 files changed

+85
-100
lines changed

bindings/ruby/Rakefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
require 'rake/clean'
22
require "bundler/gem_tasks"
3-
require "pathname"
4-
require "yaml"
53
require "rake/testtask"
4+
require_relative "extsources"
65

7-
extsources = YAML.load_file("extsources.yaml")
86
SOURCES = FileList[]
9-
extsources.each do |src|
7+
8+
EXTSOURCES.each do |src|
109
basename = src.pathmap("%f")
11-
dest = basename == "LICENSE" ? basename : basename.pathmap("ext/%f")
10+
dest = if basename == "LICENSE"
11+
basename
12+
else
13+
src.pathmap("%{../..,ext}p")
14+
end
15+
dir = dest.pathmap("%d")
1216
file src
13-
file dest => src do |t|
17+
directory dir
18+
file dest => [src, dir] do |t|
1419
cp t.source, t.name
1520
end
1621
SOURCES.include dest
1722
end
23+
1824
CLEAN.include SOURCES
1925
CLEAN.include FileList[
2026
"ext/*.o",

bindings/ruby/ext/.gitignore

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,14 @@
11
Makefile
2-
ggml.c
3-
ggml.h
4-
ggml-alloc.c
5-
ggml-alloc.h
6-
ggml-aarch64.c
7-
ggml-aarch64.h
8-
ggml-backend.cpp
9-
ggml-backend-impl.h
10-
ggml-backend.c
11-
ggml-backend.h
12-
ggml-common.h
13-
ggml-cpu-impl.h
14-
ggml-metal.m
15-
ggml-metal.metal
16-
ggml-metal-embed.metal
17-
ggml-blas.cpp
18-
ggml-cuda.h
19-
ggml-impl.h
20-
ggml-kompute.h
21-
ggml-metal.h
22-
ggml-opencl.h
23-
ggml-quants.c
24-
ggml-quants.h
25-
ggml-sycl.h
26-
ggml-vulkan.h
27-
ggml-blas.h
28-
get-flags.mk
29-
whisper.cpp
30-
whisper.h
31-
dr_wav.h
32-
depend
33-
whisper.bundle
342
whisper.so
3+
whisper.bundle
354
whisper.dll
5+
depend
6+
scripts/get-flags.mk
7+
*.o
8+
*.c
9+
*.cpp
10+
*.h
11+
*.m
12+
*.metal
13+
!ruby_whisper.cpp
14+
!ruby_whisper.h

bindings/ruby/ext/cpu.mk

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ggml/src/ggml-cpu/ggml-cpu-cpp.o: \
2+
ggml/src/ggml-cpu/ggml-cpu.cpp \
3+
ggml/include/ggml-backend.h \
4+
ggml/include/ggml.h \
5+
ggml/include/ggml-alloc.h \
6+
ggml/src/ggml-backend-impl.h \
7+
ggml/include/ggml-cpu.h \
8+
ggml/src/ggml-impl.h
9+
$(CXX) $(CXXFLAGS) -c $< -o $@

bindings/ruby/ext/extconf.rb

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
$GGML_METAL_EMBED_LIBRARY = true
3636
end
3737

38-
$MK_CPPFLAGS = ''
38+
$MK_CPPFLAGS = '-Iggml/include -Iggml/src -Iinclude -Isrc -Iexamples'
3939
$MK_CFLAGS = '-std=c11 -fPIC'
4040
$MK_CXXFLAGS = '-std=c++11 -fPIC'
4141
$MK_NVCCFLAGS = '-std=c++11'
@@ -123,53 +123,59 @@
123123

124124
unless ENV['GGML_NO_ACCELERATE']
125125
if $UNAME_S == 'Darwin'
126-
$MK_CPPFLAGS << ' -DGGML_USE_ACCELERATE -DGGML_USE_BLAS'
126+
$MK_CPPFLAGS << ' -DGGML_USE_ACCELERATE -DGGML_USE_BLAS -DGGML_BLAS_USE_ACCELERATE'
127127
$MK_CPPFLAGS << ' -DACCELERATE_NEW_LAPACK'
128128
$MK_CPPFLAGS << ' -DACCELERATE_LAPACK_ILP64'
129129
$MK_LDFLAGS << ' -framework Accelerate'
130-
$OBJ_GGML << 'ggml-blas.o'
130+
$OBJ_GGML << 'ggml/src/ggml-blas/ggml-blas.o'
131131
end
132132
end
133133

134134
if ENV['GGML_OPENBLAS']
135135
$MK_CPPFLAGS << " -DGGML_USE_BLAS #{`pkg-config --cflags-only-I openblas`.chomp}"
136136
$MK_CFLAGS << " #{`pkg-config --cflags-only-other openblas)`.chomp}"
137137
$MK_LDFLAGS << " #{`pkg-config --libs openblas`}"
138-
$OBJ_GGML << 'ggml-blas.o'
138+
$OBJ_GGML << 'ggml/src/ggml-blas/ggml-blas.o'
139139
end
140140

141141
if ENV['GGML_OPENBLAS64']
142142
$MK_CPPFLAGS << " -DGGML_USE_BLAS #{`pkg-config --cflags-only-I openblas64`.chomp}"
143143
$MK_CFLAGS << " #{`pkg-config --cflags-only-other openblas64)`.chomp}"
144144
$MK_LDFLAGS << " #{`pkg-config --libs openblas64`}"
145-
$OBJ_GGML << 'ggml-blas.o'
145+
$OBJ_GGML << 'ggml/src/ggml-blas/ggml-blas.o'
146146
end
147147

148148
if $GGML_METAL
149149
$MK_CPPFLAGS << ' -DGGML_USE_METAL'
150150
$MK_LDFLAGS << ' -framework Foundation -framework Metal -framework MetalKit'
151-
$OBJ_GGML << 'ggml-metal.o'
151+
$OBJ_GGML << 'ggml/src/ggml-metal/ggml-metal.o'
152152

153153
if ENV['GGML_METAL_NDEBUG']
154154
$MK_CPPFLAGS << ' -DGGML_METAL_NDEBUG'
155155
end
156156

157157
if $GGML_METAL_EMBED_LIBRARY
158158
$MK_CPPFLAGS << ' -DGGML_METAL_EMBED_LIBRARY'
159-
$OBJ_GGML << 'ggml-metal-embed.o'
159+
$OBJ_GGML << 'ggml/src/ggml-metal/ggml-metal-embed.o'
160160
end
161161
end
162162

163163
$OBJ_GGML <<
164-
'ggml.o' <<
165-
'ggml-cpu.o' <<
166-
'ggml-alloc.o' <<
167-
'ggml-backend.o' <<
168-
'ggml-quants.o' <<
169-
'ggml-aarch64.o'
164+
'ggml/src/ggml.o' <<
165+
'ggml/src/ggml-aarch64.o' <<
166+
'ggml/src/ggml-alloc.o' <<
167+
'ggml/src/ggml-backend.o' <<
168+
'ggml/src/ggml-backend-reg.o' <<
169+
'ggml/src/ggml-opt.o' <<
170+
'ggml/src/ggml-quants.o' <<
171+
'ggml/src/ggml-threading.o' <<
172+
'ggml/src/ggml-cpu/ggml-cpu.o' <<
173+
'ggml/src/ggml-cpu/ggml-cpu-cpp.o' <<
174+
'ggml/src/ggml-cpu/ggml-cpu-aarch64.o' <<
175+
'ggml/src/ggml-cpu/ggml-cpu-quants.o'
170176

171177
$OBJ_WHISPER <<
172-
'whisper.o'
178+
'src/whisper.o'
173179

174180
$objs = $OBJ_GGML + $OBJ_WHISPER + $OBJ_COMMON + $OBJ_SDL
175181
$objs << "ruby_whisper.o"
@@ -184,9 +190,12 @@
184190
create_makefile('whisper')
185191

186192
File.open 'Makefile', 'a' do |file|
187-
file.puts 'include get-flags.mk'
193+
file.puts 'include scripts/get-flags.mk'
194+
file.puts 'include cpu.mk'
188195

189196
if $GGML_METAL
197+
file.puts 'include metal.mk'
198+
190199
if $GGML_METAL_EMBED_LIBRARY
191200
file.puts 'include metal-embed.mk'
192201
end

bindings/ruby/ext/metal-embed.mk

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
ggml-metal-embed.o: \
2-
ggml-metal.metal \
3-
ggml-common.h
1+
ggml/src/ggml-metal/ggml-metal-embed.o: \
2+
ggml/src/ggml-metal/ggml-metal.metal \
3+
ggml/src/ggml-metal/ggml-metal-impl.h \
4+
ggml/src/ggml-common.h
45
@echo "Embedding Metal library"
5-
@sed -e '/#include "ggml-common.h"/r ggml-common.h' -e '/#include "ggml-common.h"/d' < ggml-metal.metal > ggml-metal-embed.metal
6-
$(eval TEMP_ASSEMBLY=$(shell mktemp))
7-
@echo ".section __DATA, __ggml_metallib" > $(TEMP_ASSEMBLY)
8-
@echo ".globl _ggml_metallib_start" >> $(TEMP_ASSEMBLY)
9-
@echo "_ggml_metallib_start:" >> $(TEMP_ASSEMBLY)
10-
@echo ".incbin \"ggml-metal-embed.metal\"" >> $(TEMP_ASSEMBLY)
11-
@echo ".globl _ggml_metallib_end" >> $(TEMP_ASSEMBLY)
12-
@echo "_ggml_metallib_end:" >> $(TEMP_ASSEMBLY)
13-
@$(AS) $(TEMP_ASSEMBLY) -o $@
14-
@rm -f ${TEMP_ASSEMBLY}
6+
@sed -e '/__embed_ggml-common.h__/r ggml/src/ggml-common.h' -e '/__embed_ggml-common.h__/d' < ggml/src/ggml-metal/ggml-metal.metal > ggml/src/ggml-metal/ggml-metal-embed.metal.tmp
7+
@sed -e '/#include "ggml-metal-impl.h"/r ggml/src/ggml-metal/ggml-metal-impl.h' -e '/#include "ggml-metal-impl.h"/d' < ggml/src/ggml-metal/ggml-metal-embed.metal.tmp > ggml/src/ggml-metal/ggml-metal-embed.metal
8+
$(eval TEMP_ASSEMBLY=$(shell mktemp -d))
9+
@echo ".section __DATA, __ggml_metallib" > $(TEMP_ASSEMBLY)/ggml-metal-embed.s
10+
@echo ".globl _ggml_metallib_start" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
11+
@echo "_ggml_metallib_start:" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
12+
@echo ".incbin \"ggml/src/ggml-metal/ggml-metal-embed.metal\"" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
13+
@echo ".globl _ggml_metallib_end" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
14+
@echo "_ggml_metallib_end:" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
15+
$(CC) $(CFLAGS) -c $(TEMP_ASSEMBLY)/ggml-metal-embed.s -o $@
16+
@rm -f ${TEMP_ASSEMBLY}/ggml-metal-embed.s
17+
@rmdir ${TEMP_ASSEMBLY}

bindings/ruby/ext/metal.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ggml/src/ggml-metal/ggml-metal.o: \
2+
ggml/src/ggml-metal/ggml-metal.m \
3+
ggml/src/ggml-metal/ggml-metal-impl.h \
4+
ggml/include/ggml-metal.h \
5+
ggml/include/ggml.h
6+
$(CC) $(CFLAGS) -c $< -o $@

bindings/ruby/extsources.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
EXTSOURCES = `git ls-files -z ../..`.split("\x0").grep(%r{\A\.\./\.\./(?:src|include|ggml).+\.(c|cpp|h|m|metal)\z}) <<
2+
"../../examples/dr_wav.h" <<
3+
"../../scripts/get-flags.mk" <<
4+
"../../LICENSE"

bindings/ruby/extsources.yaml

Lines changed: 0 additions & 31 deletions
This file was deleted.

bindings/ruby/whispercpp.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "yaml"
1+
require_relative "extsources"
22

33
Gem::Specification.new do |s|
44
s.name = "whispercpp"
@@ -10,12 +10,12 @@ Gem::Specification.new do |s|
1010
s.extra_rdoc_files = ['LICENSE', 'README.md']
1111

1212
s.files = `git ls-files . -z`.split("\x0") +
13-
YAML.load_file("extsources.yaml").collect {|file|
13+
EXTSOURCES.collect {|file|
1414
basename = File.basename(file)
1515
if s.extra_rdoc_files.include?(basename)
1616
basename
1717
else
18-
File.join("ext", basename)
18+
file.sub("../..", "ext")
1919
end
2020
}
2121

0 commit comments

Comments
 (0)