[SOLVED] The Rust way to add BLOB to binaries?

#1

In the past i wrote a few Application with working Data that were added as BLOB into the Data Segment of the Binary. But this i made in plain C.

Example, adding a texture to executable with C:

The C-Way:

1. Creating Object from Texture

ld -r -b binary texture.png -o texture.o

2. Adding Object

gcc $(FLAGS) main.c -o app.exe $(INCLUDE_DIR) $(LIB_DIR) $(LIBS) texture.o

3. Using in Sources

Declaration:

extern unsigned char _binary_texture_png_start;
extern unsigned char _binary_texture_png_size;

Reading:

SDL_RWops *tex_mem = SDL_RWFromMem(&_binary_texture_png_start,(intptr_t)&_binary_texture_png_size);

if (tex_mem == NULL) {
   SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Load image from memory fail : %s\n",SDL_GetError());
   return false;
}

Questions:
How can i implement this in plain Rust? Currently i would add this in C as well and calling the Rust lib with this Data, but this sounds a little bit complicated. What do you mean? Maybe you can give me some advices or hints to find a pure Rust Solution?

Maybe I also missed a helpful post in the forum?

0 Likes

#2

The most direct way is https://doc.rust-lang.org/stable/std/macro.include_bytes.html

3 Likes

#3

Wow, a quick and good answer. Many thanks that was exactly what i searched :slight_smile:

0 Likes

closed #4

This topic was automatically closed after 30 hours. New replies are no longer allowed.

0 Likes