diff mbox series

[1/1] libnfs: fix build of applications like mpd on musl

Message ID 20180922194305.27608-1-fontaine.fabrice@gmail.com
State Not Applicable
Headers show
Series [1/1] libnfs: fix build of applications like mpd on musl | expand

Commit Message

Fabrice Fontaine Sept. 22, 2018, 7:43 p.m. UTC
Include sys/time.h if __linux__ is defined otherwise applications
including libnfs.h (such as mpd) will fail to build on musl:

/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/bin/x86_64-linux-g++ -DHAVE_CONFIG_H -I.  -DNDEBUG -I./src  -DSYSTEM_CONFIG_FILE_LOCATION='"/etc/mpd.conf"'  -I/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/bin/../x86_64-buildroot-linux-musl/sysroot/usr/include   -I/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/bin/../x86_64-buildroot-linux-musl/sysroot/usr/include    -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -pthread -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -Os   -fvisibility=hidden -fno-threadsafe-statics -fmerge-all-constants -ffast-math -ftree-vectorize -ffunction-sections -fdata-sections -Wall -Wextra -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings -Wsign-compare -Wno-noexcept-type -c -o src/lib/nfs/libstorage_a-Error.o `test -f 'src/lib/nfs/Error.cxx' || echo './'`src/lib/nfs/Error.cxx
In file included from src/lib/nfs/Error.cxx:37:0:
/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/x86_64-buildroot-linux-musl/sysroot/usr/include/nfsc/libnfs.h:965:23: error: field 'atime' has incomplete type 'timeval'
        struct timeval atime;
                       ^~~~~
/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/x86_64-buildroot-linux-musl/sysroot/usr/include/nfsc/libnfs.h:965:15: note: forward declaration of 'struct timeval'
        struct timeval atime;

Fixes:
 - http://autobuild.buildroot.org/results/892469e34cb2f7e8fac4a79f8c51ca8e7235aef3

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
---
 ...nally-include-sys-time.h-in-libnfs.h.patch | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 package/libnfs/0001-conditionally-include-sys-time.h-in-libnfs.h.patch

Comments

Thomas Petazzoni Sept. 23, 2018, 2:52 p.m. UTC | #1
Hello,

On Sat, 22 Sep 2018 21:43:05 +0200, Fabrice Fontaine wrote:

> + #include <stdint.h>
> +-#if defined(__ANDROID__) || defined(AROS) \
> ++#if defined(__ANDROID__) || defined(AROS) || defined(__linux__) \
> +  || ( defined(__APPLE__) && defined(__MACH__) )
> + #include <sys/time.h>
> + #else

I think the proper fix would be to use the AC_HEADER_TIME macro
(https://www.gnu.org/software/autoconf/manual/autoconf.html#Particular-Headers).
First need to add:

AC_HEADER_TIME
AC_CHECK_HEADERS([sys/time.h])

And then in the code, do:

          #ifdef TIME_WITH_SYS_TIME
          # include <sys/time.h>
          # include <time.h>
          #else
          # ifdef HAVE_SYS_TIME_H
          #  include <sys/time.h>
          # else
          #  include <time.h>
          # endif
          #endif

Instead of the mess that is currently done based on the system on which
the stuff is being compiled.

Could you try to do this, and upstream the corresponding patch ?

Thanks,

Thomas
Fabrice Fontaine Sept. 23, 2018, 4:24 p.m. UTC | #2
Dear Thomas,

Le dim. 23 sept. 2018 à 16:52, Thomas Petazzoni <
thomas.petazzoni@bootlin.com> a écrit :

> Hello,
>
> On Sat, 22 Sep 2018 21:43:05 +0200, Fabrice Fontaine wrote:
>
> > + #include <stdint.h>
> > +-#if defined(__ANDROID__) || defined(AROS) \
> > ++#if defined(__ANDROID__) || defined(AROS) || defined(__linux__) \
> > +  || ( defined(__APPLE__) && defined(__MACH__) )
> > + #include <sys/time.h>
> > + #else
>
> I think the proper fix would be to use the AC_HEADER_TIME macro
> (
> https://www.gnu.org/software/autoconf/manual/autoconf.html#Particular-Headers
> ).
> First need to add:
>
> AC_HEADER_TIME
> AC_CHECK_HEADERS([sys/time.h])
>
> And then in the code, do:
>
>           #ifdef TIME_WITH_SYS_TIME
>           # include <sys/time.h>
>           # include <time.h>
>           #else
>           # ifdef HAVE_SYS_TIME_H
>           #  include <sys/time.h>
>           # else
>           #  include <time.h>
>           # endif
>           #endif
>
> Instead of the mess that is currently done based on the system on which
> the stuff is being compiled.
>
> Could you try to do this, and upstream the corresponding patch ?
>
Actually, that's what has been done upstream for libnfs.c (
https://github.com/sahlberg/libnfs/commit/5c1444f391f8c29cc18fd644ab282b5a037e5798)
but this will not fix our issue.
Indeed, the build is not failing on libnfs but on mpd because mpd includes
libnfs.h which is a public header.
We can't enforce that all applications that use libnfs.h such as mpd should
make a call to AC_HEADER_TIME or AC_CHECK_HEADERS([sys/time.h]), do we?

>
> Thanks,
>
> Thomas
> --
> Thomas Petazzoni, CTO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com

Best Regards,

Fabrice
<div dir="ltr"><div dir="ltr"><div>Dear Thomas,</div><br><div class="gmail_quote"><div dir="ltr">Le dim. 23 sept. 2018 à 16:52, Thomas Petazzoni &lt;<a href="mailto:thomas.petazzoni@bootlin.com">thomas.petazzoni@bootlin.com</a>&gt; a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
On Sat, 22 Sep 2018 21:43:05 +0200, Fabrice Fontaine wrote:<br>
<br>
&gt; + #include &lt;stdint.h&gt;<br>
&gt; +-#if defined(__ANDROID__) || defined(AROS) \<br>
&gt; ++#if defined(__ANDROID__) || defined(AROS) || defined(__linux__) \<br>
&gt; +  || ( defined(__APPLE__) &amp;&amp; defined(__MACH__) )<br>
&gt; + #include &lt;sys/time.h&gt;<br>
&gt; + #else<br>
<br>
I think the proper fix would be to use the AC_HEADER_TIME macro<br>
(<a href="https://www.gnu.org/software/autoconf/manual/autoconf.html#Particular-Headers" rel="noreferrer" target="_blank">https://www.gnu.org/software/autoconf/manual/autoconf.html#Particular-Headers</a>).<br>
First need to add:<br>
<br>
AC_HEADER_TIME<br>
AC_CHECK_HEADERS([sys/time.h])<br>
<br>
And then in the code, do:<br>
<br>
          #ifdef TIME_WITH_SYS_TIME<br>
          # include &lt;sys/time.h&gt;<br>
          # include &lt;time.h&gt;<br>
          #else<br>
          # ifdef HAVE_SYS_TIME_H<br>
          #  include &lt;sys/time.h&gt;<br>
          # else<br>
          #  include &lt;time.h&gt;<br>
          # endif<br>
          #endif<br>
<br>
Instead of the mess that is currently done based on the system on which<br>
the stuff is being compiled.<br>
<br>
Could you try to do this, and upstream the corresponding patch ?<br></blockquote><div>Actually, that&#39;s what has been done upstream for libnfs.c (<a href="https://github.com/sahlberg/libnfs/commit/5c1444f391f8c29cc18fd644ab282b5a037e5798">https://github.com/sahlberg/libnfs/commit/5c1444f391f8c29cc18fd644ab282b5a037e5798</a>) but this will not fix our issue.</div><div>Indeed, the build is not failing on libnfs but on mpd because mpd includes libnfs.h which is a public header.</div><div>We can&#39;t enforce that all applications that use libnfs.h such as mpd should make a call to AC_HEADER_TIME or AC_CHECK_HEADERS([sys/time.h]), do we?</div><div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Thanks,<br>
<br>
Thomas<br>
-- <br>
Thomas Petazzoni, CTO, Bootlin<br>
Embedded Linux and Kernel engineering<br>
<a href="https://bootlin.com" rel="noreferrer" target="_blank">https://bootlin.com</a></blockquote><div>Best Regards,</div><div><br></div><div>Fabrice<br></div></div></div></div>
diff mbox series

Patch

diff --git a/package/libnfs/0001-conditionally-include-sys-time.h-in-libnfs.h.patch b/package/libnfs/0001-conditionally-include-sys-time.h-in-libnfs.h.patch
new file mode 100644
index 0000000000..80b4fdca70
--- /dev/null
+++ b/package/libnfs/0001-conditionally-include-sys-time.h-in-libnfs.h.patch
@@ -0,0 +1,40 @@ 
+From e2b7bcfbc38336d12dfdd4e36af87be4352a16a9 Mon Sep 17 00:00:00 2001
+From: Fabrice Fontaine <fontaine.fabrice@gmail.com>
+Date: Sat, 22 Sep 2018 13:27:18 +0200
+Subject: [PATCH] conditionally include sys/time.h in libnfs.h
+
+Include sys/time.h if __linux__ is defined otherwise applications
+including libnfs.h (such as mpd) will fail to build on musl:
+
+/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/bin/x86_64-linux-g++ -DHAVE_CONFIG_H -I.  -DNDEBUG -I./src  -DSYSTEM_CONFIG_FILE_LOCATION='"/etc/mpd.conf"'  -I/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/bin/../x86_64-buildroot-linux-musl/sysroot/usr/include   -I/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/bin/../x86_64-buildroot-linux-musl/sysroot/usr/include    -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -pthread -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -Os   -fvisibility=hidden -fno-threadsafe-statics -fmerge-all-constants -ffast-math -ftree-vectorize -ffunction-sections -fdata-sections -Wall -Wextra -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings -Wsign-compare -Wno-noexcept-type -c -o src/lib/nfs/libstorage_a-Error.o `test -f 'src/lib/nfs/Error.cxx' || echo './'`src/lib/nfs/Error.cxx
+In file included from src/lib/nfs/Error.cxx:37:0:
+/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/x86_64-buildroot-linux-musl/sysroot/usr/include/nfsc/libnfs.h:965:23: error: field 'atime' has incomplete type 'timeval'
+        struct timeval atime;
+                       ^~~~~
+/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/x86_64-buildroot-linux-musl/sysroot/usr/include/nfsc/libnfs.h:965:15: note: forward declaration of 'struct timeval'
+        struct timeval atime;
+
+Fixes:
+ - http://autobuild.buildroot.org/results/892469e34cb2f7e8fac4a79f8c51ca8e7235aef3
+
+Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
+---
+ include/nfsc/libnfs.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/include/nfsc/libnfs.h b/include/nfsc/libnfs.h
+index 09dcf1c..23dcc98 100755
+--- a/include/nfsc/libnfs.h
++++ b/include/nfsc/libnfs.h
+@@ -24,7 +24,7 @@
+ #define _LIBNFS_H_
+ 
+ #include <stdint.h>
+-#if defined(__ANDROID__) || defined(AROS) \
++#if defined(__ANDROID__) || defined(AROS) || defined(__linux__) \
+  || ( defined(__APPLE__) && defined(__MACH__) )
+ #include <sys/time.h>
+ #else
+-- 
+2.17.1
+