Skip to content

Commit 4fe6eb2

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 bde690b commit 4fe6eb2

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
@@ -1964,10 +1964,9 @@ def generate_rust_target(self, target: build.BuildTarget) -> None:
19641964
# Rustc replaces - with _. spaces or dots are not allowed, so we replace them with underscores
19651965
args += ['--crate-name', target.name.replace('-', '_').replace(' ', '_').replace('.', '_')]
19661966
depfile = os.path.join(target.subdir, target.name + '.d')
1967-
args += ['--emit', f'dep-info={depfile}', '--emit', 'link']
1967+
args += ['--emit', f'dep-info={depfile}', '--emit', f'link={target_name}']
1968+
args += ['--out-dir', self.get_target_private_dir(target)]
19681969
args += target.get_extra_args('rust')
1969-
output = rustc.get_output_args(os.path.join(target.subdir, target.get_filename()))
1970-
args += output
19711970
linkdirs = mesonlib.OrderedSet()
19721971
external_deps = target.external_deps.copy()
19731972

mesonbuild/interpreter/interpreter.py

+4
Original file line numberDiff line numberDiff line change
@@ -3181,6 +3181,10 @@ def build_both_libraries(self, node, args, kwargs):
31813181
# Feel free to submit patches to get this fixed if it is an
31823182
# issue for you.
31833183
reuse_object_files = False
3184+
elif shared_lib.uses_rust():
3185+
# FIXME: rustc supports generating both libraries in a single invocation,
3186+
# but for now compile twice.
3187+
reuse_object_files = False
31843188
else:
31853189
reuse_object_files = static_lib.pic
31863190

0 commit comments

Comments
 (0)