Subject: PSA: Autoconf has risen from the dead

From: Tom Lane <[email-masked]>
Date: Sun, 23 Jan 2022 11:29:17 -0500

While chasing something else, I was surprised to learn that the
Autoconf project has started to make releases again.  There are
2.70 (2020-12-08) and 2.71 (2021-01-28) versions available at
https://ftp.gnu.org/gnu/autoconf/

Right now, I'm not sure we care; there seems to be more
enthusiasm for switching to meson.  But if that idea falls
through, we should update to a newer autoconf release.

			regards, tom lane

---

From: "Joel Jacobson" <[email-masked]>
Date: Sun, 23 Jan 2022 19:13:41 +0100

>through, we should update to a newer autoconf release.

Speaking of autoconf,

I don't have much experience in this area, but I noted there is
an AC_CACHE_SAVE feature to speed up rerunning ./configure,
necessary when it stops with an error due to some missing dependency.

Is there a good reason why AC_CACHE_SAVE is not used?

/Joel

---

From: Tom Lane <[email-masked]>
Date: Sun, 23 Jan 2022 13:35:22 -0500

> Is there a good reason why AC_CACHE_SAVE is not used?

Dunno ... it looks like that adds cycles to non-error cases,
which seems like optimizing for the wrong thing.

In any case, right at the moment is probably a bad time to be
working on improvements for configure per se.  We can come
back to this if the meson idea crashes and burns.

			regards, tom lane

---

From: Peter Eisentraut <[email-masked]>
Date: Mon, 24 Jan 2022 09:11:52 +0100

> https://ftp.gnu.org/gnu/autoconf/

I have patches ready for this at 
https://github.com/petere/postgresql/tree/autoconf-updates.

My thinking was to wait until Autoconf 2.71 has trickled down into the 
OS versions that developers are likely to use.  To survey that, I'm tracking

https://packages.debian.org/sid/autoconf [in testing]
https://packages.ubuntu.com/search?keywords=autoconf [in jammy, will be 
22.04 LTS]
https://src.fedoraproject.org/rpms/autoconf [in Fedora 36, planned 
2022-04-19]
https://formulae.brew.sh/formula/autoconf [done]

Currently, I think early PG16 might be good time to do this update.

---

From: Andres Freund <[email-masked]>
Date: Mon, 24 Jan 2022 00:17:32 -0800

Hi,

> through, we should update to a newer autoconf release.

Depending on the number of portability fixes in those releases the
backbranches could be reason enough to move to a newer autoconf, even if we
get to meson in HEAD? Of course only if there's more things fixed than
broken...

Greetings,

Andres Freund

---

From: Tom Lane <[email-masked]>
Date: Mon, 24 Jan 2022 09:14:27 -0500

Peter Eisentraut <[email-masked]> writes:
> OS versions that developers are likely to use.

I find that kind of irrelevant, because we expect people to install
autoconf from source anyway to avoid distro-specific behavior.
I suppose that waiting for it to get out into the wild might be good
from the standpoint of being sure it's bug-free, though.

Do these versions fix any bugs that affect us (i.e., that we've
not already created workarounds for)?

			regards, tom lane

---

From: Peter Eisentraut <[email-masked]>
Date: Mon, 24 Jan 2022 16:58:46 +0100

> not already created workarounds for)?

The only thing that could be of interest is that the workaround we are 
carrying in config/check_decls.m4 was originally upstreamed by Noah, but 
was then later partially reverted and replaced by a different solution. 
Further explanation is here:

https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=ec90049dfcf4538750e61d675d885157fa5ca7f8

I don't think it has affected us in practice, though.

---

From: Peter Eisentraut <[email-masked]>
Date: Thu, 30 Jun 2022 18:52:34 +0100

> https://github.com/petere/postgresql/tree/autoconf-updates.

I have updated this for 16devel and registered it in the commit fest.

To summarize:

- Autoconf 2.71 has been out for 1.5 years.
- It is available in many recently updated OSs.
- It allows us to throw away several workarounds.

Also:

- The created configure appears to be a bit faster, especially in the 
cached case.
- It supports checks for C11 features, which is something we might want 
to consider in the fullness of time.

---

From: Tom Lane <[email-masked]>
Date: Sat, 02 Jul 2022 12:11:12 -0400

>> Currently, I think early PG16 might be good time to do this update.

In preparation for reviewing this, I tried to install autoconf 2.71
from source locally.  All went well on my RHEL8 workstation, but
autoconf's testsuite falls over rather badly on my macOS laptop [1].
It fails differently on another Mac where I have a MacPorts
installation at the head of the search path [2].

After sending the requested reports, I tried scanning the bug-autoconf
archives, and found a similar report that was answered thus [3]:

> I *think* this is the same problem as https://savannah.gnu.org/support/?110492 
> : current Autoconf doesn't work correctly with the (rather old) version of GNU 
> M4 that ships with MacOS.  Please try installing a current version of GNU M4 in 
> your PATH and then retry the build and testsuite.

So that explains part of it: most of the failures are down to using
Apple's hoary m4 instead of the one from MacPorts.  We could usefully
warn about that in our own docs, perhaps.  But there's still these
scary failures:

509: AC_CHECK_HEADER_STDBOOL                         FAILED (acheaders.at:9)
514: AC_HEADER_STDBOOL                               FAILED (acheaders.at:14)

The generated autoconf program builds the same output files as you have
in your patch, and running the configure script gives the correct answer
from AC_HEADER_STDBOOL, so I'm not sure what these test failures are
unhappy about.  Still, this is not a good look for a mainstream
development platform.  I wonder if we ought to wait for a fix.

			regards, tom lane

[1] https://lists.gnu.org/archive/html/bug-autoconf/2022-07/msg00000.html
[2] https://lists.gnu.org/archive/html/bug-autoconf/2022-07/msg00001.html
[3] https://lists.gnu.org/archive/html/bug-autoconf/2022-04/msg00002.html

---

From: Tom Lane <[email-masked]>
Date: Sat, 02 Jul 2022 13:42:33 -0400

I wrote:
> warn about that in our own docs, perhaps.

Hmm.  I have just spent a very frustrating hour trying, and failing,
to build any version of GNU m4 from source on either RHEL8 or current
macOS.  I don't quite understand why: neither the RPM specfile nor
the MacPorts recipe for their respective m4 packages seem to contain
any special hacks, so that it looks like the usual "configure; make;
make check; make install" procedure ought to work fine.  But it doesn't.
I hit build failures (apparently because the source code is far too much
in bed with nonstandard aspects of libc), or get an executable that
SIGABRT's instantly, or if it doesn't do that it still fails some
self-tests.  With the latest 1.4.19 on macOS, the configure script
hangs up, for crissakes.

I am now feeling *very* hesitant about doing anything where we might
be effectively asking people to build m4 for themselves.

On the whole, I'm questioning the value of messing with our autoconf
infrastructure at this stage.  We did agree at PGCon that we'd keep
it going for a couple years more, but it's not real clear to me why
we can't limp along with 2.69 until we decide to drop it.

			regards, tom lane

---

From: Robert Haas <[email-masked]>
Date: Sun, 3 Jul 2022 10:41:43 -0400

> we can't limp along with 2.69 until we decide to drop it.

If building it on macOS is going to be annoying, then -1 from me for
upgrading to a new version until that's resolved.

Hmm, I also don't know how annoying it's going to be to get the new
ninja/meson stuff working on macOS ... I really hope someone puts a
good set of directions on the wiki or in the documentation or
someplace.

-- 
Robert Haas
EDB: http://www.enterprisedb.com

---

From: Tom Lane <[email-masked]>
Date: Sun, 03 Jul 2022 10:50:49 -0400

> good set of directions on the wiki or in the documentation or

If you use MacPorts it's just "install those packages", and I imagine
the same for Homebrew.  I've not tried build-from-source on modern
platforms.

One thing I think we lack data on is whether we're going to need a
policy similar to everyone-must-use-exactly-this-autoconf-version.
If we do, that will greatly raise the importance of building from
source.

			regards, tom lane

---

From: Andres Freund <[email-masked]>
Date: Sun, 3 Jul 2022 10:17:02 -0700

Hi,

> > good set of directions on the wiki or in the documentation or

Yea, I guess I should start a documentation section...

I've only used homebrew on mac, but with that it should be something along the
lines of

brew install meson
meson setup --buildtype debug -Dcassert=true build-directory
cd build-directory
ninja

of course if you want to build against some dependencies and / or run tap
tests, you need to do something similar to what you have to do for
configure. I.e.
- install perl modules [1]
- tell the build about location of homebrew [2]

> the same for Homebrew.  I've not tried build-from-source on modern

I've done some semi automated testing (to be turned fully automatic) across
meson versions that didn't so far show any need for that. We do require a
certain minimum version of meson (indicated in the top-level meson.build,
raises an error if not met), which in turn requires a minimum version of ninja
(also errors).

The windows build with msbuild is slower on older versions of meson that are
unproblematic on other platforms. But given you're not going to install an
outdated meson from $package-manager there, I don't think it's worth worrying
about.

Greetings,

Andres Freund

[1] https://github.com/anarazel/postgres/blob/meson/.cirrus.yml#L638
[2] https://github.com/anarazel/postgres/blob/meson/.cirrus.yml#L742

---

From: Robert Haas <[email-masked]>
Date: Tue, 5 Jul 2022 14:42:03 -0400

> - tell the build about location of homebrew [2]

Since I'm a macports user I hope at some point we'll have directions
for that as well as for homebrew.

---

From: Andres Freund <[email-masked]>
Date: Tue, 5 Jul 2022 11:47:38 -0700

Hi,

> for that as well as for homebrew.

I am not a normal mac user, it looks hard to run macos in a VM, and I'm not
sure it's wise to mix macports and homebrew on my test box. So I don't want to
test it myself.

But it looks like it's just
  sudo port install meson

Greetings,

Andres Freund

---

From: Tom Lane <[email-masked]>
Date: Tue, 05 Jul 2022 14:52:05 -0400

> But it looks like it's just

Yeah, that's what I did to install it locally.  The ninja package
has some weird name (ninja-build or some such), but you don't have
to remember that because installing meson is enough to pull it in.

I dunno anything about the other steps Andres mentioned, but
presumably they're independent of where you got meson from.

			regards, tom lane

---

From: Robert Haas <[email-masked]>
Date: Tue, 5 Jul 2022 14:52:55 -0400

> presumably they're independent of where you got meson from.

That seems simple enough that even I can handle it!

---

From: Andres Freund <[email-masked]>
Date: Tue, 5 Jul 2022 12:02:36 -0700

Hi,

> presumably they're independent of where you got meson from.

Yea. They might not be independent of where you get other dependencies from
though. Does macports install headers / libraries into a path that's found by
default? Or does one have to pass --with-includes / --with-libs to configure
and set PKG_CONFIG_PATH, like with homebrew?

Except that with meson doing PKG_CONFIG_PATH should suffice for most (all?)
dependencies on macos, and that the syntax for with-includes/libs is a bit
different (-Dextra_include_dirs=... and -Dextra_lib_dirs=...) and that
optionally one can use a parameter (--pkg-config-path) instead of
PKG_CONFIG_PATH, that part shouldn't really differ from what's neccesary
for configure.

Greetings,

Andres Freund

---

From: Tom Lane <[email-masked]>
Date: Tue, 05 Jul 2022 15:06:31 -0400

> and set PKG_CONFIG_PATH, like with homebrew?

What are you expecting to need PKG_CONFIG_PATH for?  Or more precisely,
why would meson/ninja create any new need for that that doesn't exist
in the autoconf case?

			regards, tom lane

---

From: Andres Freund <[email-masked]>
Date: Tue, 5 Jul 2022 12:14:20 -0700

Hi,

> why would meson/ninja create any new need for that that doesn't exist

It's just used in more cases than before, with fallback to non-pkg-config in
most cases. I think all dependencies besides perl can use pkg-config. So all
that changes compared to AC is that you might not need to pass extra
include/lib paths for some dependencies that needed it before, if you set/pass
PKG_CONFIG_PATH.

Greetings,

Andres Freund

---

From: Robert Haas <[email-masked]>
Date: Tue, 5 Jul 2022 17:04:41 -0400

> and set PKG_CONFIG_PATH, like with homebrew?

My configure switches include: --with-libraries=/opt/local/lib
--with-includes=/opt/local/include

I don't do anything with PKG_CONFIG_PATH.

---

From: Tom Lane <[email-masked]>
Date: Sat, 16 Jul 2022 11:26:46 -0400

... anyway, to get back to the main point of this thread:

The Autoconf developers were pretty responsive to my bug reports,
and after some back-and-forth we determined that:

1. The minimum GNU m4 version for modern autoconf is 1.4.8; this
is directly traceable to intentional behavioral changes in that
version, so it's a pretty hard requirement.  They've updated their
own configure script to enforce that minimum.

2. The macOS-specific problems I saw with the STDBOOL tests are
resolved by the attached patch, which should also appear in 2.72.
Since AC_HEADER_STDBOOL appears to work correctly in our usage
anyway, this is only important if you're the kind of person who
likes to see 100% pass from a tool's own self-tests before you
install it.

So as far as autoconf itself is concerned, we could probably move
forward, perhaps after waiting for 2.72.  The difficulty here is the
prospect that some people might find themselves having to install a
newer GNU m4, because GNU m4 is a hot mess.  Many post-1.4.8 versions
flat out don't compile on $your-favorite-platform [1], and many
others contain a showstopper bug (that's rejected by a runtime test in
autoconf's configure, independently of the min-version test) [2].
If you don't have a pretty recent m4 available from a package manager,
you might be in for a lot of hair-pulling.

The flip side of that is that probably nobody really needs to
update the configure script on non-mainstream platforms, so
maybe this wouldn't matter to us too much in practice.

On the whole though, my feeling is that autoconf 2.71 doesn't
offer enough to us to justify possibly causing substantial pain
for a few developers.  I recommend setting this project aside
for now.  We can always reconsider if the situation changes.

			regards, tom lane

[1] https://lists.gnu.org/archive/html/bug-autoconf/2022-07/msg00004.html
[2] https://lists.gnu.org/archive/html/bug-autoconf/2022-07/msg00006.html

diff --git a/lib/autoconf/headers.m4 b/lib/autoconf/headers.m4
index 8944da41..5cd1f4d5 100644
--- a/lib/autoconf/headers.m4
+++ b/lib/autoconf/headers.m4
@@ -633,8 +633,10 @@ AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
              bool *pp = &p;
 
              /* C 1999 specifies that bool, true, and false are to be
-                macros, but C++ 2011 and later overrule this.  */
-             #if __cplusplus < 201103
+                macros, but C++ 2011 overrules this.  The C++ committee
+                was codifying existing practice, so we allow them to
+                not be macros whenever __cplusplus is defined.  */
+             #ifndef __cplusplus
               #ifndef bool
                #error "bool is not defined"
               #endif
diff --git a/tests/local.at b/tests/local.at
index 3f348929..f79f57ff 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -593,9 +593,9 @@ AT_CMP([at_defines-$1], [at_defines-$2])[]dnl
 m4_define([_AT_DEFINES_CMP_PRUNE],
 [m4_bmatch([$1],
   [^vary:],
-[	/@%:@define ]m4_bpatsubsts([$1], [\<vary:], [])dnl
+[	/@%:@define ]m4_bpatsubsts([$1], [\<vary:], [])[]dnl
 [@<:@ @{:@@:>@/ d ;@%:@@:}@
-	/@%:@undef ]m4_bpatsubsts([$1], [\<vary:], [])dnl
+	/@%:@undef ]m4_bpatsubsts([$1], [\<vary:], [])[]dnl
 [@<:@ @{:@@:>@/ d ;@%:@@:}@
 ],
   [m4_fatal([unrecognized AT_DEFINES_CMP variance token: "$1"])])])

---

From: Peter Eisentraut <[email-masked]>
Date: Mon, 18 Jul 2022 11:11:59 +0200

> for now.  We can always reconsider if the situation changes.

Ok, let's do that.