diff options
-rw-r--r-- | docs/markdown/Rust.md | 8 | ||||
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 19 | ||||
-rw-r--r-- | test cases/rust/18 proc-macro/meson.build | 3 |
3 files changed, 20 insertions, 10 deletions
diff --git a/docs/markdown/Rust.md b/docs/markdown/Rust.md index b7e36e3..151aac0 100644 --- a/docs/markdown/Rust.md +++ b/docs/markdown/Rust.md @@ -65,3 +65,11 @@ be configured to use the file as it's not in the source root (Meson does not write files into the source directory). [See the upstream docs](https://rust-analyzer.github.io/manual.html#non-cargo-based-projects) for more information on how to configure that. + +## Linking with standard libraries + +Meson will link the Rust standard libraries (e.g. libstd) statically, unless the +target is a proc macro or dylib, or it depends on a dylib, in which case [`-C +prefer-dynamic`](https://doc.rust-lang.org/rustc/codegen-options/index.html#prefer-dynamic) +will be passed to the Rust compiler, and the standard libraries will be +dynamically linked. 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 diff --git a/test cases/rust/18 proc-macro/meson.build b/test cases/rust/18 proc-macro/meson.build index 01c4cbe..2958df1 100644 --- a/test cases/rust/18 proc-macro/meson.build +++ b/test cases/rust/18 proc-macro/meson.build @@ -13,7 +13,8 @@ pm = shared_library( main = executable( 'main', 'use.rs', - link_with : pm + link_with : pm, + rust_args : ['-C', 'panic=abort'], ) test('main_test', main) |