aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2023-06-20 08:18:33 +0000
committerXavier Claessens <xclaesse@gmail.com>2023-06-21 18:05:16 -0400
commitab17bd2393b6973250a8e98f4fd06cde5045dca7 (patch)
tree96192e99edc9df781f8f947cf251e1c082ea5489 /mesonbuild
parent548dd25c67f331741d2185875f1df7a519d86a37 (diff)
downloadmeson-ab17bd2393b6973250a8e98f4fd06cde5045dca7.zip
meson-ab17bd2393b6973250a8e98f4fd06cde5045dca7.tar.gz
meson-ab17bd2393b6973250a8e98f4fd06cde5045dca7.tar.bz2
rust: fix -C prefer-dynamic behavior
I noticed when building a project that uses a proc macro that Meson passed -C prefer-dynamic for the executable, and not the proc macro, while cargo passed -C prefer-dynamic for the proc macro, but not for the executable. Meson's behavior broke setting -C panic=abort on the executable. As far as we can tell, because we explicitly pass each library path to rustc, the only thing -C prefer-dynamic affects in Meson is how the standard libraries are linked. Generally, one does not want the standard libraries to be dynamically linked, because if the Rust compiler is ever updated, anything linked against the old standard libraries will likely break, due to the lack of a stable Rust ABI. Therefore, I've reorganised Meson's behavior around the principle that the standard libraries should only be dynamically linked when Rust dynamic linking has already been opted into in some other way. The details of how this manifests are now explained in the documentation.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/backend/ninjabackend.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 348d0c9..c60143b 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -2043,16 +2043,17 @@ class NinjaBackend(backends.Backend):
args += ['-L', d]
target_deps = target.get_dependencies()
has_shared_deps = any(isinstance(dep, build.SharedLibrary) for dep in target_deps)
- if isinstance(target, build.SharedLibrary) or has_shared_deps:
- has_rust_shared_deps = any(isinstance(dep, build.SharedLibrary) and dep.uses_rust()
- and dep.rust_crate_type not in {'cdylib', 'proc-macro'}
- for dep in target_deps)
- if cratetype not in {'cdylib', 'proc-macro'} or has_rust_shared_deps:
- # add prefer-dynamic if any of the Rust libraries we link
- # against are dynamic or this is a dynamic library itself,
- # otherwise we'll end up with multiple implementations of crates
- args += ['-C', 'prefer-dynamic']
+ has_rust_shared_deps = any(dep.uses_rust()
+ and dep.rust_crate_type == 'dylib'
+ for dep in target_deps)
+
+ if cratetype in {'dylib', 'proc-macro'} or has_rust_shared_deps:
+ # add prefer-dynamic if any of the Rust libraries we link
+ # against are dynamic or this is a dynamic library itself,
+ # otherwise we'll end up with multiple implementations of libstd.
+ args += ['-C', 'prefer-dynamic']
+ if isinstance(target, build.SharedLibrary) or has_shared_deps:
# build the usual rpath arguments as well...
# Set runtime-paths so we can run executables without needing to set