gnome: make sure the target build directory is passed first for linking

determine_rpath_dirs() can return paths to external dependencies not
in the build dir and passing them first as a link path leads to
g-ir-scanner for example linking against the already installed library
instead of the just built one.

This was reported in g-i: https://gitlab.gnome.org/GNOME/gobject-introspection/issues/272
and comes up quite often when a library adds some new symbols which aren't present in the
system library, which then makes linking fail.

The first place where the order is changed is _scan_gir_targets(), which looks like an unintentional
change in the refactoring in 8377ea45aa

The second place in _get_link_args() has always been that way and only the rpath order is changed,
but it looks to me as if the same rules should apply here too.
pull/5437/head
Christoph Reiter 6 years ago committed by Jussi Pakkanen
parent 9491878681
commit 20eb948b97
  1. 16
      mesonbuild/modules/gnome.py
  2. 42
      test cases/frameworks/28 gir link order 2/meson-sample.c
  3. 17
      test cases/frameworks/28 gir link order 2/meson-sample.h
  4. 35
      test cases/frameworks/28 gir link order 2/meson.build
  5. 5
      test cases/frameworks/28 gir link order 2/samelibname/meson.build

@ -299,6 +299,9 @@ class GnomeModule(ExtensionModule):
if isinstance(lib, build.SharedLibrary):
libdir = os.path.join(state.environment.get_build_dir(), state.backend.get_target_dir(lib))
link_command.append('-L' + libdir)
if include_rpath:
link_command.append('-Wl,-rpath,' + libdir)
depends.append(lib)
# Needed for the following binutils bug:
# https://github.com/mesonbuild/meson/issues/1911
# However, g-ir-scanner does not understand -Wl,-rpath
@ -308,9 +311,6 @@ class GnomeModule(ExtensionModule):
link_command.append('-L' + d)
if include_rpath:
link_command.append('-Wl,-rpath,' + d)
if include_rpath:
link_command.append('-Wl,-rpath,' + libdir)
depends.append(lib)
if gir_has_option(self.interpreter, '--extra-library') and use_gir_args:
link_command.append('--extra-library=' + lib.name)
else:
@ -553,6 +553,11 @@ class GnomeModule(ExtensionModule):
libname = girtarget.get_basename()
else:
libname = os.path.join("@PRIVATE_OUTDIR_ABS_%s@" % girtarget.get_id(), girtarget.get_filename())
ret += ['--library', libname]
# need to put our output directory first as we need to use the
# generated libraries instead of any possibly installed system/prefix
# ones.
ret += ["-L@PRIVATE_OUTDIR_ABS_%s@" % girtarget.get_id()]
# Needed for the following binutils bug:
# https://github.com/mesonbuild/meson/issues/1911
# However, g-ir-scanner does not understand -Wl,-rpath
@ -560,11 +565,6 @@ class GnomeModule(ExtensionModule):
for d in state.backend.determine_rpath_dirs(girtarget):
d = os.path.join(state.environment.get_build_dir(), d)
ret.append('-L' + d)
ret += ['--library', libname]
# need to put our output directory first as we need to use the
# generated libraries instead of any possibly installed system/prefix
# ones.
ret += ["-L@PRIVATE_OUTDIR_ABS_%s@" % girtarget.get_id()]
return ret

@ -0,0 +1,42 @@
#include "meson-sample.h"
struct _MesonSample {
GObject parent_instance;
};
G_DEFINE_TYPE (MesonSample, meson_sample, G_TYPE_OBJECT)
/**
* meson_sample_new:
*
* Allocates a new #MesonSample.
*
* Returns: (transfer full): a #MesonSample.
*/
MesonSample *
meson_sample_new (void)
{
return g_object_new (MESON_TYPE_SAMPLE, NULL);
}
static void
meson_sample_class_init (MesonSampleClass *klass)
{
}
static void
meson_sample_init (MesonSample *self)
{
}
/**
* meson_sample_print_message:
* @self: a #MesonSample.
*
* Prints a message.
*/
void
meson_sample_print_message (MesonSample *self)
{
g_return_if_fail (MESON_IS_SAMPLE (self));
}

@ -0,0 +1,17 @@
#ifndef MESON_SAMPLE_H
#define MESON_SAMPLE_H
#include <glib-object.h>
G_BEGIN_DECLS
#define MESON_TYPE_SAMPLE (meson_sample_get_type())
G_DECLARE_FINAL_TYPE (MesonSample, meson_sample, MESON, SAMPLE, GObject)
MesonSample *meson_sample_new (void);
void meson_sample_print_message (MesonSample *self);
G_END_DECLS
#endif /* MESON_SAMPLE_H */

@ -0,0 +1,35 @@
project('gir link order 2', 'c')
if not dependency('gobject-2.0', required : false).found()
error('MESON_SKIP_TEST gobject not found.')
endif
gnome = import('gnome')
gobject = dependency('gobject-2.0')
# This builds a dummy libsample under samelibname that's not really used
subdir('samelibname')
# This builds the real libsample
meson_sample_sources = ['meson-sample.c', 'meson-sample.h']
meson_sample_lib = shared_library(
'sample',
sources : meson_sample_sources,
dependencies : [gobject],
link_with: [samelibname],
install : false,
)
# g-ir-scanner should get the linker paths in the right order so it links first
# against the target libsample and not the dummy one that's just a dependency
# https://github.com/mesonbuild/meson/pull/5423
gnome.generate_gir(
meson_sample_lib,
sources : meson_sample_sources,
nsversion : '1.0',
namespace : 'Meson',
symbol_prefix : 'meson',
identifier_prefix : 'Meson',
install : false,
build_by_default: true,
)

@ -0,0 +1,5 @@
samelibname = shared_library(
'sample',
sources : [],
install : false,
)
Loading…
Cancel
Save