Skip to content

Commit b4e5ebc

Browse files
Merge pull request #2 from FootprintAI/feat---whispercpp
feat: add whisper.cpp. use go:embed to archive .a and .h files
2 parents a2c88a5 + 1436b6c commit b4e5ebc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+5761
-46
lines changed

.github/workflows/ci.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
go-version: "1.24"
4040
- name: Build with CGO (llamacpp tag)
4141
run: CGO_ENABLED=1 go build -tags llamacpp ./ggml/llamacpp/...
42+
- name: Build with CGO (whispercpp tag)
43+
run: CGO_ENABLED=1 go build -tags whispercpp ./ggml/whispercpp/...
4244

4345
build-libs:
4446
name: Build Libraries from Source (${{ matrix.os }})
@@ -68,9 +70,16 @@ jobs:
6870
- name: Build static libraries from source
6971
run: make build-libs
7072
- name: Verify CGO build with fresh libraries
71-
run: CGO_ENABLED=1 go build -tags llamacpp ./ggml/llamacpp/...
72-
- name: Upload prebuilt artifacts
73+
run: |
74+
CGO_ENABLED=1 go build -tags llamacpp ./ggml/llamacpp/...
75+
CGO_ENABLED=1 go build -tags whispercpp ./ggml/whispercpp/...
76+
- name: Upload llama.cpp prebuilt artifacts
77+
uses: actions/upload-artifact@v4
78+
with:
79+
name: prebuilt-llamacpp-${{ matrix.platform }}
80+
path: ggml/llamacpp/third_party/prebuilt/${{ matrix.platform }}/*.a
81+
- name: Upload whisper.cpp prebuilt artifacts
7382
uses: actions/upload-artifact@v4
7483
with:
75-
name: prebuilt-${{ matrix.platform }}
76-
path: third_party/llama.cpp/prebuilt/${{ matrix.platform }}/*.a
84+
name: prebuilt-whispercpp-${{ matrix.platform }}
85+
path: ggml/whispercpp/third_party/prebuilt/${{ matrix.platform }}/*.a

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Build artifacts (source downloads, cmake dirs)
2-
third_party/llama.cpp/src/
3-
third_party/whisper.cpp/src/
4-
third_party/**/build/
2+
ggml/llamacpp/third_party/src/
3+
ggml/whispercpp/third_party/src/
4+
**/build/
55
out/
66

77
# Prebuilt .a files and headers ARE committed — do not ignore them

Dockerfile.libs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Dockerfile.libs — build linux-amd64 static libraries for llama.cpp
1+
# Dockerfile.libs — build linux-amd64 static libraries for llama.cpp and whisper.cpp
22
#
33
# Usage:
44
# docker build -f Dockerfile.libs -o ./out .
@@ -18,27 +18,46 @@ COPY go.mod ./
1818
COPY version.go ./
1919
COPY cmd/versioncmd/ ./cmd/versioncmd/
2020

21-
# Read versions and download sources
21+
# Download llama.cpp
2222
RUN LLAMA_VERSION=$(go run ./cmd/versioncmd llama.cpp) && \
2323
echo "Downloading llama.cpp ${LLAMA_VERSION}..." && \
2424
wget -qO llama.cpp.tar.gz "https://github.com/ggerganov/llama.cpp/archive/refs/tags/${LLAMA_VERSION}.tar.gz" && \
2525
mkdir -p llama-src && \
2626
tar xzf llama.cpp.tar.gz --strip-components=1 -C llama-src && \
2727
rm llama.cpp.tar.gz
2828

29+
# Download whisper.cpp
30+
RUN WHISPER_VERSION=$(go run ./cmd/versioncmd whisper.cpp) && \
31+
echo "Downloading whisper.cpp ${WHISPER_VERSION}..." && \
32+
wget -qO whisper.cpp.tar.gz "https://github.com/ggerganov/whisper.cpp/archive/refs/tags/${WHISPER_VERSION}.tar.gz" && \
33+
mkdir -p whisper-src && \
34+
tar xzf whisper.cpp.tar.gz --strip-components=1 -C whisper-src && \
35+
rm whisper.cpp.tar.gz
36+
2937
# Build llama.cpp
3038
RUN cd llama-src && \
3139
cmake -B build -DBUILD_SHARED_LIBS=OFF && \
3240
cmake --build build --config Release -j$(nproc)
3341

34-
# Collect artifacts
42+
# Build whisper.cpp
43+
RUN cd whisper-src && \
44+
cmake -B build -DBUILD_SHARED_LIBS=OFF && \
45+
cmake --build build --config Release -j$(nproc)
46+
47+
# Collect llama.cpp artifacts
3548
RUN mkdir -p /out/llama.cpp/linux-amd64 /out/llama.cpp/include /out/llama.cpp/ggml/include /out/llama.cpp/common && \
3649
find llama-src/build -name "*.a" -exec cp {} /out/llama.cpp/linux-amd64/ \; && \
3750
cp llama-src/include/*.h /out/llama.cpp/include/ && \
3851
cp llama-src/ggml/include/*.h /out/llama.cpp/ggml/include/ && \
3952
cp llama-src/common/common.h /out/llama.cpp/common/ && \
4053
cp llama-src/common/sampling.h /out/llama.cpp/common/
4154

55+
# Collect whisper.cpp artifacts
56+
RUN mkdir -p /out/whisper.cpp/linux-amd64 /out/whisper.cpp/include /out/whisper.cpp/ggml/include && \
57+
find whisper-src/build -name "*.a" -exec cp {} /out/whisper.cpp/linux-amd64/ \; && \
58+
cp whisper-src/include/*.h /out/whisper.cpp/include/ && \
59+
cp whisper-src/ggml/include/*.h /out/whisper.cpp/ggml/include/
60+
4261
# Output stage — docker build -o extracts from here
4362
FROM scratch
4463
COPY --from=builder /out/ /

Makefile

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
#
33
# For consumers:
44
# go get github.com/footprintai/go-nativeml
5-
# go build -tags llamacpp ./... # just works — prebuilt .a files are in the module
5+
# go build -tags llamacpp ./... # just works — prebuilt .a files are in the module
6+
# go build -tags whispercpp ./... # whisper.cpp bindings
67
#
78
# For maintainers (rebuild .a files from source):
89
# make build-libs # Build all libraries for current platform
910
# make build-libs-llama # Build llama.cpp only
11+
# make build-libs-whisper # Build whisper.cpp only
1012
# make build-libs-linux # Build linux-amd64 .a files via Docker
1113
# make build-libs-all # Build native + linux-amd64
1214
# make clean # Remove temp build dirs (keeps prebuilt .a + headers)
@@ -21,15 +23,18 @@ PLATFORM := $(shell go env GOOS)-$(shell go env GOARCH)
2123
# Parallel build cores
2224
NPROC := $(shell if which nproc > /dev/null 2>&1; then nproc; elif [ "$$(uname)" = "Darwin" ]; then sysctl -n hw.ncpu; else echo 4; fi)
2325

24-
# Paths
25-
THIRD_PARTY := third_party
26-
LLAMA_DIR := $(THIRD_PARTY)/llama.cpp
27-
LLAMA_SRC := $(LLAMA_DIR)/src
28-
LLAMA_PREBUILT := $(LLAMA_DIR)/prebuilt/$(PLATFORM)
26+
# Paths — assets live inside the Go package directories
27+
LLAMA_THIRD_PARTY := ggml/llamacpp/third_party
28+
LLAMA_SRC := $(LLAMA_THIRD_PARTY)/src
29+
LLAMA_PREBUILT := $(LLAMA_THIRD_PARTY)/prebuilt/$(PLATFORM)
2930

30-
.PHONY: build-libs build-libs-llama build-libs-linux build-libs-all clean verify
31+
WHISPER_THIRD_PARTY := ggml/whispercpp/third_party
32+
WHISPER_SRC := $(WHISPER_THIRD_PARTY)/src
33+
WHISPER_PREBUILT := $(WHISPER_THIRD_PARTY)/prebuilt/$(PLATFORM)
3134

32-
build-libs: build-libs-llama
35+
.PHONY: build-libs build-libs-llama build-libs-whisper build-libs-linux build-libs-all clean verify
36+
37+
build-libs: build-libs-llama build-libs-whisper
3338

3439
# Build both native platform and linux-amd64 (via Docker)
3540
build-libs-all: build-libs build-libs-linux
@@ -46,13 +51,13 @@ $(LLAMA_PREBUILT): $(LLAMA_SRC)
4651
@mkdir -p $(LLAMA_PREBUILT)
4752
find $(LLAMA_SRC)/build -name "*.a" -exec cp {} $(LLAMA_PREBUILT)/ \;
4853
@echo "==> Copying llama.cpp headers..."
49-
@mkdir -p $(LLAMA_DIR)/include
50-
cp $(LLAMA_SRC)/include/*.h $(LLAMA_DIR)/include/
51-
@mkdir -p $(LLAMA_DIR)/ggml/include
52-
cp $(LLAMA_SRC)/ggml/include/*.h $(LLAMA_DIR)/ggml/include/
53-
@mkdir -p $(LLAMA_DIR)/common
54-
cp $(LLAMA_SRC)/common/common.h $(LLAMA_DIR)/common/
55-
cp $(LLAMA_SRC)/common/sampling.h $(LLAMA_DIR)/common/
54+
@mkdir -p $(LLAMA_THIRD_PARTY)/include
55+
cp $(LLAMA_SRC)/include/*.h $(LLAMA_THIRD_PARTY)/include/
56+
@mkdir -p $(LLAMA_THIRD_PARTY)/ggml/include
57+
cp $(LLAMA_SRC)/ggml/include/*.h $(LLAMA_THIRD_PARTY)/ggml/include/
58+
@mkdir -p $(LLAMA_THIRD_PARTY)/common
59+
cp $(LLAMA_SRC)/common/common.h $(LLAMA_THIRD_PARTY)/common/
60+
cp $(LLAMA_SRC)/common/sampling.h $(LLAMA_THIRD_PARTY)/common/
5661
@echo "==> llama.cpp $(LLAMA_VERSION) ready: $(LLAMA_PREBUILT)/"
5762

5863
$(LLAMA_SRC):
@@ -62,37 +67,71 @@ $(LLAMA_SRC):
6267
tar xzf llama.cpp.tar.gz --strip-components=1 -C $(LLAMA_SRC)
6368
rm llama.cpp.tar.gz
6469

70+
# ============================================================================
71+
# whisper.cpp
72+
# ============================================================================
73+
build-libs-whisper: $(WHISPER_PREBUILT)
74+
75+
$(WHISPER_PREBUILT): $(WHISPER_SRC)
76+
@echo "==> Building whisper.cpp $(WHISPER_VERSION) for $(PLATFORM)..."
77+
cd $(WHISPER_SRC) && cmake -B build -DBUILD_SHARED_LIBS=OFF && \
78+
cmake --build build --config Release -j$(NPROC)
79+
@mkdir -p $(WHISPER_PREBUILT)
80+
find $(WHISPER_SRC)/build -name "*.a" -exec cp {} $(WHISPER_PREBUILT)/ \;
81+
@echo "==> Copying whisper.cpp headers..."
82+
@mkdir -p $(WHISPER_THIRD_PARTY)/include
83+
cp $(WHISPER_SRC)/include/*.h $(WHISPER_THIRD_PARTY)/include/
84+
@mkdir -p $(WHISPER_THIRD_PARTY)/ggml/include
85+
cp $(WHISPER_SRC)/ggml/include/*.h $(WHISPER_THIRD_PARTY)/ggml/include/
86+
@echo "==> whisper.cpp $(WHISPER_VERSION) ready: $(WHISPER_PREBUILT)/"
87+
88+
$(WHISPER_SRC):
89+
@echo "==> Downloading whisper.cpp $(WHISPER_VERSION)..."
90+
wget -qO whisper.cpp.tar.gz https://github.com/ggerganov/whisper.cpp/archive/refs/tags/$(WHISPER_VERSION).tar.gz
91+
mkdir -p $(WHISPER_SRC)
92+
tar xzf whisper.cpp.tar.gz --strip-components=1 -C $(WHISPER_SRC)
93+
rm whisper.cpp.tar.gz
94+
6595
# ============================================================================
6696
# Docker build for linux-amd64 (cross-compile from macOS)
6797
# ============================================================================
6898
build-libs-linux:
6999
@echo "==> Building linux-amd64 static libraries via Docker..."
70100
docker build -f Dockerfile.libs -o ./out .
71-
@mkdir -p $(LLAMA_DIR)/prebuilt/linux-amd64
72-
cp out/llama.cpp/linux-amd64/*.a $(LLAMA_DIR)/prebuilt/linux-amd64/
73-
@# Copy headers if not already present
74-
@mkdir -p $(LLAMA_DIR)/include $(LLAMA_DIR)/ggml/include $(LLAMA_DIR)/common
75-
cp out/llama.cpp/include/*.h $(LLAMA_DIR)/include/
76-
cp out/llama.cpp/ggml/include/*.h $(LLAMA_DIR)/ggml/include/
77-
cp out/llama.cpp/common/common.h $(LLAMA_DIR)/common/
78-
cp out/llama.cpp/common/sampling.h $(LLAMA_DIR)/common/
101+
@# llama.cpp
102+
@mkdir -p $(LLAMA_THIRD_PARTY)/prebuilt/linux-amd64
103+
cp out/llama.cpp/linux-amd64/*.a $(LLAMA_THIRD_PARTY)/prebuilt/linux-amd64/
104+
@mkdir -p $(LLAMA_THIRD_PARTY)/include $(LLAMA_THIRD_PARTY)/ggml/include $(LLAMA_THIRD_PARTY)/common
105+
cp out/llama.cpp/include/*.h $(LLAMA_THIRD_PARTY)/include/
106+
cp out/llama.cpp/ggml/include/*.h $(LLAMA_THIRD_PARTY)/ggml/include/
107+
cp out/llama.cpp/common/common.h $(LLAMA_THIRD_PARTY)/common/
108+
cp out/llama.cpp/common/sampling.h $(LLAMA_THIRD_PARTY)/common/
109+
@# whisper.cpp
110+
@mkdir -p $(WHISPER_THIRD_PARTY)/prebuilt/linux-amd64
111+
cp out/whisper.cpp/linux-amd64/*.a $(WHISPER_THIRD_PARTY)/prebuilt/linux-amd64/
112+
@mkdir -p $(WHISPER_THIRD_PARTY)/include $(WHISPER_THIRD_PARTY)/ggml/include
113+
cp out/whisper.cpp/include/*.h $(WHISPER_THIRD_PARTY)/include/
114+
cp out/whisper.cpp/ggml/include/*.h $(WHISPER_THIRD_PARTY)/ggml/include/
79115
rm -rf out
80116
@echo "==> linux-amd64 libraries ready"
81117

82118
# ============================================================================
83119
# Verification
84120
# ============================================================================
85121
verify:
86-
@echo "==> Verifying stub build (no tag)..."
122+
@echo "==> Verifying stub builds (no tags)..."
87123
go build ./ggml/llamacpp/...
88-
@echo "==> Verifying CGO build (with tag)..."
124+
go build ./ggml/whispercpp/...
125+
@echo "==> Verifying CGO builds (with tags)..."
89126
CGO_ENABLED=1 go build -tags llamacpp ./ggml/llamacpp/...
127+
CGO_ENABLED=1 go build -tags whispercpp ./ggml/whispercpp/...
90128
@echo "==> Running stub tests..."
91129
go test ./ggml/llamacpp/...
130+
go test ./ggml/whispercpp/...
92131
@echo "==> All checks passed"
93132

94133
# ============================================================================
95134
# Cleanup
96135
# ============================================================================
97136
clean:
98-
rm -rf $(LLAMA_SRC) out
137+
rm -rf $(LLAMA_SRC) $(WHISPER_SRC) out

0 commit comments

Comments
 (0)