libwebp-sys

Low-level bindgen FFI bindings to Google's libwebp for encoding and decoding WebP images in Rust.

Library
Cargo
v0.14.4
48stars
MIT License

Repository Health

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

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
67/100Good
Architecture76
Code Quality74
Innovation62
Learning Curve55

libwebp-sys is a Rust -sys crate exposing raw FFI bindings to libwebp, Google’s WebP image codec library. The bindings are generated with bindgen and cover the encode, decode, mux, and demux APIs so Rust programs can produce and consume WebP images directly against the native C library.

The crate vendors the libwebp C source and builds it with the cc crate (no cmake required), statically linking it into your binary. It supports no_std builds and exposes SIMD feature flags (Neon, SSE 4.1, AVX2) for tuning the compiled codec.

What You Get

  • Complete bindgen-generated FFI declarations for the WebP encode, decode, mux, and demux APIs
  • A build script that compiles the vendored libwebp C source via the cc crate, with no cmake dependency
  • no_std support for embedding in constrained or non-standard-library targets
  • SIMD feature flags (neon, sse41, avx2) plus optional parallel encoding to tune codec performance
  • Static linking of libwebp into your binary for self-contained, dependency-free deployment

Common Use Cases

  • Encoding raw RGBA or YUV pixel buffers into WebP bytes from Rust
  • Decoding WebP images into raw pixel data for further processing
  • Serving as the native backend for a safe, higher-level Rust WebP wrapper crate
  • Reading and writing animated or muxed WebP containers via the mux and demux bindings

Under The Hood

Architecture - The crate is intentionally thin: src/ffi.rs holds the bindgen-generated declarations for every allowlisted WebP symbol, and src/lib.rs re-exports them plus a handful of small helper wrappers (for example WebPMuxNew and the ABI-versioned init functions) that supply the correct internal ABI version constants. The heavy lifting is in build.rs, which globs the vendored C sources under vendor/ and compiles them with the cc crate, honoring the SIMD and parallel feature flags.

Tech Stack - Rust edition 2024 targeting an FFI boundary to C. Build dependencies are cc (to compile libwebp), glob (to enumerate sources), pkg-config, and an optional bindgen for regenerating the bindings. The vendored libwebp C source and sharpyuv are bundled in-tree so no system library is required.

Code Quality - As a -sys crate the surface is machine-generated and deliberately unsafe, with lint allowances (non_snake_case, missing_safety_doc) appropriate to raw bindings. The repo carries integration tests exercising real .webp fixtures (including animation) to verify the bindings link and round-trip correctly against the compiled library.

API Design - The public API mirrors the C library one-to-one, so it is unsafe and pointer-based by design rather than ergonomic; callers are expected to wrap it. The README documents encode and decode examples and the feature/RUSTFLAGS knobs for SIMD, which lowers the barrier for the intended audience of wrapper authors.

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