Rust: C static library cannot link_whole Rust static library

pull/11742/head
Xavier Claessens 2 years ago
parent a78af23686
commit 2dadc3ae5b
  1. 23
      mesonbuild/build.py
  2. 13
      test cases/rust/5 polyglot static/meson.build
  3. 3
      test cases/rust/5 polyglot static/test.json

@ -1407,17 +1407,9 @@ You probably should put it in link_with instead.''')
mlog.warning(f'Try to link an installed static library target {self.name} with a'
'custom target that is not installed, this might cause problems'
'when you try to use this static library')
elif t.is_internal() and not t.uses_rust():
elif t.is_internal():
# When we're a static library and we link_with to an
# internal/convenience library, promote to link_whole.
#
# There are cases we cannot do this, however. In Rust, for
# example, this can't be done with Rust ABI libraries, though
# it could be done with C ABI libraries, though there are
# several meson issues that need to be fixed:
# https://github.com/mesonbuild/meson/issues/10722
# https://github.com/mesonbuild/meson/issues/10723
# https://github.com/mesonbuild/meson/issues/10724
return self.link_whole(t)
if not isinstance(t, (Target, CustomTargetIndex)):
raise InvalidArguments(f'{t!r} is not a target.')
@ -1442,9 +1434,6 @@ You probably should put it in link_with instead.''')
raise InvalidArguments(f'Custom target {t!r} is not linkable.')
if t.links_dynamically():
raise InvalidArguments('Can only link_whole custom targets that are static archives.')
if isinstance(self, StaticLibrary):
# FIXME: We could extract the .a archive to get object files
raise InvalidArguments('Cannot link_whole a custom target into a static library')
elif not isinstance(t, StaticLibrary):
raise InvalidArguments(f'{t!r} is not a static library.')
elif isinstance(self, SharedLibrary) and not t.pic:
@ -1458,6 +1447,16 @@ You probably should put it in link_with instead.''')
else:
mlog.warning(msg + ' This will fail in cross build.')
if isinstance(self, StaticLibrary):
if isinstance(t, (CustomTarget, CustomTargetIndex)) or t.uses_rust():
# There are cases we cannot do this, however. In Rust, for
# example, this can't be done with Rust ABI libraries, though
# it could be done with C ABI libraries, though there are
# several meson issues that need to be fixed:
# https://github.com/mesonbuild/meson/issues/10722
# https://github.com/mesonbuild/meson/issues/10723
# https://github.com/mesonbuild/meson/issues/10724
# FIXME: We could extract the .a archive to get object files
raise InvalidArguments('Cannot link_whole a custom or Rust target into a static library')
# When we're a static library and we link_whole: to another static
# library, we need to add that target's objects to ourselves.
self.objects += [t.extract_all_objects()]

@ -9,7 +9,18 @@ deps = [
extra_winlibs = meson.get_compiler('c').get_id() in ['msvc', 'clang-cl'] ? ['userenv.lib', 'ws2_32.lib', 'bcrypt.lib'] : []
r = static_library('stuff', 'stuff.rs', rust_crate_type : 'staticlib')
l = static_library('clib', 'clib.c', link_with : r, install : true)
# clib is installed static library and stuff is not installed. That means that
# to be usable clib must link_whole stuff. Meson automatically promote to link_whole,
# as it would do with C libraries, but then cannot extract objects from stuff and
# thus should error out.
# FIXME: We should support this use-case in the future.
testcase expect_error('Cannot link_whole a custom or Rust target into a static library')
l = static_library('clib', 'clib.c', link_with : r, install : true)
endtestcase
l = static_library('clib', 'clib.c', link_with : r)
e = executable('prog', 'prog.c',
dependencies: deps,
link_with : l,

@ -1,7 +1,6 @@
{
"installed": [
{"type": "exe", "file": "usr/bin/prog"},
{"type": "pdb", "file": "usr/bin/prog"},
{"type": "file", "file": "usr/lib/libclib.a"}
{"type": "pdb", "file": "usr/bin/prog"}
]
}

Loading…
Cancel
Save