meson: drop separate version library

When building `libgit.a` we link it against a `libgit_version.a` library that contains the version information that we inject at build time. The intent of this is to avoid rebuilding all of `libgit.a` whenever the version changes. But that wouldn't happen in the first place, as we know to just rebuild the files that depend on the generated "version-def.h" file. This is an artifact of an earlier version of the Meson build infra that didn't ultimately land. We didn't yet have "version-def.h", and instead injected the version via preprocessor directives. And here we would have rebuilt all of `libgit.a` indeed in case the version changes, because the preprocessor directive applied to all files. Stop building the separate library and instead add "version-def.h" to the list of source files directly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Feb 26, 2025 at 09:22 UTC eee25bbd84e2c3c00ea75080133374c48eeb3240
1 file changed +5 -16
meson.build
+5 -16
@@ -478,6 +478,7 @@ libgit_sources = [
478 'userdiff.c',
479 'utf8.c',
480 'varint.c',
481 + 'version.c',
482 'versioncmp.c',
483 'walker.c',
484 'wildmatch.c',
@@ -1542,26 +1543,14 @@ version_def_h = custom_target(
1543 depends: [git_version_file],
1544 env: version_gen_environment,
1545 )
1545 -
1546 -# Build a separate library for "version.c" so that we do not have to rebuild
1547 -# everything when the current Git commit changes.
1548 -libgit_version_library = static_library('git-version',
1549 - sources: [
1550 - 'version.c',
1551 - version_def_h,
1552 - ],
1553 - c_args: libgit_c_args + [
1554 - '-DGIT_VERSION_H="' + version_def_h.full_path() + '"',
1555 - ],
1556 - dependencies: libgit_dependencies,
1557 - include_directories: libgit_include_directories,
1558 -)
1546 +libgit_sources += version_def_h
1547
1548 libgit = declare_dependency(
1549 link_with: static_library('git',
1550 sources: libgit_sources,
1563 - c_args: libgit_c_args,
1564 - link_with: libgit_version_library,
1551 + c_args: libgit_c_args + [
1552 + '-DGIT_VERSION_H="' + version_def_h.full_path() + '"',
1553 + ],
1554 dependencies: libgit_dependencies,
1555 include_directories: libgit_include_directories,
1556 ),