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
2224NPROC := $(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)
3540build-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# ============================================================================
6898build-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# ============================================================================
85121verify :
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# ============================================================================
97136clean :
98- rm -rf $(LLAMA_SRC ) out
137+ rm -rf $(LLAMA_SRC ) $( WHISPER_SRC ) out
0 commit comments