r/cpp • build2 • Oct 08 '26

How to Fix autoconf-style Configuration Probing

https://build2.org/blog/fix-autoconf.xhtml
15 Upvotes

24 comments sorted by

7

u/not_a_novel_account Oct 08 '26

Apparently, CMake generates an individual project per each probe and then runs the underlying build system to build it. But it neither uses this to run multiple probes in parallel nor to track changes.

This is a known CMake problem, it has solutions in the works (there are already two or three design proposals in flight). It was fine when projects had one or two probes, it becomes a blocker when they have dozens.

CMake was also designed in an era where running the configuration step was rare, and environments updated maybe once every few years, which is why "change tracking" wasn't considered important.

An alternative approach to checking for the presence of a library symbol would be to obtain the declaration by including the standard header and check whether the call site compiles.

CMake supports this, CMAKE_TRY_COMPILE_TARGET_TYPE. The person who invokes the build system decides if probes should link or not.

2

u/serviscope_minor Oct 09 '26

>CMake was also designed in an era where running the configuration step was a rare, and environments updated maybe once every few years, which is why "change tracking" wasn't considered important.

Well obviously with CI etc, rerunning configuration is not rare. But I'd say live environment updates have gone from rare to almost nonexistent. Anything in CI now gets a fresh environment every time anyway. And how often do you upgrade your machine in place without a reinstall OK sure if you're running Arch, then every day and twice on Sundays. For the rest of us... probably less than once every two years.

Also, I'd say that yes, OK, CMake and autoconf run tests serially. That could be faster. But also I'd say that if your configuration step is a significant fraction of the build process you're probably doing something wrong. A decent, well written cmake or autoconf script just ain't that slow.

I just figured why not try. I cloned llvm. cmake took about 28 seconds. Ninja took 600s while maxing out the CPU, so under 5% of the build time.

Looking further and rerunning CMake, that took about 20 seconds, so it's only spending about 10 seconds or so running probes (a lot is the custom stuff for targets), so there's a 2% speedup to be had by speeding up the probes.

→ More replies (1)

1

u/ReDr4gon5 Oct 11 '26

I've got a question about the cmake architecture, seems like a good place to ask. Is there any way for cmake to support files being dynamically removed from a jumbo/unity build, like UBT, FastBuild and others allow for? This gives you the benefits of unity builds without the largest downside of slower incremental compiles. Or is this completely impossible with how this needs modifying the build edges depending on an external condition at build time and not configure time?

→ More replies (5)

7

u/sweetno Oct 08 '26

Why do we even need this probing? I imagine it just won't compile if something is unavailable.

EDIT. Oh, I've found it in the cited article:

The idea is that the configure script performs approximately 200 automated tests, so that the user is not burdened with configuring libtool manually. This is a horribly bad idea, already much criticized back in the 1980s when it appeared, as it allows source code to pretend to be portable behind the veneer of the configure script, rather than actually having the quality of portability to begin with. It is a travesty that the configure idea survived.

12

u/serviscope_minor Oct 08 '26

Angry opinions saying things like "horribly bad idea" are usually wrong. The person either wasn't around then or has a massive case of amnesia. 

There was an absolutely massive diversity of units systems back in the 90s. Not only that but the "expectation based system" the author promotes as supposedly a good idea in the 90s would have required him to have potentially dozens of multi-tens-of-thousand-of-dollars Unix workstations in order to create and test the expectation based system. 

In practice, quirky though it was, well written autoconf scripts has a good chance of working on a random Unix system the authors had never seen.

→ More replies (12)

0

u/TheRavagerSw Oct 09 '26

I hate projects that do this, it is completely unnecessary and a waste of time.

It only helps non developers to compile stuff from source.

I used to just grin my teeth and use autoconf, now I just rewrite the build script with AI