This take a files from the build environment a puts it directly into the data section of a binary, making them accessible as a library.
This allows large test or binary artifacts to come from files (or other build artifacts) rather than deal with escaping them into string literals.
bazel_dep(
name = "com_github_bcsgh_cc_embed_data",
version = ...,
)
load("//cc_embed_data:cc_embed_data.bzl", "cc_embed_data")
cc_embed_data(
name = "cc_embed_example",
srcs = [
"foo.bin",
#...
],
namespace = "my_namespace",
)
cc_test(
name = "cc_embed_example_usage",
srcs = ["cc_embed_example_usage.cc"],
data = SRCS,
deps = [
":cc_embed_example",
"@com_google_googletest//:gtest_main",
],
)
#include <string_view>
#include "cc_embed_example_data.h"
void Use(std::string_view);
void Use(std::string_view, std::string_view);
int main() {
// find one
Use(my_namespace::src_foo_bin());
// find all
for (const auto& i : my_namespace::EmbedIndex()) {
Use(i.first, i.second);
}
return 0;
}
load("@com_github_bcsgh_cc_embed_data//cc_embed_data:cc_embed_data.bzl", "cc_embed_data")
cc_embed_data(name, deps, srcs, a, cc, h, json, namespace)
Generate a library containing the contents of srcs.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | A map from build rules to embed to a path (e.g. "files") on the Target object that yeilds a depset of files. (Figuring out what this path should be more or less requiers mucking around with rule implementations. Sorry.) | Dictionary: Label -> String | optional | {} |
| srcs | The files to embed. | List of labels | optional | [] |
| a | The generated cc_library archive. (This must be set for other rules to depend on individual output files.) | Label | optional | None |
| cc | The generated C++ source file. (This must be set for other rules to depend on individual output files.) | Label | optional | None |
| h | The generated C++ header file. (This must be set for other rules to depend on individual output files.) | Label | optional | None |
| json | - | Label | optional | None |
| namespace | If given, the C++ namespace to generate in. | String | optional | "" |
To configure the git hooks, run ./.git_hooks/setup.sh