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
+20 -5
View File
@@ -35,13 +35,12 @@ testcommon_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'),
join_paths(zstd_rootdir, 'programs/benchfn.c'),
join_paths(zstd_rootdir, 'programs/benchzstd.c')]
testcommon = static_library('testcommon',
testcommon_sources,
# needed due to use of private symbol + -fvisibility=hidden
link_with: libzstd_static)
# The final executable carries libzstd: static archives cannot consume a
# custom-generated archive directly on Meson 0.50.
testcommon = static_library('testcommon', testcommon_sources)
testcommon_dep = declare_dependency(link_with: testcommon,
dependencies: libzstd_deps,
dependencies: [libzstd_deps, libzstd_static_dep],
include_directories: libzstd_includes)
datagen_sources = [join_paths(zstd_rootdir, 'tests/datagencli.c'),
@@ -102,6 +101,22 @@ invalidDictionaries = executable('invalidDictionaries',
dependencies: [ libzstd_dep ],
install: false)
# A native consumer must need only libzstd.a. This exercises the flattened
# C/Rust archive rather than relying on Cargo's archive order at link time.
rustLibSmokeStatic = executable('rustLibSmokeStatic',
join_paths(zstd_rootdir, 'tests/rustLibSmoke.c'),
dependencies: [libzstd_static_dep],
install: false)
test('test-rustLibSmokeStatic', rustLibSmokeStatic)
if default_library_type != 'static'
rustLibSmokeShared = executable('rustLibSmokeShared',
join_paths(zstd_rootdir, 'tests/rustLibSmoke.c'),
dependencies: [libzstd_dep],
install: false)
test('test-rustLibSmokeShared', rustLibSmokeShared)
endif
if 0 < legacy_level and legacy_level <= 4
legacy_sources = [join_paths(zstd_rootdir, 'tests/legacy.c')]
legacy = executable('legacy',