Richard W.M. Jones
2020-Apr-23 17:04 UTC
Re: [Libguestfs] [PATCH nbdkit] golang: Compile against the local nbdkit build, not installed.
On Thu, Apr 23, 2020 at 05:58:25PM +0100, Daniel P. Berrangé wrote:> On Thu, Apr 23, 2020 at 05:55:14PM +0100, Richard W.M. Jones wrote: > > When compiling when an older nbdkit is installed, the build would fail > > because certain symbols such as .get_ready were not defined: > > > > ../../src/libguestfs.org/nbdkit/nbdkit.go:541:8: plugin.get_ready undefined (type _Ctype_struct_nbdkit_plugin has no field or method get_ready) > > > > This happens because we were using the installed <nbdkit-plugin.h> > > rather than the local copy. > > > > We don't want to modify the *.go files themselves as they might be > > copied into other projects. Instead we can set PKG_CONFIG to point to > > a fake pkg-config binary which will return the correct CFLAGS. > > > > Fixes: commit 1ff44288ae1cf95428283e252edd9474c3fe3b55 > > Thanks: Dan Berrangé, Eric Blake > > > +# This fake pkg-config program is used to trick cgo so that > > +# "#cgo pkg-config nbdkit" lines are processed relative to the local > > +# directory and not the installed nbdkit. > > + > > +case "$1" in > > + --cflags*) echo "-I@abs_top_builddir@/include" ;; > > + *) ;; > > +esac > > Don't you need something like this too: > > --libs) echo "-L@abs_top_builddir@/lib -lnbdkit"We don't actually have "libnbdkit". It was proposed a while back but we didn't get sufficient review feedback, and the code was very complex and unmaintainable so it never made it upstream. cgo currently issues the following two commands: $PKG_CONFIG --cflags -- nbdkit nbdkit nbdkit $PKG_CONFIG --libs -- nbdkit nbdkit nbdkit and yes I also don't know why it prints the package name 3 times.> The installed nbdkit.pc would do this I presume. Or are you happy relying > on the allow undefined symbols LDFLAGSA "local" nbdkit.pc might indeed be better because we'd be using pkg-config itself to parse the command line. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Daniel P. Berrangé
2020-Apr-23 17:06 UTC
Re: [Libguestfs] [PATCH nbdkit] golang: Compile against the local nbdkit build, not installed.
On Thu, Apr 23, 2020 at 06:04:20PM +0100, Richard W.M. Jones wrote:> On Thu, Apr 23, 2020 at 05:58:25PM +0100, Daniel P. Berrangé wrote: > > On Thu, Apr 23, 2020 at 05:55:14PM +0100, Richard W.M. Jones wrote: > > > When compiling when an older nbdkit is installed, the build would fail > > > because certain symbols such as .get_ready were not defined: > > > > > > ../../src/libguestfs.org/nbdkit/nbdkit.go:541:8: plugin.get_ready undefined (type _Ctype_struct_nbdkit_plugin has no field or method get_ready) > > > > > > This happens because we were using the installed <nbdkit-plugin.h> > > > rather than the local copy. > > > > > > We don't want to modify the *.go files themselves as they might be > > > copied into other projects. Instead we can set PKG_CONFIG to point to > > > a fake pkg-config binary which will return the correct CFLAGS. > > > > > > Fixes: commit 1ff44288ae1cf95428283e252edd9474c3fe3b55 > > > Thanks: Dan Berrangé, Eric Blake > > > > > +# This fake pkg-config program is used to trick cgo so that > > > +# "#cgo pkg-config nbdkit" lines are processed relative to the local > > > +# directory and not the installed nbdkit. > > > + > > > +case "$1" in > > > + --cflags*) echo "-I@abs_top_builddir@/include" ;; > > > + *) ;; > > > +esac > > > > Don't you need something like this too: > > > > --libs) echo "-L@abs_top_builddir@/lib -lnbdkit" > > We don't actually have "libnbdkit". It was proposed a while back but > we didn't get sufficient review feedback, and the code was very > complex and unmaintainable so it never made it upstream.Ah I see then.> cgo currently issues the following two commands: > > $PKG_CONFIG --cflags -- nbdkit nbdkit nbdkit > $PKG_CONFIG --libs -- nbdkit nbdkit nbdkit > > and yes I also don't know why it prints the package name 3 times.You have three .go files which have the pkg-config stanza in them. It is just combining them all and not bothering to eliminate duplicates as they're harmless> > > The installed nbdkit.pc would do this I presume. Or are you happy relying > > on the allow undefined symbols LDFLAGS > > A "local" nbdkit.pc might indeed be better because we'd be using > pkg-config itself to parse the command line.Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Richard W.M. Jones
2020-Apr-23 17:09 UTC
Re: [Libguestfs] [PATCH nbdkit] golang: Compile against the local nbdkit build, not installed.
On Thu, Apr 23, 2020 at 06:06:12PM +0100, Daniel P. Berrangé wrote:> On Thu, Apr 23, 2020 at 06:04:20PM +0100, Richard W.M. Jones wrote: > > On Thu, Apr 23, 2020 at 05:58:25PM +0100, Daniel P. Berrangé wrote: > > > On Thu, Apr 23, 2020 at 05:55:14PM +0100, Richard W.M. Jones wrote: > > > > When compiling when an older nbdkit is installed, the build would fail > > > > because certain symbols such as .get_ready were not defined: > > > > > > > > ../../src/libguestfs.org/nbdkit/nbdkit.go:541:8: plugin.get_ready undefined (type _Ctype_struct_nbdkit_plugin has no field or method get_ready) > > > > > > > > This happens because we were using the installed <nbdkit-plugin.h> > > > > rather than the local copy. > > > > > > > > We don't want to modify the *.go files themselves as they might be > > > > copied into other projects. Instead we can set PKG_CONFIG to point to > > > > a fake pkg-config binary which will return the correct CFLAGS. > > > > > > > > Fixes: commit 1ff44288ae1cf95428283e252edd9474c3fe3b55 > > > > Thanks: Dan Berrangé, Eric Blake > > > > > > > +# This fake pkg-config program is used to trick cgo so that > > > > +# "#cgo pkg-config nbdkit" lines are processed relative to the local > > > > +# directory and not the installed nbdkit. > > > > + > > > > +case "$1" in > > > > + --cflags*) echo "-I@abs_top_builddir@/include" ;; > > > > + *) ;; > > > > +esac > > > > > > Don't you need something like this too: > > > > > > --libs) echo "-L@abs_top_builddir@/lib -lnbdkit" > > > > We don't actually have "libnbdkit". It was proposed a while back but > > we didn't get sufficient review feedback, and the code was very > > complex and unmaintainable so it never made it upstream. > > Ah I see then. > > > cgo currently issues the following two commands: > > > > $PKG_CONFIG --cflags -- nbdkit nbdkit nbdkit > > $PKG_CONFIG --libs -- nbdkit nbdkit nbdkit > > > > and yes I also don't know why it prints the package name 3 times. > > You have three .go files which have the pkg-config stanza in them. > It is just combining them all and not bothering to eliminate duplicates > as they're harmlessAh yes, good point! Rich.> > > > > The installed nbdkit.pc would do this I presume. Or are you happy relying > > > on the allow undefined symbols LDFLAGS > > > > A "local" nbdkit.pc might indeed be better because we'd be using > > pkg-config itself to parse the command line. > > Regards, > Daniel > -- > |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| > |: https://libvirt.org -o- https://fstop138.berrange.com :| > |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Reasonably Related Threads
- Re: [PATCH nbdkit] golang: Compile against the local nbdkit build, not installed.
- Re: [PATCH nbdkit] golang: Compile against the local nbdkit build, not installed.
- [PATCH nbdkit] golang: Compile against the local nbdkit build, not installed.
- Re: [PATCH nbdkit v3 2/2] golang: Compile against the local nbdkit build, not installed.
- [PATCH nbdkit 2/2] golang: Compile against the local nbdkit build, not installed.