Richard W.M. Jones
2020-Apr-23 18:04 UTC
[Libguestfs] [PATCH nbdkit 0/2 v2] golang: Compile against the local nbdkit build.
Version 1 was here: https://www.redhat.com/archives/libguestfs/2020-April/thread.html#00160 Version 2 side-steps the objections to the first patch by using a well-formed alternate nbdkit.pc file and running ordinary pkg-config against it, so any parsing of --cflags etc will be done by pkg-config. The first patch is essentially the same idea as: https://github.com/libguestfs/libnbd/commit/dc87a1a6d6918ac5477e1d6b225998ff7fedc86e (which follows on from similar tricks in libguestfs and libvirt). Rich.
Richard W.M. Jones
2020-Apr-23 18:04 UTC
[Libguestfs] [PATCH nbdkit 1/2] server: Add pkg-config file to compile against locally compiled nbdkit.
In most cases it is incorrect to use this - pay attention to the note at the top of the newly added file. --- .gitignore | 1 + configure.ac | 1 + server/local/nbdkit.pc.in | 45 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/.gitignore b/.gitignore index 4f6fcf1b..8c701295 100644 --- a/.gitignore +++ b/.gitignore @@ -83,6 +83,7 @@ plugins/*/*.3 /plugins/tar/nbdkit-tar-plugin /plugins/tmpdisk/default-command.c /podwrapper.pl +/server/local/nbdkit.pc /server/nbdkit /server/nbdkit.pc /server/synopsis.c diff --git a/configure.ac b/configure.ac index b71d9d8c..17d8d676 100644 --- a/configure.ac +++ b/configure.ac @@ -1088,6 +1088,7 @@ AC_CONFIG_FILES([Makefile filters/truncate/Makefile filters/xz/Makefile fuzzing/Makefile + server/local/nbdkit.pc server/Makefile server/nbdkit.pc tests/functions.sh diff --git a/server/local/nbdkit.pc.in b/server/local/nbdkit.pc.in new file mode 100644 index 00000000..96c33d2f --- /dev/null +++ b/server/local/nbdkit.pc.in @@ -0,0 +1,45 @@ +# nbdkit +# Copyright (C) 2013-2020 Red Hat Inc. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of Red Hat nor the names of its contributors may be +# used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +# This alternate pkg-config file may be used to compile plugins +# against a locally compiled (but not installed) nbdkit. Note you +# probably should *not* use this in most cases, since your plugin will +# may end up containing hard paths to the local nbdkit sources. + +prefix=@abs_top_builddir@ +exec_prefix=@abs_top_builddir@ + +Name: @PACKAGE_NAME@ +Version: @PACKAGE_VERSION@ +Description: A toolkit for creating NBD servers +Requires: +Cflags: -I@abs_top_srcdir@/include -I@abs_top_builddir@/include +Libs: -- 2.18.2
Richard W.M. Jones
2020-Apr-23 18:04 UTC
[Libguestfs] [PATCH nbdkit 2/2] golang: Compile against the local nbdkit build, not installed.
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_PATH to point to the local nbdkit.pc which will return the correct CFLAGS. Fixes: commit 1ff44288ae1cf95428283e252edd9474c3fe3b55 Thanks: Dan Berrangé, Eric Blake --- plugins/golang/Makefile.am | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/golang/Makefile.am b/plugins/golang/Makefile.am index f189184c..d8d19b7a 100644 --- a/plugins/golang/Makefile.am +++ b/plugins/golang/Makefile.am @@ -66,18 +66,21 @@ noinst_DATA = \ examples/dump-plugin/nbdkit-godump-plugin.so: \ $(plugin_sources) examples/dump-plugin/dumpplugin.go cd examples/dump-plugin && \ + PKG_CONFIG_PATH="$(abs_builddir)/server/local" \ GOPATH="$(abs_builddir)" \ $(GOLANG) build -o nbdkit-godump-plugin.so -buildmode=c-shared examples/minimal/nbdkit-gominimal-plugin.so: \ $(plugin_sources) examples/minimal/minimal.go cd examples/minimal && \ + PKG_CONFIG_PATH="$(abs_builddir)/server/local" \ GOPATH="$(abs_builddir)" \ $(GOLANG) build -o nbdkit-gominimal-plugin.so -buildmode=c-shared examples/ramdisk/nbdkit-goramdisk-plugin.so: \ $(plugin_sources) examples/ramdisk/ramdisk.go cd examples/ramdisk && \ + PKG_CONFIG_PATH="$(abs_builddir)/server/local" \ GOPATH="$(abs_builddir)" \ $(GOLANG) build -o nbdkit-goramdisk-plugin.so -buildmode=c-shared @@ -87,6 +90,7 @@ check_DATA = test/nbdkit-gotest-plugin.so test/nbdkit-gotest-plugin.so: $(plugin_sources) test/test.go cd test && \ + PKG_CONFIG_PATH="$(abs_builddir)/server/local" \ GOPATH="$(abs_builddir)" \ $(GOLANG) build -o nbdkit-gotest-plugin.so -buildmode=c-shared -- 2.18.2
Daniel P. Berrangé
2020-Apr-23 18:06 UTC
Re: [Libguestfs] [PATCH nbdkit 0/2 v2] golang: Compile against the local nbdkit build.
On Thu, Apr 23, 2020 at 07:04:13PM +0100, Richard W.M. Jones wrote:> Version 1 was here: > https://www.redhat.com/archives/libguestfs/2020-April/thread.html#00160 > > Version 2 side-steps the objections to the first patch by using a > well-formed alternate nbdkit.pc file and running ordinary pkg-config > against it, so any parsing of --cflags etc will be done by pkg-config. > > The first patch is essentially the same idea as: > > https://github.com/libguestfs/libnbd/commit/dc87a1a6d6918ac5477e1d6b225998ff7fedc86e > > (which follows on from similar tricks in libguestfs and libvirt).For both patches Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> 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 18:08 UTC
Re: [Libguestfs] [PATCH nbdkit 1/2] server: Add pkg-config file to compile against locally compiled nbdkit.
On Thu, Apr 23, 2020 at 07:04:14PM +0100, Richard W.M. Jones wrote:> +# probably should *not* use this in most cases, since your plugin will > +# may end up containing hard paths to the local nbdkit sources."will may" -> "may" in my local copy. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Eric Blake
2020-Apr-23 18:22 UTC
Re: [Libguestfs] [PATCH nbdkit 2/2] golang: Compile against the local nbdkit build, not installed.
On 4/23/20 1:04 PM, 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_PATH to > point to the local nbdkit.pc which will return the correct CFLAGS. > > Fixes: commit 1ff44288ae1cf95428283e252edd9474c3fe3b55 > Thanks: Dan Berrangé, Eric Blake > --- > plugins/golang/Makefile.am | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/plugins/golang/Makefile.am b/plugins/golang/Makefile.am > index f189184c..d8d19b7a 100644 > --- a/plugins/golang/Makefile.am > +++ b/plugins/golang/Makefile.am > @@ -66,18 +66,21 @@ noinst_DATA = \ > examples/dump-plugin/nbdkit-godump-plugin.so: \ > $(plugin_sources) examples/dump-plugin/dumpplugin.go > cd examples/dump-plugin && \ > + PKG_CONFIG_PATH="$(abs_builddir)/server/local" \Shouldn't this be more like: PKG_CONFIG_PATH="$(abs_builddir)/server/local$${PKG_CONFIG_PATH:-:$$PKG_CONFIG_PATH}" so as to preserve any inherited override locations for other .pc files that might also be needed by cgo? -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Seemingly Similar Threads
- Re: [PATCH nbdkit 1/2] server: Add pkg-config file to compile against locally compiled nbdkit.
- [PATCH nbdkit INCOMPLETE 0/6] Introduce filters to nbdkit.
- Re: [PATCH nbdkit filters-v2 2/5] Introduce filters.
- [PATCH nbdkit 1/2] server: Add pkg-config file to compile against locally compiled nbdkit.
- [PATCH nbdkit filters-v3 0/7] Introduce filters.