Skip to content

Conversation

@bonzini
Copy link
Collaborator

@bonzini bonzini commented Oct 13, 2025

As a first step towards full support for cross compilation of Cargo subprojects, allow building the same crate for both the host and the build machine.

Right now the crate name must match the file name, but that means that the same file name is used for host and build rlibs. To allow that, drop anything after a + sign from the crate name. This convention is already in use, for example Fedora uses it to denote the features that packages support (e.g. rust-$crate+$feature-devel), so it makes sense for Meson to use it instead of reinventing something else.

Other than for cross compilation, this is also useful in some cases where the same crate can be compiled with multiple configurations. Using the "+SUFFIX" syntax avoids having to use a dependency map.

Extracted from #14952.

@bonzini bonzini requested a review from jpakkane as a code owner October 13, 2025 08:02
@bonzini bonzini added this to the 1.10 milestone Oct 13, 2025
_get_rust_dependency_name was less lenient in accepting targets containing
invalid characters for a crate name.  This made it impossible to link to
those targets without using a dependency map.  Use the same algorithm to
do the conversion.

Signed-off-by: Paolo Bonzini <[email protected]>
Allow multiple targets for the same crate name, which is useful when the
same crate is used for both the host and the build machine.

Signed-off-by: Paolo Bonzini <[email protected]>
@xclaesse
Copy link
Member

I don't think this is specific to Rust, the same issue happens for libfoo.so compiled for both machines. I'm thinking for example about cross compiling glib where tools (e.g. glib-compile-resources), and thus libs, should be built for both machines.

I know @dcbaker had a much bigger fix to allow building whole subprojects for both machines.

@xclaesse
Copy link
Member

I always wanted to be able to do e.g.

host_lib = library('foo', native: 'both')
native_lib = lib.native()

Which is not too different from both_libraries().

@bonzini
Copy link
Collaborator Author

bonzini commented Oct 17, 2025

This is true, but then this patch is useful anyway because you need to give different file names to the two build outputs, and map the two file names to the same crate name.

@bonzini bonzini mentioned this pull request Oct 27, 2025
@xclaesse
Copy link
Member

Ok, facing the same kind of issue myself, I better understand the logic of this PR. LGTM.

@xclaesse xclaesse merged commit f08a8f9 into mesonbuild:master Oct 27, 2025
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants