{"thread":{"id":"63743","subject":"[PATCH] build: fix FreeBSD build when sysinfo compat library installed","startedAt":"2025-07-04T22:26:24Z","lastAt":"2025-07-07T17:12:33Z","messageCount":6,"participants":["Ramsay Jones","Eric Sunshine","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"521338","messageId":"e6a80163-47ef-436b-98a6-2ac39c477080@ramsayjones.plus.com","threadId":"63743","inReplyTo":null,"subject":"[PATCH] build: fix FreeBSD build when sysinfo compat library installed","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2025-07-04T22:23:11Z","receivedAt":"2025-07-04T22:26:24Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nCommit 50dec7c566 (\"config.mak.uname: add sysinfo() configuration for\ncygwin\", 2025-04-17) and later commit 187ce0222f (\"configure.ac: upgrade\nto a compilation check for sysinfo\", 2025-05-19) added a 'sysinfo()'\ncheck to the autoconf build.\n\nThe FreeBSD system has an optional sysinfo compatibility library, used\nto assist in porting software, which causes the build to fail when it\nis installed. The reason for the failure is the lack of '-lsysinfo'\nduring the linking step.\n\nSeveral solutions were considered:\n\n  - add an 'linking' check to configure.ac in order to determine the\n    need to link a separate library (-lsysinfo). (This would require\n    a similar change to meson.build).\n\n  - change the order of the preprocessor conditionals in the total_ram()\n    function in 'builtin/gc.c', so that the *BSD sysctl() function\n    (in the HAVE_BSD_SYSCTL block) takes priority over the sysinfo()\n    function (in the HAVE_SYSINFO block).\n\n  - suppress the setting of HAVE_SYSINFO when HAVE_BSD_SYSCTL has been\n    defined (in both configure.ac and meson.build).\n\nThe first solution above, while simple, adds unnecessary code (the\nsysinfo compat function is likely implemented using sysctl() anyway)\nwhen git is happy to use sysctl() on *BSD systems.\n\nThe second solution would only be required by the autoconf and meson\nbuild systems, the Makefile already sets the build variables to the\nrequired values (since they are not 'auto-detected').\n\nHere we opt for the final solution above, since it only requires that\nwe prioritise the 'auto-detected' build variables in the autoconf and\nmeson builds.\n\nIn order to fix the FreeBSD build, move the sysinfo() check after the\ndetermination of the HAVE_BSD_SYSCTL build variable, suppressing the\nsetting of HAVE_SYSINFO if HAVE_BSD_SYSCTL is defined. Apply this logic\nto both the configure.ac and meson.build file.\n\n[Thanks go to Renato Botelho <garga@FreeBSD.org> for testing this patch\non FreeBSD.]\n\nTested-by: Renato Botelho <garga@FreeBSD.org>\nSigned-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n---\n configure.ac | 61 ++++++++++++++++++++++++++++++----------------------\n meson.build  | 10 +++++----\n 2 files changed, 41 insertions(+), 30 deletions(-)\n\ndiff --git a/configure.ac b/configure.ac\nindex f6caab919a..bf710ac91a 100644\n--- a/configure.ac\n+++ b/configure.ac\n@@ -1067,32 +1067,6 @@ AC_CHECK_LIB([iconv], [locale_charset],\n                      [CHARSET_LIB=-lcharset])])\n GIT_CONF_SUBST([CHARSET_LIB])\n \n-#\n-# Define HAVE_SYSINFO=YesPlease if sysinfo is available.\n-#\n-AC_DEFUN([HAVE_SYSINFO_SRC], [\n-AC_LANG_PROGRAM([[\n-#include <stdint.h>\n-#include <sys/sysinfo.h>\n-]], [[\n-struct sysinfo si;\n-uint64_t t = 0;\n-if (!sysinfo(&si)) {\n-\tt = si.totalram;\n-\tif (si.mem_unit > 1)\n-\t\tt *= (uint64_t)si.mem_unit;\n-}\n-return t;\n-]])])\n-\n-AC_MSG_CHECKING([for sysinfo])\n-AC_COMPILE_IFELSE([HAVE_SYSINFO_SRC],\n-\t[AC_MSG_RESULT([yes])\n-\tHAVE_SYSINFO=YesPlease],\n-\t[AC_MSG_RESULT([no])\n-\tHAVE_SYSINFO=])\n-GIT_CONF_SUBST([HAVE_SYSINFO])\n-\n #\n # Define HAVE_CLOCK_GETTIME=YesPlease if clock_gettime is available.\n GIT_CHECK_FUNC(clock_gettime,\n@@ -1221,6 +1195,41 @@ AC_COMPILE_IFELSE([BSD_SYSCTL_SRC],\n \tHAVE_BSD_SYSCTL=])\n GIT_CONF_SUBST([HAVE_BSD_SYSCTL])\n \n+#\n+# Define HAVE_SYSINFO=YesPlease if sysinfo is available.\n+#\n+\n+HAVE_SYSINFO=\n+# on a *BSD system, sysctl() takes precedence over the\n+# sysinfo() compatibility library (if installed).\n+\n+if test -z \"$HAVE_BSD_SYSCTL\"; then\n+\n+  AC_DEFUN([HAVE_SYSINFO_SRC], [\n+  AC_LANG_PROGRAM([[\n+  #include <stdint.h>\n+  #include <sys/sysinfo.h>\n+  ]], [[\n+  struct sysinfo si;\n+  uint64_t t = 0;\n+  if (!sysinfo(&si)) {\n+\tt = si.totalram;\n+\tif (si.mem_unit > 1)\n+\t\tt *= (uint64_t)si.mem_unit;\n+  }\n+  return t;\n+  ]])])\n+\n+  AC_MSG_CHECKING([for sysinfo])\n+  AC_COMPILE_IFELSE([HAVE_SYSINFO_SRC],\n+\t[AC_MSG_RESULT([yes])\n+\tHAVE_SYSINFO=YesPlease],\n+\t[AC_MSG_RESULT([no])\n+\tHAVE_SYSINFO=])\n+  GIT_CONF_SUBST([HAVE_SYSINFO])\n+\n+fi\n+\n ## Other checks.\n # Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link.\n # Enable it on Windows.  By default, symrefs are still used.\ndiff --git a/meson.build b/meson.build\nindex 7fea4a34d6..355cad730c 100644\n--- a/meson.build\n+++ b/meson.build\n@@ -1331,10 +1331,6 @@ if host_machine.system() != 'windows'\n   endif\n endif\n \n-if compiler.has_member('struct sysinfo', 'totalram', prefix: '#include <sys/sysinfo.h>')\n-  libgit_c_args += '-DHAVE_SYSINFO'\n-endif\n-\n if compiler.has_member('struct stat', 'st_mtimespec.tv_nsec', prefix: '#include <sys/stat.h>')\n   libgit_c_args += '-DUSE_ST_TIMESPEC'\n elif not compiler.has_member('struct stat', 'st_mtim.tv_nsec', prefix: '#include <sys/stat.h>')\n@@ -1449,6 +1445,12 @@ if compiler.has_header('sys/sysctl.h')\n   endif\n endif\n \n+if not has_bsd_sysctl\n+  if compiler.has_member('struct sysinfo', 'totalram', prefix: '#include <sys/sysinfo.h>')\n+    libgit_c_args += '-DHAVE_SYSINFO'\n+  endif\n+endif\n+\n if not meson.is_cross_build() and compiler.run('''\n   #include <stdio.h>\n \n-- \n2.50.0\n"},{"id":"521339","messageId":"CAPig+cTybBgkwFEsMVNNu2o1w9T5qnhau4chvGU2opEPJO78zg@mail.gmail.com","threadId":"63743","inReplyTo":"e6a80163-47ef-436b-98a6-2ac39c477080@ramsayjones.plus.com","subject":"Re: [PATCH] build: fix FreeBSD build when sysinfo compat library installed","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2025-07-04T23:49:53Z","receivedAt":"2025-07-04T23:50:06Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Fri, Jul 4, 2025 at 6:26 PM Ramsay Jones <ramsay@ramsayjones.plus.com> wrote:\n> Commit 50dec7c566 (\"config.mak.uname: add sysinfo() configuration for\n> cygwin\", 2025-04-17) and later commit 187ce0222f (\"configure.ac: upgrade\n> to a compilation check for sysinfo\", 2025-05-19) added a 'sysinfo()'\n> check to the autoconf build.\n>\n> The FreeBSD system has an optional sysinfo compatibility library, used\n> to assist in porting software, which causes the build to fail when it\n> is installed. The reason for the failure is the lack of '-lsysinfo'\n> during the linking step.\n>\n> Several solutions were considered:\n>\n>   - add an 'linking' check to configure.ac in order to determine the\n\ns/an/a/\n\n(not worth a reroll)\n\n>     need to link a separate library (-lsysinfo). (This would require\n>     a similar change to meson.build).\n>\n>   - change the order of the preprocessor conditionals in the total_ram()\n>     function in 'builtin/gc.c', so that the *BSD sysctl() function\n>     (in the HAVE_BSD_SYSCTL block) takes priority over the sysinfo()\n>     function (in the HAVE_SYSINFO block).\n>\n>   - suppress the setting of HAVE_SYSINFO when HAVE_BSD_SYSCTL has been\n>     defined (in both configure.ac and meson.build).\n>\n> The first solution above, while simple, adds unnecessary code (the\n> sysinfo compat function is likely implemented using sysctl() anyway)\n> when git is happy to use sysctl() on *BSD systems.\n>\n> The second solution would only be required by the autoconf and meson\n> build systems, the Makefile already sets the build variables to the\n> required values (since they are not 'auto-detected').\n>\n> Here we opt for the final solution above, since it only requires that\n> we prioritise the 'auto-detected' build variables in the autoconf and\n> meson builds.\n\nThe final solution is almost certainly good enough (and is definitely\nsimple), although the second solution has the benefit that it \"fixes\"\nthe problem once and for all even if someone defines both\nHAVE_BSD_SYSCTL and HAVE_SYSINFO (say, in config.mak), assuming I'm\nunderstanding correctly.\n\n> In order to fix the FreeBSD build, move the sysinfo() check after the\n> determination of the HAVE_BSD_SYSCTL build variable, suppressing the\n> setting of HAVE_SYSINFO if HAVE_BSD_SYSCTL is defined. Apply this logic\n> to both the configure.ac and meson.build file.\n\nNicely described. I wasn't really following along with the discussion,\nbut this commit message summarizes the situation well, so I can\nunderstand the reason for the change and (I hope) the implications.\n\n> Tested-by: Renato Botelho <garga@FreeBSD.org>\n> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n"},{"id":"521446","messageId":"xmqqzfdg3t78.fsf@gitster.g","threadId":"63743","inReplyTo":"CAPig+cTybBgkwFEsMVNNu2o1w9T5qnhau4chvGU2opEPJO78zg@mail.gmail.com","subject":"Re: [PATCH] build: fix FreeBSD build when sysinfo compat library installed","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-07-07T15:40:27Z","receivedAt":"2025-07-07T15:40:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n>>     need to link a separate library (-lsysinfo). (This would require\n>>     a similar change to meson.build).\n>>\n>>   - change the order of the preprocessor conditionals in the total_ram()\n>>     function in 'builtin/gc.c', so that the *BSD sysctl() function\n>>     (in the HAVE_BSD_SYSCTL block) takes priority over the sysinfo()\n>>     function (in the HAVE_SYSINFO block).\n>>\n>>   - suppress the setting of HAVE_SYSINFO when HAVE_BSD_SYSCTL has been\n>>     defined (in both configure.ac and meson.build).\n>> ...\n>> The second solution would only be required by the autoconf and meson\n>> build systems, the Makefile already sets the build variables to the\n>> required values (since they are not 'auto-detected').\n> ...\n> The final solution is almost certainly good enough (and is definitely\n> simple), although the second solution has the benefit that it \"fixes\"\n> the problem once and for all even if someone defines both\n> HAVE_BSD_SYSCTL and HAVE_SYSINFO (say, in config.mak), assuming I'm\n> understanding correctly.\n\nYeah, I think I agree with this assessment.\n\n>> In order to fix the FreeBSD build, move the sysinfo() check after the\n>> determination of the HAVE_BSD_SYSCTL build variable, suppressing the\n>> setting of HAVE_SYSINFO if HAVE_BSD_SYSCTL is defined. Apply this logic\n>> to both the configure.ac and meson.build file.\n>\n> Nicely described. I wasn't really following along with the discussion,\n> but this commit message summarizes the situation well, so I can\n> understand the reason for the change and (I hope) the implications.\n\nAgreed.  Thanks, all.\n"},{"id":"521452","messageId":"ba0a3469-3a4d-44f4-b1b8-d9c1a825cb94@ramsayjones.plus.com","threadId":"63743","inReplyTo":"xmqqzfdg3t78.fsf@gitster.g","subject":"Re: [PATCH] build: fix FreeBSD build when sysinfo compat library installed","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2025-07-07T16:51:22Z","receivedAt":"2025-07-07T16:54:33Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\n\nOn 07/07/2025 16:40, Junio C Hamano wrote:\n> Eric Sunshine <sunshine@sunshineco.com> writes:\n> \n>>>     need to link a separate library (-lsysinfo). (This would require\n>>>     a similar change to meson.build).\n>>>\n>>>   - change the order of the preprocessor conditionals in the total_ram()\n>>>     function in 'builtin/gc.c', so that the *BSD sysctl() function\n>>>     (in the HAVE_BSD_SYSCTL block) takes priority over the sysinfo()\n>>>     function (in the HAVE_SYSINFO block).\n>>>\n>>>   - suppress the setting of HAVE_SYSINFO when HAVE_BSD_SYSCTL has been\n>>>     defined (in both configure.ac and meson.build).\n>>> ...\n>>> The second solution would only be required by the autoconf and meson\n>>> build systems, the Makefile already sets the build variables to the\n>>> required values (since they are not 'auto-detected').\n>> ...\n>> The final solution is almost certainly good enough (and is definitely\n>> simple), although the second solution has the benefit that it \"fixes\"\n>> the problem once and for all even if someone defines both\n>> HAVE_BSD_SYSCTL and HAVE_SYSINFO (say, in config.mak), assuming I'm\n>> understanding correctly.\n> \n> Yeah, I think I agree with this assessment.\n\n[Sorry for the late reply - real life keeps getting in the way!]\n\nYep, I thought about including this fix *in addition to* the solution\nimplemented in this patch, but decided that the chances that anyone would\nset both in a Makefile build was practically zero. (famous last words ;) ).\n\nOf course, practically zero is not zero, so we could do this in a\nfollow-up patch if we wanted to take a more conservative approach.\n(Carlos has a series in progress which would conflict with such a\npatch - but the conflict resolution would be simple).\n\n>>> In order to fix the FreeBSD build, move the sysinfo() check after the\n>>> determination of the HAVE_BSD_SYSCTL build variable, suppressing the\n>>> setting of HAVE_SYSINFO if HAVE_BSD_SYSCTL is defined. Apply this logic\n>>> to both the configure.ac and meson.build file.\n>>\n>> Nicely described. I wasn't really following along with the discussion,\n>> but this commit message summarizes the situation well, so I can\n>> understand the reason for the change and (I hope) the implications.\n> \n> Agreed.  Thanks, all.\n\nThanks!\n\nLet me know if you would like that follow-up patch.\n\nATB,\nRamsay Jones\n\n\n\n"},{"id":"521453","messageId":"77b52fde-e1f7-4193-a1c0-1aea94b22e69@ramsayjones.plus.com","threadId":"63743","inReplyTo":"ba0a3469-3a4d-44f4-b1b8-d9c1a825cb94@ramsayjones.plus.com","subject":"Re: [PATCH] build: fix FreeBSD build when sysinfo compat library installed","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2025-07-07T16:58:08Z","receivedAt":"2025-07-07T16:58:13Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\n\nOn 07/07/2025 17:51, Ramsay Jones wrote:\n> \n> \n> On 07/07/2025 16:40, Junio C Hamano wrote:\n>> Eric Sunshine <sunshine@sunshineco.com> writes:\n>>\n>>>>     need to link a separate library (-lsysinfo). (This would require\n>>>>     a similar change to meson.build).\n>>>>\n>>>>   - change the order of the preprocessor conditionals in the total_ram()\n>>>>     function in 'builtin/gc.c', so that the *BSD sysctl() function\n>>>>     (in the HAVE_BSD_SYSCTL block) takes priority over the sysinfo()\n>>>>     function (in the HAVE_SYSINFO block).\n>>>>\n>>>>   - suppress the setting of HAVE_SYSINFO when HAVE_BSD_SYSCTL has been\n>>>>     defined (in both configure.ac and meson.build).\n>>>> ...\n>>>> The second solution would only be required by the autoconf and meson\n>>>> build systems, the Makefile already sets the build variables to the\n>>>> required values (since they are not 'auto-detected').\n>>> ...\n>>> The final solution is almost certainly good enough (and is definitely\n>>> simple), although the second solution has the benefit that it \"fixes\"\n>>> the problem once and for all even if someone defines both\n>>> HAVE_BSD_SYSCTL and HAVE_SYSINFO (say, in config.mak), assuming I'm\n>>> understanding correctly.\n>>\n>> Yeah, I think I agree with this assessment.\n> \n> [Sorry for the late reply - real life keeps getting in the way!]\n> \n> Yep, I thought about including this fix *in addition to* the solution\n> implemented in this patch, but decided that the chances that anyone would\n> set both in a Makefile build was practically zero. (famous last words ;) ).\n> \n> Of course, practically zero is not zero, so we could do this in a\n> follow-up patch if we wanted to take a more conservative approach.\n> (Carlos has a series in progress which would conflict with such a\n\nSigh, sorry, Carlo.\n\nATB,\nRamsay Jones\n\n\n"},{"id":"521455","messageId":"xmqqh5zo3oxt.fsf@gitster.g","threadId":"63743","inReplyTo":"ba0a3469-3a4d-44f4-b1b8-d9c1a825cb94@ramsayjones.plus.com","subject":"Re: [PATCH] build: fix FreeBSD build when sysinfo compat library installed","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-07-07T17:12:30Z","receivedAt":"2025-07-07T17:12:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramsay Jones <ramsay@ramsayjones.plus.com> writes:\n\n> Of course, practically zero is not zero, so we could do this in a\n> follow-up patch if we wanted to take a more conservative approach.\n> (Carlos has a series in progress which would conflict with such a\n> patch - but the conflict resolution would be simple).\n> ...\n> Let me know if you would like that follow-up patch.\n\nNah, I think good enough is good enough.  Not worth spending more\nbraincycles on it.  Unless you absolutely do not have anything\nbetter to do, that is ;-)\n\nIf somebody really finds the \"practically zero\" solution disturbing,\nthey can do a follow-up after the dust settles, of course.\n"}]}