Skip to content

Commit 172f327

Browse files
xclaesserobtaylor
authored andcommitted
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 ab9fe38 commit 172f327

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

mesonbuild/backend/ninjabackend.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1951,10 +1951,9 @@ def generate_rust_target(self, target: build.BuildTarget) -> None:
19511951
# Rustc replaces - with _. spaces or dots are not allowed, so we replace them with underscores
19521952
args += ['--crate-name', target.name.replace('-', '_').replace(' ', '_').replace('.', '_')]
19531953
depfile = os.path.join(target.subdir, target.name + '.d')
1954-
args += ['--emit', f'dep-info={depfile}', '--emit', 'link']
1954+
args += ['--emit', f'dep-info={depfile}', '--emit', f'link={target_name}']
1955+
args += ['--out-dir', self.get_target_private_dir(target)]
19551956
args += target.get_extra_args('rust')
1956-
output = rustc.get_output_args(os.path.join(target.subdir, target.get_filename()))
1957-
args += output
19581957
linkdirs = mesonlib.OrderedSet()
19591958
external_deps = target.external_deps.copy()
19601959

mesonbuild/interpreter/interpreter.py

+4
Original file line numberDiff line numberDiff line change
@@ -3206,6 +3206,10 @@ def build_both_libraries(self, node, args, kwargs):
32063206
# Feel free to submit patches to get this fixed if it is an
32073207
# issue for you.
32083208
reuse_object_files = False
3209+
elif shared_lib.uses_rust():
3210+
# FIXME: rustc supports generating both libraries in a single invocation,
3211+
# but for now compile twice.
3212+
reuse_object_files = False
32093213
else:
32103214
reuse_object_files = static_lib.pic
32113215

0 commit comments

Comments
 (0)