Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/markdown/Wrap-dependency-system-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions docs/markdown/snippets/cargo_default_library.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 8 additions & 3 deletions mesonbuild/cargo/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading