Check for file existence when static linking

I'm trying to use a linker script to include a binary as a static variable in my code. At the moment, I am calling include_bytes on "binary.xz".

I want to change my compression algorithm and start calling include_bytes on "binary.gz", but only in specific scenarios. In my mind, the way I want to do this is by checking if "binary.gz" exists, and if yes, including it, otherwise using "binary.xz".

How do I go about this?

The simplest way is probably to check this in build.rs and emit the file with either include_bytes!("binary.gz") or include_bytes!("binary.xz"), which will be then include!d into the actual code.

1 Like

Oh I was having some complications in my build.rs , so I was trying to do the check in my Makefile. But for whatever reason, wildcard is not returning the output that is expected.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.