lzma-sys

Raw Rust FFI bindings to liblzma for LZMA and xz stream encoding and decoding.

Library
Cargo
v0.1.20
93stars
MIT/Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
31/100Needs Attention
Development Activity0
Maintenance0
Community52
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
66/100Good
Architecture70
Code Quality72
Innovation60
Learning Curve55

lzma-sys is a -sys crate that exposes raw, unsafe Rust FFI bindings to liblzma, the C library that implements LZMA and xz stream compression and decompression. It maps liblzma’s functions and types directly into Rust, and its build script can compile a bundled copy of xz or link against a system liblzma.

Because it is the low-level foundation, most applications use the safe, idiomatic wrapper crate xz2 instead of calling lzma-sys directly. But as a -sys crate it underpins a large slice of the Rust compression ecosystem — with tens of millions of downloads — providing the reliable liblzma linkage that higher-level xz/LZMA crates build on.

What You Get

  • Raw FFI declarations for liblzma’s encoding and decoding functions and types
  • A build script that compiles bundled xz sources or links system liblzma
  • pkg-config and cc based configuration for cross-platform linkage
  • A stable links = "lzma" base that other Rust crates can depend on
  • The foundation for the higher-level, safe xz2 crate

Common Use Cases

  • Serving as the liblzma linkage layer beneath the safe xz2 crate
  • Providing raw liblzma access to crates that need custom xz/LZMA handling
  • Building portable Rust binaries that bundle xz rather than rely on a system library
  • Interfacing existing C liblzma workflows with Rust code via FFI

Under The Hood

Architecture - The crate is intentionally thin. src/lib.rs contains the extern "C" declarations mirroring liblzma’s public headers (stream encoder/decoder init, code, and end functions plus the relevant structs and enums), and build.rs decides at build time whether to compile the vendored xz-5.2 C sources with the cc crate or link a system liblzma discovered via pkg-config. A config.h and the bundled xz tree support the from-source build path.

Tech Stack - Rust FFI over the C liblzma library. Runtime dependency is just libc; build dependencies are cc (to compile bundled sources) and pkg-config (to locate a system library). The crate uses links = "lzma" so Cargo enforces a single liblzma link across the dependency graph.

Code Quality - As a -sys crate the surface is small and stable; correctness is validated in the parent xz2-rs repo via a systest crate that checks the bindings against the real C headers, plus the xz2 integration tests. Activity is low because the liblzma ABI it wraps is itself stable and mature.

API Design - The API is deliberately unsafe and low-level, matching liblzma one-to-one, so it is not meant to be pleasant to call directly — that is the job of the safe xz2 wrapper. For its intended audience (crate authors building higher-level bindings), the direct correspondence with the C API is exactly the right, predictable interface.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search