bazelbuild / rules_cc

C++ Rules for Bazel
https://bazel.build
Apache License 2.0
187 stars 93 forks source link

FR: capability to embed binary data in CC object file. #116

Open aiuto opened 5 years ago

aiuto commented 5 years ago

It is often extremely useful to embed a generated (or static) binary object directly in a C++ library. For example, the ICU library build compiles text files describing character attributes into compressed binary structures that can be evaluated at run time. The canonical technique is to

Typically, the object file defines at least 2 symbols unit8_t _DATA_OBJECT_NAME_start[] unit32_t _DATA_OBJECT_NAME_size Those are declared in a generated .h file and provided by the object module.

Problem scope

There is an interesting overview of issues and techniques here: https://www.devever.net/~hl/incbin

bkotsopoulossc commented 3 years ago

Any suggestions on this?

bcsgh commented 3 years ago

A partial solution (hits about half the bullets under "Scope"): https://github.com/bcsgh/bazel_rules/tree/master/cc_embed_data

I've only tested that on the limited environments I've needed it in (Linux/ELF) so YMMV. If anyone wants to add Win/COFF I'd accept pull requests.

aiuto commented 3 years ago

Related: https://github.com/bazelbuild/rules_cc/issues/41.