Subject: Re: git no longer builds on SunOS 5.10, a report

From: Patrick Steinhardt <[email-masked]>
Date: Sat, 12 Oct 2024 10:19:55 +0200

On Fri, Oct 11, 2024 at 10:10:26PM -0400, Alejandro R. Sedeño wrote:
> First, clar.suite was generated as broken because clar-decls.h was
> generated as empty. Tweaking the sed one-liner in Makefile that is
> used to generate clar-decls.h fixed that (move the end-of-line marker
> outside of the capture group, `$$\)` -> `\)$$`), which I would submit
> as a patch, but (a) that only fixed part of the problem and (b) I'm
> not entirely sure why it helped. If someone else wants to apply this
> change, which would align the end-of-line marker placement with the
> start-of-line marker placement, have at it.

I'd still appreciate it if you could show me the diff. From thereon I
can handle the rest.

> The next issue was that clar/sandbox.h uses mkdtemp, which I don't
> have here. Git has solved this in compat/mkdtemp.c via
> git-compat-util.h, but clar is not using it. Adding git-compat-util.h
> to clar/sandbox.h feels weird, but does get us further along. That
> change introduced banned.h into clar, which exposed the use of strncpy
> and localtime, both otherwise banned in git.

Yeah, we don't want to pull in that header. The clar is from upstream,
so ideally we shouldn't have to modify it with non-upstreamable bits.

In any case, I've got a similar report yesterday where some functions
weren't available. The root cause is that we don't set `_POSIX_C_SOURCE`
in "clar.c", so with the below patch things started to work. Does that
patch work for you, too? At least I think it should, as [1] mentions
that the function is available on SunOS when those defines exist.

In any case, the patch has already been merged upstream [2], and I'll
send a patch early next week that updates our bundled version of clar.

[1]: https://www.unix.com/man-page/sunos/3/MKDTEMP/
[2]: https://github.com/clar-test/clar/pull/106

[snip]
> Please note that this should not be read as opposition to the new
> unit-testing framework in any way. Building git (and curl, and gmake,
> and zlib, and openssl, and perl, all for git) for SunOS was a hobby
> for me, and not anything I personally need, and besides, it's not like
> my previous builds have disappeared.

Sure. But if the fix is easy enough I don't see a reason why we
shouldn't try to support your platform. It would be great to get earlier
feedback such that we can fix issues like this before we create the
release (see also our Documentation/technical/platform-support.txt,
which we have released recently.). But I'll take what I can get, so
thanks a lot for sending the report in the first place!

Patrick

diff --git a/t/unit-tests/clar/clar.c b/t/unit-tests/clar/clar.c
index cef0f023c24..76557df3040 100644
--- a/t/unit-tests/clar/clar.c
+++ b/t/unit-tests/clar/clar.c
@@ -4,6 +4,10 @@
  * This file is part of clar, distributed under the ISC license.
  * For full terms see the included COPYING file.
  */
+
+#define _DARWIN_C_SOURCE
+#define _POSIX_C_SOURCE 200809L
+
 #include <assert.h>
 #include <setjmp.h>
 #include <stdlib.h>
@@ -271,9 +275,7 @@ static double clar_time_diff(clar_time *start, clar_time *end)
 
 static void clar_time_now(clar_time *out)
 {
-	struct timezone tz;
-
-	gettimeofday(out, &tz);
+	gettimeofday(out, NULL);
 }
 
 static double clar_time_diff(clar_time *start, clar_time *end)