Bazel save preprocessed files

Viewed 41

I have a BUILD file in my cpp project, that defines what is build. I have no clue in bazel, nor there it is being run from. Currently I either copy rules or add sources to existing rules, e.g., this is the rule where I want to add an action

cc_library(
    name = "cool_app",
    srcs = ["cool_app.cpp"],
    hdrs = ["cool_app.h"],
    deps = ["//modules/common"],
)

I want to produce a pre-processor output for cool_app.h. Are there options that could be added to this rule to achieve what I want?

UPDATE: The content of cool_app.h:

#pragma once

#define ENUM_INIT_LIST \
    ADD_VALUE(First) \
    ADD_VALUE(Second) \

#define ADD_VALUE(topic) topic,
enum class Topic : int {
    Invalid = -1,
    TOPIC_INIT_LIST
    LAST_ENUM_ELEMENT,
};
#undef ADD_VALUE

#define ADD_VALUE(topic) Topic::topic,
constexpr auto kAvailableTopics =
    std::initializer_list<Topic>({TOPIC_INIT_LIST});
#undef ADD_VALUE

And I want to save a C pre-processor output, so humans can get something similar to:

#pragma once

enum class Topic : int {
    Invalid = -1,
    First,
    Second,
    LAST_ENUM_ELEMENT,
};

constexpr auto AvailableTopics =
    std::initializer_list<Topic>({
        Topic::First,
        Topic::Second,
    });
0 Answers
Related