build(meson): link migrated Rust code into native libraries

Build a configuration-matched Cargo archive from Meson and flatten its object
members into static libzstd.  This gives C consumers one archive even though
the migrated Rust objects and remaining C code refer to each other.

Shared libraries whole-archive the Cargo output to retain Rust-only ABI
exports.  The implementation supports Meson 0.50's generated-archive linking
rules, matching HUF mode and 32-bit configuration, and documents cross-build
target and archiver selection.

Test Plan:
- fresh Meson both-build smoke consumers and invalidDictionaries
- modern static/shared/both, forced-HUF, i686, install, and fuzzer paths
- real Meson 0.50 static and shared smoke builds
- cargo clippy, cargo clippy --benches, cargo clippy --tests, and nightly fmt

Refs: build/meson/README.md archive and cross-build documentation
This commit is contained in:
2026-07-10 22:08:55 +02:00
parent 6a762660b7
commit 3d679116d8
6 changed files with 405 additions and 36 deletions
+17
View File
@@ -12,6 +12,12 @@ by Dima Krasner \<dima@dimakrasner.com\>.
It outputs one `libzstd`, either shared or static, depending on
`default_library` option.
The migrated compatibility modules are built with Cargo as part of every
Meson library build. Static builds flatten the Cargo object members into
`libzstd.a`, so external C consumers link one archive. Shared builds use a
whole-archive link for the Cargo archive, retaining Rust-only public ABI
exports.
## How to build
`cd` to this meson directory (`build/meson`)
@@ -36,3 +42,14 @@ meson configure
```
See [man meson(1)](https://manpages.debian.org/testing/meson/meson.1.en.html).
For a cross build, set the Cargo target explicitly, for example:
```sh
meson setup -Dzstd_rust_target=aarch64-unknown-linux-gnu builddir
```
On 32-bit Linux, the `i686-unknown-linux-gnu` target is selected
automatically. Set `-Dzstd_rust_archiver=...` when the C cross toolchain needs
a non-default archiver. The `huf_force_decompress_x1` and
`huf_force_decompress_x2` options select matching C and Rust decoder modes.