include-flate icon indicating copy to clipboard operation
include-flate copied to clipboard

Support for compile-time environment variable lookup

Open MiSawa opened this issue 3 years ago • 2 comments

First off, thank you for the great crate!

I'm now generating some plaintext in build.rs to $OUT_DIR/foo.txt, and including it in the library code like include_str!(concat!(env!("OUT_DIR"), "/foo.txt")). It'd be great if flate! also supports either

  • flate!(concat!(env!("OUT_DIR"), "/foo.txt")), or
  • flate!("$OUT_DIR/foo.txt")

so that one can use include-flate for generated file stored in OUT_DIR (or wherever else relative to an environment variable).

MiSawa avatar Mar 26 '22 12:03 MiSawa

I don't think macro resolution is currently possible in stable Rust. The second option of shell expansion is possible, but it breaks backwards compatibility. Perhaps we can consider a separate syntax?

flate_env!(OUT_DIR, "foo.txt")

different pieces are joined, non-literal components are parsed as identifiers that interpret as environment variable names.

SOF3 avatar Mar 27 '22 02:03 SOF3

That totally makes sense to me! Probably flate!(OUT_DIR, "foo.txt") is also backward compatible, but I see benefit of separating the macro.

MiSawa avatar Mar 27 '22 04:03 MiSawa