ggml : do not use _GNU_SOURCE gratuitously (#1027)

* 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.
This commit is contained in:
Przemysław Pawełczyk 2023-06-25 15:34:30 +02:00 committed by GitHub
parent 62642bb61c
commit 3f7a03ebe3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 10 additions and 18 deletions

View file

@ -36,11 +36,12 @@ CFLAGS = -I. -O3 -DNDEBUG -std=c11 -fPIC
CXXFLAGS = -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC CXXFLAGS = -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC
LDFLAGS = LDFLAGS =
# ref: https://github.com/ggerganov/whisper.cpp/issues/37 # clock_gettime came in POSIX.1b (1993)
ifneq ($(wildcard /usr/include/musl/*),) # CLOCK_MONOTONIC came in POSIX.1-2001 / SUSv3 as optional
CFLAGS += -D_POSIX_SOURCE -D_GNU_SOURCE # posix_memalign came in POSIX.1-2001 / SUSv3
CXXFLAGS += -D_POSIX_SOURCE -D_GNU_SOURCE # M_PI is an XSI extension since POSIX.1-2001 / SUSv3, came in XPG1 (1985)
endif CFLAGS += -D_XOPEN_SOURCE=600
CXXFLAGS += -D_XOPEN_SOURCE=600
# OS specific # OS specific
# TODO: support Windows # TODO: support Windows

View file

@ -6,8 +6,8 @@
// ref: https://github.com/ggerganov/whisper.cpp/issues/171 // ref: https://github.com/ggerganov/whisper.cpp/issues/171
// //
#include "common.h"
#include "common-sdl.h" #include "common-sdl.h"
#include "common.h"
#include "whisper.h" #include "whisper.h"
#include <sstream> #include <sstream>

View file

@ -3,8 +3,8 @@
// A very quick-n-dirty implementation serving mainly as a proof of concept. // A very quick-n-dirty implementation serving mainly as a proof of concept.
// //
#include "common.h"
#include "common-sdl.h" #include "common-sdl.h"
#include "common.h"
#include "whisper.h" #include "whisper.h"
#include <cassert> #include <cassert>

View 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-util.h"
#include "llama.h" #include "llama.h"

View file

@ -1,8 +1,8 @@
// Talk with AI // Talk with AI
// //
#include "common.h"
#include "common-sdl.h" #include "common-sdl.h"
#include "common.h"
#include "whisper.h" #include "whisper.h"
#include "llama.h" #include "llama.h"

View file

@ -1,8 +1,8 @@
// Talk with AI // Talk with AI
// //
#include "common.h"
#include "common-sdl.h" #include "common-sdl.h"
#include "common.h"
#include "whisper.h" #include "whisper.h"
#include "gpt-2.h" #include "gpt-2.h"

1
ggml.c
View file

@ -1,4 +1,3 @@
#define _GNU_SOURCE // Defines CLOCK_MONOTONIC on Linux
#define _CRT_SECURE_NO_DEPRECATE // Disables ridiculous "unsafe" warnigns on Windows #define _CRT_SECURE_NO_DEPRECATE // Disables ridiculous "unsafe" warnigns on Windows
#include "ggml.h" #include "ggml.h"