meson: compile compatibility sources separately

In the next commit we're about to introduce a precompiled header for "git-compat-util.h". The consequence of this change is that we'll implicitly include that header for every compilation unit that uses the precompiled headers. This is okay for our "normal" library sources and our builtins. But some of our compatibility sources do not include the header on purpose, and doing so would cause compilation errors. Prepare for this change by splitting out compatibility sources into their static library. Like this, we can selectively enable precompiled headers for the library sources. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Mar 19, 2026 at 06:33 UTC daa56fb7897ce8819e5a64f4ec7800b3eef03031
1 file changed +45 -34
meson.build
+45 -34
@@ -271,6 +271,13 @@ version_gen_environment.set('GIT_VERSION', get_option('version'))
271
272 compiler = meson.get_compiler('c')
273
274 +compat_sources = [
275 + 'compat/nonblock.c',
276 + 'compat/obstack.c',
277 + 'compat/open.c',
278 + 'compat/terminal.c',
279 +]
280 +
281 libgit_sources = [
282 'abspath.c',
283 'add-interactive.c',
@@ -304,10 +311,6 @@ libgit_sources = [
311 'commit.c',
312 'common-exit.c',
313 'common-init.c',
307 - 'compat/nonblock.c',
308 - 'compat/obstack.c',
309 - 'compat/open.c',
310 - 'compat/terminal.c',
314 'compiler-tricks/not-constant.c',
315 'config.c',
316 'connect.c',
@@ -1163,7 +1166,7 @@ endif
1166
1167 if not has_poll_h and not has_sys_poll_h
1168 libgit_c_args += '-DNO_POLL'
1166 - libgit_sources += 'compat/poll/poll.c'
1169 + compat_sources += 'compat/poll/poll.c'
1170 libgit_include_directories += 'compat/poll'
1171 endif
1172
@@ -1179,7 +1182,7 @@ endif
1182 # implementation to threat things like drive prefixes specially.
1183 if host_machine.system() == 'windows' or not compiler.has_header('libgen.h')
1184 libgit_c_args += '-DNO_LIBGEN_H'
1182 - libgit_sources += 'compat/basename.c'
1185 + compat_sources += 'compat/basename.c'
1186 endif
1187
1188 if compiler.has_header('paths.h')
@@ -1209,7 +1212,7 @@ if host_machine.system() != 'windows'
1212 foreach symbol : ['inet_ntop', 'inet_pton', 'hstrerror']
1213 if not compiler.has_function(symbol, dependencies: networking_dependencies)
1214 libgit_c_args += '-DNO_' + symbol.to_upper()
1212 - libgit_sources += 'compat/' + symbol + '.c'
1215 + compat_sources += 'compat/' + symbol + '.c'
1216 endif
1217 endforeach
1218 endif
@@ -1251,18 +1254,18 @@ else
1254 endif
1255
1256 if host_machine.system() == 'darwin'
1254 - libgit_sources += 'compat/precompose_utf8.c'
1257 + compat_sources += 'compat/precompose_utf8.c'
1258 libgit_c_args += '-DPRECOMPOSE_UNICODE'
1259 libgit_c_args += '-DPROTECT_HFS_DEFAULT'
1260 endif
1261
1262 # Configure general compatibility wrappers.
1263 if host_machine.system() == 'cygwin'
1261 - libgit_sources += [
1264 + compat_sources += [
1265 'compat/win32/path-utils.c',
1266 ]
1267 elif host_machine.system() == 'windows'
1265 - libgit_sources += [
1268 + compat_sources += [
1269 'compat/winansi.c',
1270 'compat/win32/dirent.c',
1271 'compat/win32/flush.c',
@@ -1289,20 +1292,20 @@ elif host_machine.system() == 'windows'
1292 libgit_include_directories += 'compat/win32'
1293 if compiler.get_id() == 'msvc'
1294 libgit_include_directories += 'compat/vcbuild/include'
1292 - libgit_sources += 'compat/msvc.c'
1295 + compat_sources += 'compat/msvc.c'
1296 else
1294 - libgit_sources += 'compat/mingw.c'
1297 + compat_sources += 'compat/mingw.c'
1298 endif
1299 endif
1300
1301 if host_machine.system() == 'linux'
1299 - libgit_sources += 'compat/linux/procinfo.c'
1302 + compat_sources += 'compat/linux/procinfo.c'
1303 elif host_machine.system() == 'windows'
1301 - libgit_sources += 'compat/win32/trace2_win32_process_info.c'
1304 + compat_sources += 'compat/win32/trace2_win32_process_info.c'
1305 elif host_machine.system() == 'darwin'
1303 - libgit_sources += 'compat/darwin/procinfo.c'
1306 + compat_sources += 'compat/darwin/procinfo.c'
1307 else
1305 - libgit_sources += 'compat/stub/procinfo.c'
1308 + compat_sources += 'compat/stub/procinfo.c'
1309 endif
1310
1311 if host_machine.system() == 'cygwin' or host_machine.system() == 'windows'
@@ -1315,13 +1318,13 @@ endif
1318
1319 # Configure the simple-ipc subsystem required fro the fsmonitor.
1320 if host_machine.system() == 'windows'
1318 - libgit_sources += [
1321 + compat_sources += [
1322 'compat/simple-ipc/ipc-shared.c',
1323 'compat/simple-ipc/ipc-win32.c',
1324 ]
1325 libgit_c_args += '-DSUPPORTS_SIMPLE_IPC'
1326 else
1324 - libgit_sources += [
1327 + compat_sources += [
1328 'compat/simple-ipc/ipc-shared.c',
1329 'compat/simple-ipc/ipc-unix-socket.c',
1330 ]
@@ -1339,7 +1342,7 @@ if fsmonitor_backend != ''
1342 libgit_c_args += '-DHAVE_FSMONITOR_DAEMON_BACKEND'
1343 libgit_c_args += '-DHAVE_FSMONITOR_OS_SETTINGS'
1344
1342 - libgit_sources += [
1345 + compat_sources += [
1346 'compat/fsmonitor/fsm-health-' + fsmonitor_backend + '.c',
1347 'compat/fsmonitor/fsm-ipc-' + fsmonitor_backend + '.c',
1348 'compat/fsmonitor/fsm-listen-' + fsmonitor_backend + '.c',
@@ -1355,7 +1358,7 @@ if not get_option('b_sanitize').contains('address') and get_option('regex').allo
1358
1359 if compiler.get_define('REG_ENHANCED', prefix: '#include <regex.h>') != ''
1360 libgit_c_args += '-DUSE_ENHANCED_BASIC_REGULAR_EXPRESSIONS'
1358 - libgit_sources += 'compat/regcomp_enhanced.c'
1361 + compat_sources += 'compat/regcomp_enhanced.c'
1362 endif
1363 elif not get_option('regex').enabled()
1364 libgit_c_args += [
@@ -1364,7 +1367,7 @@ elif not get_option('regex').enabled()
1367 '-DNO_MBSUPPORT',
1368 ]
1369 build_options_config.set('NO_REGEX', '1')
1367 - libgit_sources += 'compat/regex/regex.c'
1370 + compat_sources += 'compat/regex/regex.c'
1371 libgit_include_directories += 'compat/regex'
1372 else
1373 error('Native regex support requested but not found')
@@ -1428,7 +1431,7 @@ else
1431
1432 if get_option('b_sanitize').contains('address')
1433 libgit_c_args += '-DNO_MMAP'
1431 - libgit_sources += 'compat/mmap.c'
1434 + compat_sources += 'compat/mmap.c'
1435 else
1436 checkfuncs += { 'mmap': ['mmap.c'] }
1437 endif
@@ -1438,7 +1441,7 @@ foreach func, impls : checkfuncs
1441 if not compiler.has_function(func)
1442 libgit_c_args += '-DNO_' + func.to_upper()
1443 foreach impl : impls
1441 - libgit_sources += 'compat/' + impl
1444 + compat_sources += 'compat/' + impl
1445 endforeach
1446 endif
1447 endforeach
@@ -1449,13 +1452,13 @@ endif
1452
1453 if not compiler.has_function('strdup')
1454 libgit_c_args += '-DOVERRIDE_STRDUP'
1452 - libgit_sources += 'compat/strdup.c'
1455 + compat_sources += 'compat/strdup.c'
1456 endif
1457
1458 if not compiler.has_function('qsort')
1459 libgit_c_args += '-DINTERNAL_QSORT'
1460 endif
1458 -libgit_sources += 'compat/qsort_s.c'
1461 +compat_sources += 'compat/qsort_s.c'
1462
1463 if compiler.has_function('getdelim')
1464 libgit_c_args += '-DHAVE_GETDELIM'
@@ -1511,7 +1514,7 @@ if meson.can_run_host_binaries() and compiler.run('''
1514 }
1515 ''', name: 'fread reads directories').returncode() == 0
1516 libgit_c_args += '-DFREAD_READS_DIRECTORIES'
1514 - libgit_sources += 'compat/fopen.c'
1517 + compat_sources += 'compat/fopen.c'
1518 endif
1519
1520 if not meson.is_cross_build() and fs.exists('/dev/tty')
@@ -1745,14 +1748,22 @@ else
1748 endif
1749
1750 libgit = declare_dependency(
1748 - link_with: static_library('git',
1749 - sources: libgit_sources,
1750 - c_args: libgit_c_args + [
1751 - '-DGIT_VERSION_H="' + version_def_h.full_path() + '"',
1752 - ],
1753 - dependencies: libgit_dependencies,
1754 - include_directories: libgit_include_directories,
1755 - ),
1751 + link_with: [
1752 + static_library('compat',
1753 + sources: compat_sources,
1754 + c_args: libgit_c_args,
1755 + dependencies: libgit_dependencies,
1756 + include_directories: libgit_include_directories,
1757 + ),
1758 + static_library('git',
1759 + sources: libgit_sources,
1760 + c_args: libgit_c_args + [
1761 + '-DGIT_VERSION_H="' + version_def_h.full_path() + '"',
1762 + ],
1763 + dependencies: libgit_dependencies,
1764 + include_directories: libgit_include_directories,
1765 + ),
1766 + ],
1767 compile_args: libgit_c_args,
1768 dependencies: libgit_dependencies,
1769 include_directories: libgit_include_directories,