static-files
Automate static resource collection and embed assets into your Rust binary at build time.
Repository Health
Technical Analysis
static-files helps Rust projects automate the collection of static resources — HTML, CSS, JavaScript, images — and embed them directly into the compiled executable. Invoked from a build script, it walks a resource directory, generates Rust code that maps each file to its bytes and MIME type, and can optionally run npm-based build steps and detect changes to avoid unnecessary recompilation.
What You Get
- A build-script API that scans a directory and generates embedding code
- MIME-type detection for each collected resource via mime_guess
- Optional npm/yarn integration to run frontend build commands before collection
- Change-detection support to skip rebuilds when resources are unchanged
Common Use Cases
- Embedding a compiled frontend bundle into an Actix Web or Warp binary
- Running webpack or another npm build as part of cargo build
- Shipping a self-contained executable with no external asset files
Under The Hood
Architecture
The library runs from a build script: resource_dir.rs and resource.rs walk a target directory, sets.rs groups resources, and the generator emits a generate() function into OUT_DIR that returns a map of path to Resource. npm_build.rs orchestrates optional package-manager build steps, and change-detection wraps the whole pass so cargo only reruns when inputs change.
Tech Stack
Rust (edition 2021, MSRV 1.78) with mime_guess for content types, path-slash for cross-platform paths, and the optional change-detection crate. Feature flags gate change-detection and deterministic sort ordering.
Code Quality
Code is organized into small focused modules under src/mods and enforces strict clippy pedantic lints in Cargo.toml. The design keeps build-time and runtime concerns separate, and the crate is dual-licensed and actively versioned, though it relies primarily on integration through downstream projects rather than a large in-repo test suite.
API Design
The entry point is a single resource_dir(path).build() call in build.rs, plus an include! of the generated file — a minimal surface that gets projects embedding assets in a few lines. Feature flags expose sorting and change detection without complicating the common path.