whisper.cpp
whisper.cpp copied to clipboard
Fix MUSL Linux build
close #37
@mikeslattery Could you please check if this works on MUSL Linux?
It did not. However, when I commented out the ifneq
it did. $(CCV)
is the CC
value below:
I whisper.cpp build info:
I UNAME_S: Linux
I UNAME_P: unknown
I UNAME_M: x86_64
I CFLAGS: -I. -O3 -DNDEBUG -std=c11 -fPIC -pthread -mavx -mavx2 -mfma -mf16c -msse3
I CXXFLAGS: -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC -pthread
I LDFLAGS:
I CC: cc (Alpine 12.2.1_git20220924-r4) 12.2.1 20220924
I CXX: g++ (Alpine 12.2.1_git20220924-r4) 12.2.1 20220924
I don't know if this helps, but this is how I build:
FROM alpine:3.17.2 AS alpine0
RUN mkdir /whisper && \
wget -q https://github.com/masterful/whisper.cpp/tarball/master -O - | \
tar -xz -C /whisper --strip-components 1
# git alternative
# RUN apk add git &&
# git clone --depth 1 https://github.com/ggerganov/whisper.cpp.git /whisper
WORKDIR /whisper
RUN apk add --quiet g++ make bash wget sdl2-dev alsa-utils
# Workaround build
RUN cat > Makefile.musl <<MAKEFILE
CFLAGS += -D_POSIX_SOURCE -D_GNU_SOURCE
CXXFLAGS += -D_POSIX_SOURCE -D_GNU_SOURCE
MAKEFILE
RUN make -f Makefile -f Makefile.musl main stream command talk bench
# Once workaround is no longer necessary
# RUN make main stream command talk bench
RUN bash ./models/download-ggml-model.sh base.en
FROM alpine:3.17.2
COPY --from=alpine0 /whisper/main /usr/local/bin/whisper
COPY --from=alpine0 /whisper/stream /usr/local/bin/stream
COPY --from=alpine0 /whisper/talk /usr/local/bin/talk
COPY --from=alpine0 /whisper/command /usr/local/bin/wcommand
RUN mkdir /root/models
COPY --from=alpine0 /whisper/models/ggml-base.en.bin /root/models/ggml-base.en.bin
RUN apk add --quiet sdl2-dev alsa-utils
WORKDIR /root
# To use stream in a container (linux hosts only):
# docker build . -t whisper
# docker run -it --rm --device /dev/snd:/dev/snd whisper stream
Then to extract binaries
docker build -t whispercpp .
docker create --name whispercpp whispercpp
docker cp whispercpp:/usr/local/bin/whisper whisper
docker cp whispercpp:/usr/local/bin/stream wstream
docker cp whispercpp:/root/models/ggml-base.en.bin ggml-base.en.bin
docker rm whispercpp
Directly adding -D_POSIX_SOURCE -D_GNU_SOURCE
to the flags is not desired since it breaks the build for other systems. We need a way to detect MUSL in the Makefile
We need a way to detect MUSL in the Makefile
I asked ChatGPT
List 3 ways within a makefile how you can detect if the system uses musl instead of libc
ifneq ($(wildcard /usr/include/musl/*),)
CFLAGS += -D_POSIX_SOURCE -D_GNU_SOURCE
CXXFLAGS += -D_POSIX_SOURCE -D_GNU_SOURCE
endif
ifeq ($(shell ldd /bin/ls | grep -q musl && echo true),true)
endif
ifeq ($(shell pkg-config --exists musl && echo true),true)
endif
I tested the first and it worked.
Currently, I have a job to build the binary for MUSL python wheel and seems like it fails as well. 🤔
Added the suggestion by ChatGPT