Skip to content

Conversation

@xclaesse
Copy link
Member

@xclaesse xclaesse commented Nov 3, 2025

Fixes: #15183

Copy link
Collaborator

@bonzini bonzini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really prefer to have it replace both_libraries only, especially since the whole handling of both_libraries is new in 1.10.0.

But also, I think we should be looking forward at when the same Cargo.toml parsing will be applied to the toplevel project, and then "staticlib that is merged into a C build product" is an important case where the library should remain static-only.

I think there are two problems with how this PR implements it:

  1. When both libraries make sense, Cargo.toml should already have ['staticlib', 'cdylib']

  2. If there are some cases where one library does not make sense, meson should not be changing from one to the other.

@xclaesse
Copy link
Member Author

xclaesse commented Nov 3, 2025

I think we should be looking forward at when the same Cargo.toml parsing will be applied to the toplevel project, and then "staticlib that is merged into a C build product" is an important case where the library should remain static-only.

That is a fair point. But that would fail as well if crate-type = ["cdylib", "staticlib"] and we decide to only build shared library because default_library=shared.

My main motivation was for GStreamer plugins that are defined with crate-type = ["cdylib", "rlib"]. It does not make much sense to build staticlib using Cargo, but if we build them with Meson we'll have the use-case to static link plugins into what we call "gstreamer-full".

Maybe what we need is a metadata flag in Cargo.toml to enable this? Something like:

[package.metadata.meson]
default-library = true

@bonzini
Copy link
Collaborator

bonzini commented Nov 3, 2025

But that would fail as well if crate-type = ["cdylib", "staticlib"] and we decide to only build shared library because default_library=shared.

Static only C ABI is a very important case for both Cargo and Meson; and Meson decided that both-libraries-but-customizable is important enough to have its own option and function. These common scenarios and usecases should be taken into account when designing the interface, even if the interface will always be somewhat imperfect.

So maybe cdylib could be changed to library (but I am not sure), certainly not staticlib. The safest thing is to require both of them.

It does not make much sense to build staticlib using Cargo

Interesting, what makes Cargo and Meson different?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cargo: Respect Meson's default_library instead of Cargo.toml's crate_type

2 participants