Re: [PATCH RFC 1/3] meson: add infrastructure to build internal Rust library
- From
Eli Schwartz <eschwartz@gentoo.org>
- Date
- Sep 5, 2025, 13:20 UTC
- Message-ID
- <7040d009-2a1f-4962-abcc-80b82b89f1e6@gentoo.org>
- In-Reply-To
- <aLqWKYkj98QUDxRi@pks.im>
On 9/5/25 3:50 AM, Patrick Steinhardt wrote:
Show 35 quoted lines
> On Thu, Sep 04, 2025 at 09:16:03PM -0400, Eli Schwartz wrote:
>> Hmm. Patrick -- do you mind documenting why you decided to use this
>> version guard at all? Off the top of my head I'm not sure why you'd need
>> this.
>>
>> In src/meson.build,
>>
>> +libgit_rs = static_library('git_rs',
>> + sources: [
>> + 'lib.rs',
>> + ],
>> + rust_abi: 'c',
>> +)
>>
>>
>>
>> rust_abi is new in meson 1.3.0, but it's just a rename for clarity of
>> rust_crate_type, available since meson 0.42.0, so please use the
>> backwards-compatible name...
>
> Oh. I think I misunderstood the following sentence [1]:
>
> (Since 1.9.0) Rust supports mixed targets, but only supports using
> rustc as the linker for such targets. If you need to use a non-Rust
> linker, or support Meson < 1.9.0, see below.
>
> I thought that only with Meson 1.9 you could link Rust libraries with C
> libraries. But I guess this rather means that you can now have a single
> target that has both '.c' and '.rs' sources?
>
> In any way, thanks for the hint, will drop.
>
> Patrick
>
> [1]: https://mesonbuild.com/Rust.html#mixing-rust-and-nonrust-sourcesYes -- a single target is something like a libXXXX.so or a libXXXX.a file, and there are significant nuances in how a build system backend needs to run rustc in order to emit the final C interface (or merge into an executable). Once it is exported to C, though, it is "normal" C code and anything may link to it freely, even for much older versions of Meson.
The previous (<1.9.0) gold standard for Rust / C interop in Meson, was the far more well-trodden path of "use libraries, not *.o files" (which is also more straightforward in cargo, of course ;)).
-- Eli Schwartz