Compression at compiletime

Hi,

is there an include_str! like macro that does compression at compile-time and decompression at execution-time?

1 Like

I don't think there's such a thing. Maybe you could compress the file yourself and use include_bytes!, and decompress that at runtime?

Currently, you'd probably have to do this using a build.rs script.

1 Like

Sounds like a great idea though! Maybe someone could create it?

As you can depend on any crate to be used in build.rs Page Moved this would be quite easy to achieve. You could then use Redirection to include a bunch of bytes with the result and then decompress at run-time.

There are a bunch of crates for compression on https://crates.io/search?q=compression so you should be able to pick the one that fits your needs best.

1 Like

I have published a crate that allows this: GitHub - SOF3/include-flate: A variant of include_bytes!/include_str! with compile-time deflation and runtime lazy inflation (I have not added documentation yet, will do later; but the crate is already tested)

The crate encodes the data with the deflate algorithm, includes the deflated bytes, and uses lazy_static to lazily inflate the bytes at runtime.

7 Likes