From b7d4d9f519342669406874b78fbcf7f28384f39a Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Thu, 1 Jun 2023 18:50:02 -0400 Subject: [PATCH] getopt: fix build on clang 16 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Normally, when getopt builds on a non-glibc platform, it uses C library headers without including them. That’s fine unless your compiler is clang 16, which is strict about using functions without prototypes. Fortunately, Darwin’s headers are compatible enough as are Musl’s, so defining `__GNU_LIBRARY__` can be done unconditionally. --- pkgs/tools/misc/getopt/default.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/tools/misc/getopt/default.nix b/pkgs/tools/misc/getopt/default.nix index c3b94465aea1..2090fcbd7aac 100644 --- a/pkgs/tools/misc/getopt/default.nix +++ b/pkgs/tools/misc/getopt/default.nix @@ -8,6 +8,10 @@ stdenv.mkDerivation rec { sha256 = "1zn5kp8ar853rin0ay2j3p17blxy16agpp8wi8wfg4x98b31vgyh"; }; + # This should be fine on Linux and Darwin. Clang 16 requires it because otherwise getopt will + # attempt to use C library functions without declaring them, which is raised as an error. + env.NIX_CFLAGS_COMPILE = "-D__GNU_LIBRARY__"; + makeFlags = [ "WITHOUT_GETTEXT=1" "LIBCGETOPT=0"