Build feature-matched Rust archives for the native Make library path. Flatten their members into libzstd.a so static consumers resolve C-to-Rust and Rust-to-C references in one archive, and whole-archive link shared outputs so every migrated public ABI export remains available. Rust compression and decompression features now mirror the C partial-library switches. This prevents compression-only artifacts from retaining DDict references to decompression-only C helpers. Add a C archive smoke test that round-trips data and exercises the DDict lifecycle through lib/libzstd.a, rather than direct test-object links. Test Plan: - cargo fmt, strict Clippy, cargo test --all-targets, release build - Rust checks with compression-only, decompression-only, and no features - full, partial, forced-HUF, and 32-bit static/shared Make library probes - test-rust-lib-smoke, fuzzer, zstreamtest, and invalidDictionaries Refs: rust/README.md
67 lines
1.9 KiB
C
67 lines
1.9 KiB
C
/*
|
|
* Link and run through the installed-style static archive, rather than the
|
|
* direct C-object-plus-Rust-archive test path used by the other test tools.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "zstd.h"
|
|
|
|
static int checkError(size_t result, const char* operation)
|
|
{
|
|
if (!ZSTD_isError(result)) return 0;
|
|
fprintf(stderr, "%s: %s\n", operation, ZSTD_getErrorName(result));
|
|
return 1;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
enum { sourceSize = 64 * 1024 };
|
|
unsigned char source[sourceSize];
|
|
size_t const compressedCapacity = ZSTD_compressBound(sourceSize);
|
|
void* compressed = malloc(compressedCapacity);
|
|
void* restored = malloc(sourceSize);
|
|
size_t compressedSize;
|
|
size_t restoredSize;
|
|
ZSTD_DDict* ddict;
|
|
size_t index;
|
|
|
|
if (compressed == NULL || restored == NULL) {
|
|
fputs("allocation failed\n", stderr);
|
|
free(restored);
|
|
free(compressed);
|
|
return 1;
|
|
}
|
|
|
|
for (index = 0; index < sourceSize; ++index) {
|
|
source[index] = (unsigned char)((index * 13 + index / 97) & 0x1F);
|
|
}
|
|
compressedSize = ZSTD_compress(compressed, compressedCapacity,
|
|
source, sourceSize, 3);
|
|
if (checkError(compressedSize, "ZSTD_compress")) goto cleanup;
|
|
|
|
restoredSize = ZSTD_decompress(restored, sourceSize, compressed, compressedSize);
|
|
if (checkError(restoredSize, "ZSTD_decompress")) goto cleanup;
|
|
if (restoredSize != sourceSize || memcmp(source, restored, sourceSize) != 0) {
|
|
fputs("round trip mismatch\n", stderr);
|
|
goto cleanup;
|
|
}
|
|
|
|
/* This must pull the Rust DDict object and resolve its C helper cycle. */
|
|
ddict = ZSTD_createDDict(NULL, 0);
|
|
if (ddict == NULL || ZSTD_freeDDict(ddict) != 0) {
|
|
fputs("DDict lifecycle failed\n", stderr);
|
|
goto cleanup;
|
|
}
|
|
|
|
free(restored);
|
|
free(compressed);
|
|
return 0;
|
|
|
|
cleanup:
|
|
free(restored);
|
|
free(compressed);
|
|
return 1;
|
|
}
|