[libvirt] [PATCH 0/2] fix build on macOS

This series fixes too issues. - rpcgen issue. rpcgen(1) that comes with macOS is too old. I've grabbed rpcgen from FreeBSD and created a brew formula for it[1]. I configure it like: ./configure ac_cv_path_RPCGEN=/usr/local/bin/bsdrpcgen It still requires darwin to be added to the fixup list in genprotocol.pl - macOS doesn't support clock_gettime(3), so use its own routnes 1: https://gist.github.com/novel/0d74cdbc7b71f60640a42b52c9cc1459 Roman Bogorodskiy (2): genprotocol.pl: add darwing to fixup list tests: fix eventtest build on macOS configure.ac | 9 +++++++++ src/rpc/genprotocol.pl | 2 +- tests/Makefile.am | 2 +- tests/eventtest.c | 16 ++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) -- 2.10.2

--- src/rpc/genprotocol.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/genprotocol.pl b/src/rpc/genprotocol.pl index 1ac2507..69d20a3 100755 --- a/src/rpc/genprotocol.pl +++ b/src/rpc/genprotocol.pl @@ -46,7 +46,7 @@ open RPCGEN, "-|", "$rpcgen $mode $xdrdef" open TARGET, ">$target" or die "cannot create $target: $!"; -my $fixup = $^O eq "linux" || $^O eq "cygwin" || $^O eq "gnukfreebsd" || $^O eq "freebsd"; +my $fixup = $^O eq "linux" || $^O eq "cygwin" || $^O eq "gnukfreebsd" || $^O eq "freebsd" || $^O eq "darwin"; if ($mode eq "-c") { print TARGET "#include <config.h>\n"; -- 2.10.2

On Sat, 2016-11-19 at 21:16 +0300, Roman Bogorodskiy wrote:
--- src/rpc/genprotocol.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/rpc/genprotocol.pl b/src/rpc/genprotocol.pl index 1ac2507..69d20a3 100755 --- a/src/rpc/genprotocol.pl +++ b/src/rpc/genprotocol.pl @@ -46,7 +46,7 @@ open RPCGEN, "-|", "$rpcgen $mode $xdrdef" open TARGET, ">$target" or die "cannot create $target: $!";
-my $fixup = $^O eq "linux" || $^O eq "cygwin" || $^O eq "gnukfreebsd" || $^O eq "freebsd"; +my $fixup = $^O eq "linux" || $^O eq "cygwin" || $^O eq "gnukfreebsd" || $^O eq "freebsd" || $^O eq "darwin";
if ($mode eq "-c") { print TARGET "#include <config.h>\n";
ACK -- Andrea Bolognani / Red Hat / Virtualization

Andrea Bolognani wrote:
On Sat, 2016-11-19 at 21:16 +0300, Roman Bogorodskiy wrote:
--- src/rpc/genprotocol.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/rpc/genprotocol.pl b/src/rpc/genprotocol.pl index 1ac2507..69d20a3 100755 --- a/src/rpc/genprotocol.pl +++ b/src/rpc/genprotocol.pl @@ -46,7 +46,7 @@ open RPCGEN, "-|", "$rpcgen $mode $xdrdef" open TARGET, ">$target" or die "cannot create $target: $!";
-my $fixup = $^O eq "linux" || $^O eq "cygwin" || $^O eq "gnukfreebsd" || $^O eq "freebsd"; +my $fixup = $^O eq "linux" || $^O eq "cygwin" || $^O eq "gnukfreebsd" || $^O eq "freebsd" || $^O eq "darwin";
if ($mode eq "-c") { print TARGET "#include <config.h>\n";
ACK
Pushed with darwinG -> darwin typo fix, thanks! Roman Bogorodskiy

macOS doesn't support clock_gettime(2), at least versions prior 10.12 (I didn't actually check 10.12 though). So, use its own routines in eventtest. * configure.ac: check for requires symbols and define HAVE_MACH_CLOCK_ROUTINES if found * tests/eventtest.c: add clock_get_time() based implementation * tests/Makefile.am: don't explicitly LDADD -lrt, use $(LIB_CLOCK_GETTIME) --- configure.ac | 9 +++++++++ tests/Makefile.am | 2 +- tests/eventtest.c | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 66d88c4..c1b0ca0 100644 --- a/configure.ac +++ b/configure.ac @@ -2522,6 +2522,15 @@ AC_CHECK_MEMBERS([struct if_data.ifi_oqdrops], [#include <net/if.h> ]) +AC_CHECK_DECLS([clock_serv_t, host_get_clock_service, clock_get_time], + [AC_DEFINE([HAVE_MACH_CLOCK_ROUTINES], + [1], + [whether Mach clock routines are available])], + [], + [#include <mach/clock.h> + #include <mach/mach.h> + ]) + # Check if we need to look for ifconfig if test "$want_ifconfig" = "yes"; then AC_PATH_PROG([IFCONFIG_PATH], [ifconfig]) diff --git a/tests/Makefile.am b/tests/Makefile.am index 924029a..6a24861 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1310,7 +1310,7 @@ endif WITH_DRIVER_MODULES if WITH_LIBVIRTD eventtest_SOURCES = \ eventtest.c testutils.h testutils.c -eventtest_LDADD = -lrt $(LDADDS) +eventtest_LDADD = $(LIB_CLOCK_GETTIME) $(LDADDS) endif WITH_LIBVIRTD libshunload_la_SOURCES = shunloadhelper.c diff --git a/tests/eventtest.c b/tests/eventtest.c index 011bedc..ed1089e 100644 --- a/tests/eventtest.c +++ b/tests/eventtest.c @@ -26,6 +26,11 @@ #include <signal.h> #include <time.h> +#if HAVE_MACH_CLOCK_ROUTINES +#include <mach/clock.h> +#include <mach/mach.h> +#endif + #include "testutils.h" #include "internal.h" #include "virfile.h" @@ -262,7 +267,18 @@ finishJob(const char *name, int handle, int timer) { struct timespec waitTime; int rc; +#if HAVE_MACH_CLOCK_ROUTINES + clock_serv_t cclock; + mach_timespec_t mts; + + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + waitTime.tv_sec = mts.tv_sec; + waitTime.tv_nsec = mts.tv_nsec; +#else clock_gettime(CLOCK_REALTIME, &waitTime); +#endif waitTime.tv_sec += 5; rc = 0; while (!eventThreadJobDone && rc == 0) -- 2.10.2

On Sat, 2016-11-19 at 21:16 +0300, Roman Bogorodskiy wrote:
macOS doesn't support clock_gettime(2), at least versions prior 10.12 (I didn't actually check 10.12 though). So, use its own routines in eventtest. * configure.ac: check for requires symbols and define HAVE_MACH_CLOCK_ROUTINES if found * tests/eventtest.c: add clock_get_time() based implementation * tests/Makefile.am: don't explicitly LDADD -lrt, use $(LIB_CLOCK_GETTIME) --- configure.ac | 9 +++++++++ tests/Makefile.am | 2 +- tests/eventtest.c | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 66d88c4..c1b0ca0 100644 --- a/configure.ac +++ b/configure.ac @@ -2522,6 +2522,15 @@ AC_CHECK_MEMBERS([struct if_data.ifi_oqdrops], [#include <net/if.h> ]) +AC_CHECK_DECLS([clock_serv_t, host_get_clock_service, clock_get_time], + [AC_DEFINE([HAVE_MACH_CLOCK_ROUTINES], + [1], + [whether Mach clock routines are available])], + [], + [#include <mach/clock.h> + #include <mach/mach.h> + ]) + # Check if we need to look for ifconfig if test "$want_ifconfig" = "yes"; then AC_PATH_PROG([IFCONFIG_PATH], [ifconfig]) diff --git a/tests/Makefile.am b/tests/Makefile.am index 924029a..6a24861 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1310,7 +1310,7 @@ endif WITH_DRIVER_MODULES if WITH_LIBVIRTD eventtest_SOURCES = \ eventtest.c testutils.h testutils.c -eventtest_LDADD = -lrt $(LDADDS) +eventtest_LDADD = $(LIB_CLOCK_GETTIME) $(LDADDS) endif WITH_LIBVIRTD
This is really a separate bugfix, please move this hunk to its own commit.
libshunload_la_SOURCES = shunloadhelper.c diff --git a/tests/eventtest.c b/tests/eventtest.c index 011bedc..ed1089e 100644 --- a/tests/eventtest.c +++ b/tests/eventtest.c @@ -26,6 +26,11 @@ #include <signal.h> #include <time.h> +#if HAVE_MACH_CLOCK_ROUTINES +#include <mach/clock.h> +#include <mach/mach.h>
These two includes trip 'make syntax-check'.
+#endif + #include "testutils.h" #include "internal.h" #include "virfile.h" @@ -262,7 +267,18 @@ finishJob(const char *name, int handle, int timer) { struct timespec waitTime; int rc; +#if HAVE_MACH_CLOCK_ROUTINES + clock_serv_t cclock; + mach_timespec_t mts; + + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + waitTime.tv_sec = mts.tv_sec; + waitTime.tv_nsec = mts.tv_nsec;
I'll assume the macOS code is doing what it's supposed to do, as I have no way of verifying that myself. It looks reasonable enough :)
+#else clock_gettime(CLOCK_REALTIME, &waitTime); +#endif waitTime.tv_sec += 5; rc = 0; while (!eventThreadJobDone && rc == 0)
ACK if you move the LIB_CLOCK_GETTIME fix to its own commit and tweak includes to make syntax-check happy. -- Andrea Bolognani / Red Hat / Virtualization

Andrea Bolognani wrote:
On Sat, 2016-11-19 at 21:16 +0300, Roman Bogorodskiy wrote:
macOS doesn't support clock_gettime(2), at least versions prior 10.12 (I didn't actually check 10.12 though). So, use its own routines in eventtest. * configure.ac: check for requires symbols and define HAVE_MACH_CLOCK_ROUTINES if found * tests/eventtest.c: add clock_get_time() based implementation * tests/Makefile.am: don't explicitly LDADD -lrt, use $(LIB_CLOCK_GETTIME) --- configure.ac | 9 +++++++++ tests/Makefile.am | 2 +- tests/eventtest.c | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 66d88c4..c1b0ca0 100644 --- a/configure.ac +++ b/configure.ac @@ -2522,6 +2522,15 @@ AC_CHECK_MEMBERS([struct if_data.ifi_oqdrops], [#include <net/if.h> ]) +AC_CHECK_DECLS([clock_serv_t, host_get_clock_service, clock_get_time], + [AC_DEFINE([HAVE_MACH_CLOCK_ROUTINES], + [1], + [whether Mach clock routines are available])], + [], + [#include <mach/clock.h> + #include <mach/mach.h> + ]) + # Check if we need to look for ifconfig if test "$want_ifconfig" = "yes"; then AC_PATH_PROG([IFCONFIG_PATH], [ifconfig]) diff --git a/tests/Makefile.am b/tests/Makefile.am index 924029a..6a24861 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1310,7 +1310,7 @@ endif WITH_DRIVER_MODULES if WITH_LIBVIRTD eventtest_SOURCES = \ eventtest.c testutils.h testutils.c -eventtest_LDADD = -lrt $(LDADDS) +eventtest_LDADD = $(LIB_CLOCK_GETTIME) $(LDADDS) endif WITH_LIBVIRTD
This is really a separate bugfix, please move this hunk to its own commit.
libshunload_la_SOURCES = shunloadhelper.c diff --git a/tests/eventtest.c b/tests/eventtest.c index 011bedc..ed1089e 100644 --- a/tests/eventtest.c +++ b/tests/eventtest.c @@ -26,6 +26,11 @@ #include <signal.h> #include <time.h> +#if HAVE_MACH_CLOCK_ROUTINES +#include <mach/clock.h> +#include <mach/mach.h>
These two includes trip 'make syntax-check'.
+#endif + #include "testutils.h" #include "internal.h" #include "virfile.h" @@ -262,7 +267,18 @@ finishJob(const char *name, int handle, int timer) { struct timespec waitTime; int rc; +#if HAVE_MACH_CLOCK_ROUTINES + clock_serv_t cclock; + mach_timespec_t mts; + + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + waitTime.tv_sec = mts.tv_sec; + waitTime.tv_nsec = mts.tv_nsec;
I'll assume the macOS code is doing what it's supposed to do, as I have no way of verifying that myself. It looks reasonable enough :)
+#else clock_gettime(CLOCK_REALTIME, &waitTime); +#endif waitTime.tv_sec += 5; rc = 0; while (!eventThreadJobDone && rc == 0)
ACK if you move the LIB_CLOCK_GETTIME fix to its own commit and tweak includes to make syntax-check happy.
Addressed that and pushed, thanks! Roman Bogorodskiy
participants (2)
-
Andrea Bolognani
-
Roman Bogorodskiy