Rust: Fix both_libraries() case

Rustc does not produce object files we can reuse to build both
libraries. Ideally this should be done with a single target that has
both `--crate-type` arguments instead of having 2 different build rules.

As temporary workaround, build twice and ensure they don't get conflicts
in intermediary files created by rustc by passing target's private
directory as --out-dir.

See https://github.com/rust-lang/rust/issues/111083.
pull/12276/head
Xavier Claessens 2 years ago committed by Xavier Claessens
parent 7321f01678
commit dbf081c9ce
  1. 5
      mesonbuild/backend/ninjabackend.py
  2. 4
      mesonbuild/interpreter/interpreter.py

@ -1951,10 +1951,9 @@ class NinjaBackend(backends.Backend):
# Rustc replaces - with _. spaces or dots are not allowed, so we replace them with underscores
args += ['--crate-name', target.name.replace('-', '_').replace(' ', '_').replace('.', '_')]
depfile = os.path.join(target.subdir, target.name + '.d')
args += ['--emit', f'dep-info={depfile}', '--emit', 'link']
args += ['--emit', f'dep-info={depfile}', '--emit', f'link={target_name}']
args += ['--out-dir', self.get_target_private_dir(target)]
args += target.get_extra_args('rust')
output = rustc.get_output_args(os.path.join(target.subdir, target.get_filename()))
args += output
linkdirs = mesonlib.OrderedSet()
external_deps = target.external_deps.copy()

@ -3206,6 +3206,10 @@ class Interpreter(InterpreterBase, HoldableObject):
# Feel free to submit patches to get this fixed if it is an
# issue for you.
reuse_object_files = False
elif shared_lib.uses_rust():
# FIXME: rustc supports generating both libraries in a single invocation,
# but for now compile twice.
reuse_object_files = False
else:
reuse_object_files = static_lib.pic

Loading…
Cancel
Save