From 61fb2262e71a044198b8b18872a802036c332d80 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Fri, 25 Apr 2025 01:25:40 -0400 Subject: meson: simplify and parameterize various standard function checks This is repetitive logic. We either want to use some -lc function, or if it is not available we define it as -DNO_XXX and usually (but not always) provide some custom compatibility impl instead. Checking the intent of each block when reading through the file is slow and not very DRY. Switch to taking an array of checkable functions instead. Not all functions are straightforward to move, since different macro prefixes are used. Signed-off-by: Eli Schwartz Signed-off-by: Junio C Hamano --- meson.build | 85 +++++++++++++++++++++---------------------------------------- 1 file changed, 29 insertions(+), 56 deletions(-) diff --git a/meson.build b/meson.build index c47cb79af0..ed0359b9c9 100644 --- a/meson.build +++ b/meson.build @@ -1133,11 +1133,6 @@ else build_options_config.set('NO_UNIX_SOCKETS', '1') endif -if not compiler.has_function('pread') - libgit_c_args += '-DNO_PREAD' - libgit_sources += 'compat/pread.c' -endif - if host_machine.system() == 'darwin' libgit_sources += 'compat/precompose_utf8.c' libgit_c_args += '-DPRECOMPOSE_UNICODE' @@ -1290,23 +1285,39 @@ if not compiler.has_member('struct passwd', 'pw_gecos', prefix: '#include Date: Fri, 25 Apr 2025 01:25:41 -0400 Subject: meson: check for getpagesize before using it It is deprecated and removed in SUS v3 / POSIX 2001, so various systems may not include it. Solaris, in particular, carefully refrains from defining it except inside of a maze of `#ifdef` to make sure you have kept your nose clean and only used it in code that *targets* SUS v2 or earlier. config.mak.uname defines this automatically, though only for QNX. Signed-off-by: Eli Schwartz Signed-off-by: Junio C Hamano --- meson.build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/meson.build b/meson.build index ed0359b9c9..e575231129 100644 --- a/meson.build +++ b/meson.build @@ -1304,6 +1304,8 @@ else 'mmap' : ['mmap.c'], # provided by compat/mingw.c. 'unsetenv' : ['unsetenv.c'], + # provided by compat/mingw.c. + 'getpagesize' : [], } endif -- cgit v1.2.3 From f5e3c6c57d396ab85f7530c8d9675f74d1576f61 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Fri, 25 Apr 2025 01:25:42 -0400 Subject: meson: do a full usage-based compile check for sysinfo On Solaris, sys/sysinfo.h is a completely different file and doesn't resemble the linux file at all. There is also a sysinfo() function, but it takes a totally different call signature, which asks for: - the field you wish to receive - a `char *buf` to copy the data to and is very useful IFF you want to know, say, the hardware provider. Or, get *specific* fields from uname(2). https://docs.oracle.com/cd/E86824_01/html/E54765/sysinfo-2.html It is surely possible to do this manually via `sysconf(3)` without the nice API. I can't find anything more direct. Either way, I'm not very attached to Solaris, so someone who cares can add it. Either way, it's wrong to assume that sysinfo.h contains what we are looking for. Check that sysinfo.h defines the struct we actually utilize in builtins/gc.c, which will correctly fail on systems that don't have it. Signed-off-by: Eli Schwartz Signed-off-by: Junio C Hamano --- meson.build | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index e575231129..b21b191d25 100644 --- a/meson.build +++ b/meson.build @@ -1058,10 +1058,6 @@ if compiler.has_header('alloca.h') libgit_c_args += '-DHAVE_ALLOCA_H' endif -if compiler.has_header('sys/sysinfo.h') - libgit_c_args += '-DHAVE_SYSINFO' -endif - # Windows has libgen.h and a basename implementation, but we still need our own # implementation to threat things like drive prefixes specially. if host_machine.system() == 'windows' or not compiler.has_header('libgen.h') @@ -1267,6 +1263,10 @@ if host_machine.system() != 'windows' endif endif +if compiler.has_member('struct sysinfo', 'totalram', prefix: '#include ') + libgit_c_args += '-DHAVE_SYSINFO' +endif + if compiler.has_member('struct stat', 'st_mtimespec.tv_nsec', prefix: '#include ') libgit_c_args += '-DUSE_ST_TIMESPEC' elif not compiler.has_member('struct stat', 'st_mtim.tv_nsec', prefix: '#include ') -- cgit v1.2.3 From 5cb05d76af33367b061aec65113de06eaa39fc71 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Fri, 25 Apr 2025 01:25:43 -0400 Subject: meson: add a couple missing networking dependencies As evidenced in config.mak.uname and configure.ac, there are various possible scenarios where these libraries are default-enabled in the build, which mainly boils down to: SunOS. -lresolv is simply not the only library that, when it exists, probably needs to be linked to for networking. Check for and add -lnsl -lsocket as well. Signed-off-by: Eli Schwartz Signed-off-by: Junio C Hamano --- meson.build | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index b21b191d25..66b69f2471 100644 --- a/meson.build +++ b/meson.build @@ -1080,10 +1080,11 @@ if host_machine.system() == 'windows' networking_dependencies += winsock endif else - libresolv = compiler.find_library('resolv', required: false) - if libresolv.found() - networking_dependencies += libresolv - endif + networking_dependencies += [ + compiler.find_library('nsl', required: false), + compiler.find_library('resolv', required: false), + compiler.find_library('socket', required: false), + ] endif libgit_dependencies += networking_dependencies -- cgit v1.2.3 From 2b83df36f4176edb2457c5eb83f7adae990f2df4 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Fri, 25 Apr 2025 01:25:44 -0400 Subject: meson: fix typo in function check that prevented checking for hstrerror Nowhere in the codebase do we otherwise check for strerror. Nowhere in the codebase do we make use of -DNO_STRERROR. `strerror` is not a networking function at all. We do utilize `hstrerror` though, which is a networking function we should have been checking here. Signed-off-by: Eli Schwartz Signed-off-by: Junio C Hamano --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 66b69f2471..25bac8d89f 100644 --- a/meson.build +++ b/meson.build @@ -1088,7 +1088,7 @@ else endif libgit_dependencies += networking_dependencies -foreach symbol : ['inet_ntop', 'inet_pton', 'strerror'] +foreach symbol : ['inet_ntop', 'inet_pton', 'hstrerror'] if not compiler.has_function(symbol, dependencies: networking_dependencies) libgit_c_args += '-DNO_' + symbol.to_upper() endif -- cgit v1.2.3 From d380dfeed74d9f4530cdab41f51bd287aebfbe4d Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Fri, 25 Apr 2025 01:25:45 -0400 Subject: meson: only check for missing networking syms on non-Windows; add compat impls These are added in the Makefile, but not in meson. They probably won't work well on systems without them. CMake adds them, but only on non-Windows. Actually, it only performs compiler checks for hstrerror, but excludes that check on Windows with the note that it is "incompatible with the Windows build". This seems to be misleading -- it is not incompatible, it simply doesn't exist. Still, the compat version should not be used. I interpret this cmake logic to mean we shouldn't even be checking for symbol availability on Windows. In addition to making it simple to add compat definitions, this also probably shaves off a second or two of configure time on Windows as no compiler check needs to be performed. Signed-off-by: Eli Schwartz Signed-off-by: Junio C Hamano --- meson.build | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 25bac8d89f..fbe43be949 100644 --- a/meson.build +++ b/meson.build @@ -1088,11 +1088,14 @@ else endif libgit_dependencies += networking_dependencies -foreach symbol : ['inet_ntop', 'inet_pton', 'hstrerror'] - if not compiler.has_function(symbol, dependencies: networking_dependencies) - libgit_c_args += '-DNO_' + symbol.to_upper() - endif -endforeach +if host_machine.system() != 'windows' + foreach symbol : ['inet_ntop', 'inet_pton', 'hstrerror'] + if not compiler.has_function(symbol, dependencies: networking_dependencies) + libgit_c_args += '-DNO_' + symbol.to_upper() + libgit_sources += 'compat/' + symbol + '.c' + endif + endforeach +endif has_ipv6 = compiler.has_function('getaddrinfo', dependencies: networking_dependencies) if not has_ipv6 -- cgit v1.2.3