build: isolate build-info defines into utils/buildinfo.c (ccache-friendly)

MAGIC_VERSION / MAGIC_REVISION / MAGIC_COMMIT / MAGIC_BUILDDATE were on the
global DFLAGS, so every object's compile command line carried them.  Because
the command line is part of ccache/sccache's hash key and MAGIC_BUILDDATE
changes every second, that meant a cache miss on every unit on every build;
it also smeared the baked-in date/commit across "whenever each file last
recompiled".

Move the four values into a single translation unit:
  * utils/magic_buildinfo.h -- extern MagicVersion/MagicRevision/MagicCommit/
    MagicCompileTime (MagicCommit is new; the other three moved here from
    utils/magic.h, which now includes this header).
  * utils/buildinfo.c -- the ONLY unit compiled with the version defines
    (target-specific `buildinfo.o: DFLAGS += ${DFLAGS_MAGICVERSION}` in
    utils/Makefile.in); it defines the four globals.  ${DFLAGS_MAGICVERSION}
    is removed from the global DFLAGS/DFLAGS_NOSTUB.

Consumers updated to read the runtime symbol instead of the compile-time
macro:
  * magicTop.c / tclmagic.c no longer define the globals (the MAGIC_WRAPPER
    duplicate-symbol guard is gone -- buildinfo.o owns them for every variant,
    including WASM, which links both mains).
  * Tcl_PkgProvide/PkgRequire in router/ext2spice/lef/ext2sim/plot/tclmagic
    now pass MagicVersion.
  * extflat: EFVersion (a static-initialized copy of MAGIC_VERSION) is dropped;
    EFread.c compares the .ext version against MagicVersion directly -- the same
    value ExtCell.c already *writes* into .ext files, so read and write are now
    consistent.

Verified: only buildinfo.o carries -DMAGIC_* (hash/DBio/windCmdSZ carry none);
Tcl (375 files) and --without-tcl builds rc=0, version/commit/date embedded in
tclmagic.so, magicTop.o no longer defines MagicVersion; in-tree source clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
Darryl L. Miles
2026-07-26 14:54:11 -04:00
committed by R. Timothy Edwards
co-authored by Claude Opus 4.8
parent 465e946f2e
commit b3d6540f13
15 changed files with 89 additions and 40 deletions
+7 -1
View File
@@ -9,7 +9,7 @@ srcdir = @srcdir@
VPATH = @srcdir@
MAGICDIR = @top_builddir@
LIB_SRCS = LIBdbio.c LIBmain.c LIBtextio.c
SRCS = args.c child.c dqueue.c finddisp.c flock.c flsbuf.c fraction.c \
SRCS = args.c buildinfo.c child.c dqueue.c finddisp.c flock.c flsbuf.c fraction.c \
geometry.c getrect.c hash.c heap.c ihash.c list.c lookup.c \
lookupany.c lookupfull.c macros.c main.c malloc.c match.c \
maxrect.c netlist.c niceabort.c parser.c path.c pathvisit.c \
@@ -23,3 +23,9 @@ DFLAGS += ${GR_DFLAGS}
CFLAGS += ${GR_CFLAGS}
include ${MAGICSRC}/rules.mak
# buildinfo.c is the ONLY unit that consumes the version defines; they are no
# longer on the global DFLAGS (that kept the ever-changing MAGIC_BUILDDATE off
# every other compile command line, so ccache/sccache keys stay stable). Apply
# them just here, target-specifically.
buildinfo.o: DFLAGS += ${DFLAGS_MAGICVERSION}
+31
View File
@@ -0,0 +1,31 @@
/*
* buildinfo.c --
*
* The single translation unit that captures the build-information defines.
*
* This is the ONLY file compiled with -DMAGIC_VERSION / -DMAGIC_REVISION /
* -DMAGIC_COMMIT / -DMAGIC_BUILDDATE (see the buildinfo.o recipe in
* utils/Makefile.in). Isolating them here keeps those defines -- especially the
* ever-changing MAGIC_BUILDDATE -- off every other compile command line, so
* ccache/sccache keys stay stable and the version/date/commit baked into the
* binary are consistent rather than smeared across whenever each object last
* recompiled.
*
* Consumers include "utils/magic_buildinfo.h" and read these externs.
*/
#include "utils/magic_buildinfo.h"
char *MagicVersion = MAGIC_VERSION;
char *MagicRevision = MAGIC_REVISION;
char *MagicCommit = MAGIC_COMMIT;
/*
* MAGIC_BUILDDATE may be disabled at configure time (--disable-magic-builddate)
* for reproducible builds; when it is, MagicCompileTime reports the empty string.
*/
#ifdef MAGIC_NO_BUILDDATE
char *MagicCompileTime = "";
#else
char *MagicCompileTime = MAGIC_BUILDDATE;
#endif
+4 -3
View File
@@ -145,9 +145,10 @@ extern char *SysLibPath; /* Path for finding system
/* ------------ Globally-used strings. -------------------------------- */
extern char *MagicVersion;
extern char *MagicRevision;
extern char *MagicCompileTime;
/* Build-info globals (MagicVersion / MagicRevision / MagicCommit /
* MagicCompileTime) are defined in utils/buildinfo.c -- the one unit compiled
* with the version defines -- and declared here: */
#include "utils/magic_buildinfo.h"
extern char AbortMessage[];
/* ------------ zlib (compression) support -------------------------------- */
+24
View File
@@ -0,0 +1,24 @@
/*
* magic_buildinfo.h --
*
* Public declarations for the build-information globals: magic's version,
* revision, git commit, and compile date/time.
*
* These are the ONLY symbols initialized from the -DMAGIC_VERSION /
* -DMAGIC_REVISION / -DMAGIC_COMMIT / -DMAGIC_BUILDDATE command-line defines.
* They are defined in exactly one translation unit, utils/buildinfo.c, which is
* the only unit compiled with those defines. Every other unit reads the values
* through these externs, so the volatile build-date/commit values stay off every
* other compile command line (which keeps ccache/sccache keys stable and the
* baked-in date/commit consistent across the whole binary).
*/
#ifndef _MAGIC_BUILDINFO_H
#define _MAGIC_BUILDINFO_H
extern char *MagicVersion; /* e.g. "8.3" (major.minor) */
extern char *MagicRevision; /* e.g. "670" (patch/revision) */
extern char *MagicCommit; /* git commit SHA, or "" if unavailable */
extern char *MagicCompileTime; /* build date/time, or "" if disabled */
#endif /* _MAGIC_BUILDINFO_H */