Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MUSL Linux build #576

Merged
merged 1 commit into from Mar 22, 2023
Merged

Fix MUSL Linux build #576

merged 1 commit into from Mar 22, 2023

Conversation

ggerganov
Copy link
Owner

close #37

@mikeslattery Could you please check if this works on MUSL Linux?

@mikeslattery
Copy link

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

@mikeslattery
Copy link

mikeslattery commented Mar 6, 2023

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

@ggerganov
Copy link
Owner Author

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

@mikeslattery
Copy link

mikeslattery commented Mar 7, 2023

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.

@aarnphm
Copy link
Contributor

aarnphm commented Mar 8, 2023

Currently, I have a job to build the binary for MUSL python wheel and seems like it fails as well. 🤔

@ggerganov ggerganov marked this pull request as ready for review March 22, 2023 18:51
@ggerganov
Copy link
Owner Author

Added the suggestion by ChatGPT

@ggerganov ggerganov merged commit 4aa3bcf into master Mar 22, 2023
13 of 28 checks passed
@ggerganov ggerganov deleted the musl branch March 22, 2023 18:51
anandijain pushed a commit to anandijain/whisper.cpp that referenced this pull request Apr 28, 2023
jacobwu-b pushed a commit to jacobwu-b/Transcriptify-by-whisper.cpp that referenced this pull request Oct 24, 2023
jacobwu-b pushed a commit to jacobwu-b/Transcriptify-by-whisper.cpp that referenced this pull request Oct 24, 2023
landtanin pushed a commit to landtanin/whisper.cpp that referenced this pull request Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MUSL Linux builds
3 participants