]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
ggml : do not use _GNU_SOURCE gratuitously (#1027)
authorPrzemysław Pawełczyk <redacted>
Sun, 25 Jun 2023 13:34:30 +0000 (15:34 +0200)
committerGitHub <redacted>
Sun, 25 Jun 2023 13:34:30 +0000 (16:34 +0300)
* Do not use _GNU_SOURCE gratuitously.

What is needed to build whisper.cpp and examples is availability of
stuff defined in The Open Group Base Specifications Issue 6
(https://pubs.opengroup.org/onlinepubs/009695399/) known also as
Single Unix Specification v3 (SUSv3) or POSIX.1-2001 + XSI extensions.

There is no need to penalize musl libc which simply follows standards.

Not having feature test macros in source code gives greater flexibility
to those wanting to reuse it in 3rd party app, as they can build it with
minimal FTM (_XOPEN_SOURCE=600) or other FTM depending on their needs.

It builds without issues in Alpine (musl libc), Ubuntu (glibc), MSYS2.

* examples : include SDL headers before other headers

This is an attempt at fixing macOS build error coming from SDL2 relying
on Darwin extension memset_pattern4/8/16 coming from Apple's string.h.

Makefile
examples/command/command.cpp
examples/stream/stream.cpp
examples/talk-llama/llama.cpp
examples/talk-llama/talk-llama.cpp
examples/talk/talk.cpp
ggml.c

index 73e1c5fc729d8e6fc48b78edc99c080cfc43a4f2..c7b05a9a6d9903db4f051ce8185fd1fadf38fb41 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -36,11 +36,12 @@ CFLAGS   = -I.              -O3 -DNDEBUG -std=c11   -fPIC
 CXXFLAGS = -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC
 LDFLAGS  =
 
-# ref: https://github.com/ggerganov/whisper.cpp/issues/37
-ifneq ($(wildcard /usr/include/musl/*),)
-       CFLAGS += -D_POSIX_SOURCE -D_GNU_SOURCE
-       CXXFLAGS += -D_POSIX_SOURCE -D_GNU_SOURCE
-endif
+# clock_gettime came in POSIX.1b (1993)
+# CLOCK_MONOTONIC came in POSIX.1-2001 / SUSv3 as optional
+# posix_memalign came in POSIX.1-2001 / SUSv3
+# M_PI is an XSI extension since POSIX.1-2001 / SUSv3, came in XPG1 (1985)
+CFLAGS   += -D_XOPEN_SOURCE=600
+CXXFLAGS += -D_XOPEN_SOURCE=600
 
 # OS specific
 # TODO: support Windows
index 54e3549f3bc6884ddca22c97dc0b8efddaec54de..d39af7309a29cc4e25a0290a9f7913a42b1e7b77 100644 (file)
@@ -6,8 +6,8 @@
 // ref: https://github.com/ggerganov/whisper.cpp/issues/171
 //
 
-#include "common.h"
 #include "common-sdl.h"
+#include "common.h"
 #include "whisper.h"
 
 #include <sstream>
index cec5a2b7ce5974a5d0c18b0bf2d935d23ef736e3..e44c1f60e25b34f88c49e0ebe87fc8b4966fd9b0 100644 (file)
@@ -3,8 +3,8 @@
 // A very quick-n-dirty implementation serving mainly as a proof of concept.
 //
 
-#include "common.h"
 #include "common-sdl.h"
+#include "common.h"
 #include "whisper.h"
 
 #include <cassert>
index 942407b84a3f3234c1f6f175c2c2758fe5a118f6..04d78e03bb8b4119565d06e65b876359c19afcb8 100644 (file)
@@ -1,11 +1,3 @@
-// Defines fileno on msys:
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#include <cstddef>
-#include <cstdint>
-#include <cstdio>
-#endif
-
 #include "llama-util.h"
 #include "llama.h"
 
index 57a02eacf627068d0092641a4c51e8e652c63504..18658669a8a4244a255b34e4bc89e9d335979a0d 100644 (file)
@@ -1,8 +1,8 @@
 // Talk with AI
 //
 
-#include "common.h"
 #include "common-sdl.h"
+#include "common.h"
 #include "whisper.h"
 #include "llama.h"
 
index 651ca2008f3e426d063bd1f625c7d5b2e0415605..12d98a0033b2a7b64ed8fdee01edd616b03c8100 100644 (file)
@@ -1,8 +1,8 @@
 // Talk with AI
 //
 
-#include "common.h"
 #include "common-sdl.h"
+#include "common.h"
 #include "whisper.h"
 #include "gpt-2.h"
 
diff --git a/ggml.c b/ggml.c
index 955f335cd18275174f2e3b338db013dc70aa7c2d..9dcaafa9605b63b3a64cf27c2f195e8bbdbd2038 100644 (file)
--- a/ggml.c
+++ b/ggml.c
@@ -1,4 +1,3 @@
-#define _GNU_SOURCE // Defines CLOCK_MONOTONIC on Linux
 #define _CRT_SECURE_NO_DEPRECATE // Disables ridiculous "unsafe" warnigns on Windows
 
 #include "ggml.h"