Skip to content

Commit f4c7c26

Browse files
committed
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 rust-lang/rust#111083.
1 parent fb10adf commit f4c7c26

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

mesonbuild/backend/ninjabackend.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,10 +1955,9 @@ def generate_rust_target(self, target: build.BuildTarget) -> None:
19551955
# Rustc replaces - with _. spaces or dots are not allowed, so we replace them with underscores
19561956
args += ['--crate-name', target.name.replace('-', '_').replace(' ', '_').replace('.', '_')]
19571957
depfile = os.path.join(target.subdir, target.name + '.d')
1958-
args += ['--emit', f'dep-info={depfile}', '--emit', 'link']
1958+
args += ['--emit', f'dep-info={depfile}', '--emit', f'link={target_name}']
1959+
args += ['--out-dir', self.get_target_private_dir(target)]
19591960
args += target.get_extra_args('rust')
1960-
output = rustc.get_output_args(os.path.join(target.subdir, target.get_filename()))
1961-
args += output
19621961
linkdirs = mesonlib.OrderedSet()
19631962
external_deps = target.external_deps.copy()
19641963

mesonbuild/interpreter/interpreter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3188,6 +3188,10 @@ def build_both_libraries(self, node, args, kwargs):
31883188
# Feel free to submit patches to get this fixed if it is an
31893189
# issue for you.
31903190
reuse_object_files = False
3191+
elif shared_lib.uses_rust():
3192+
# FIXME: rustc supports generating both libraries in a single invocation,
3193+
# but for now compile twice.
3194+
reuse_object_files = False
31913195
else:
31923196
reuse_object_files = static_lib.pic
31933197

0 commit comments

Comments
 (0)