diff --git a/docs/markdown/Wrap-dependency-system-manual.md b/docs/markdown/Wrap-dependency-system-manual.md index 077535a8db4d..15640ccd247f 100644 --- a/docs/markdown/Wrap-dependency-system-manual.md +++ b/docs/markdown/Wrap-dependency-system-manual.md @@ -373,6 +373,10 @@ recommended to regroup all Cargo dependencies inside a single workspace invoked from the main Meson project. When invoking multiple different Cargo subprojects from Meson, feature resolution of common dependencies might be wrong. +Since *1.10.0* When a C ABI library is produced (`crate_type` contains `staticlib` +and/or `cdylib`), Meson will follow the `default_library` option to decide +whether a shared and/or static library should be built. + ## Using wrapped projects Wraps provide a convenient way of obtaining a project into your diff --git a/docs/markdown/snippets/cargo_default_library.md b/docs/markdown/snippets/cargo_default_library.md new file mode 100644 index 000000000000..e9615bf117aa --- /dev/null +++ b/docs/markdown/snippets/cargo_default_library.md @@ -0,0 +1,5 @@ +## Cargo C ABI libraries follows `default_library` option + +When a C ABI library is produced (`crate_type` contains `staticlib` +and/or `cdylib`), Meson will follow the `default_library` option to decide +whether a shared and/or static library should be built. diff --git a/mesonbuild/cargo/interpreter.py b/mesonbuild/cargo/interpreter.py index 297ff5e8745f..b29f8df8e88e 100644 --- a/mesonbuild/cargo/interpreter.py +++ b/mesonbuild/cargo/interpreter.py @@ -754,11 +754,16 @@ def _create_lib(self, pkg: PackageState, build: builder.Builder, subdir: str, if lib_type == 'proc-macro': lib = build.method('proc_macro', build.identifier('rust'), posargs, kwargs) else: - if static and shared: + if lib_type == 'c': + # Let Meson's default_library option decide for C ABI, regardless + # whether Cargo.toml requests static and/or shared. + target_type = 'library' + elif static and shared: target_type = 'both_libraries' + elif shared: + target_type = 'shared_library' else: - target_type = 'shared_library' if shared else 'static_library' - + target_type = 'static_library' kwargs['rust_abi'] = build.string(lib_type) lib = build.function(target_type, posargs, kwargs)