#binary #binary-file #compile-time #byte #file #include #build-time

build include-blob

Include large binary files in an application without incurring the compile time cost

6 releases (1 stable)

1.0.0 Apr 19, 2024
0.1.5 Apr 18, 2024
0.1.4 Nov 7, 2023
0.1.3 Jun 4, 2023
0.1.1 Jan 24, 2023

#347 in Build Utils

Download history 31/week @ 2024-07-27 13/week @ 2024-09-21

338 downloads per month

0BSD license

10KB
154 lines

include-blob

include-blob is a small crate that provides a replacement for include_bytes! that does not have the same severe impact on compile times when used with large files (several MB).

It works by pre-processing the files to be included in a build script, bundling them into static libraries, and telling Cargo to link against them.


lib.rs:

Include large files without the high compile time cost.

This crate provides the include_blob! macro as an alternative to the standard include_bytes! macro, which embeds a file by copying it to an object file and linking to it. This can reduce the (quite high) compile time cost of include_bytes!.

In order for this to work, the user code has to first add a build script that calls the make_includable function.

// build.rs
fn main() {
    include_blob::make_includable("../../directory-with-big-files");
}
let bytes: &[u8] = include_blob::include_blob!("test-project/blobs/file.txt");

Dependencies

~1.5–2.4MB
~49K SLoC