user19185854
user19185854

Reputation: 9

How to wrap a rule in Bazel?

I use bazel configure_make rule to build 3rd party lib. This lib requires specifying paths to compiler in its configure options (or it uses default compiler, like /usr/bin/gcc, that is definitely wrong for cross-compilation). I want to make my BUILD file free of configurable paths to toolchain, and I see, that I can get a toolchain from ctx in rule implementation. Idea is to get compiler/linker/etc paths from ctx and add them to configure options of configure_make rule, so the BUILD file will not have any info about toolchain. I made a POC - copied original configure_make rule and changed its implementation - it works as I want. But I don't want to keep a copy of configure_make, if there is a way to write some wrapper for this rule. Generally, what I want:

def _new_impl(ctx):
    find_cpp_toolchain(ctx)
    attrs = ctx.attr
    # add new configure options somehow
    # pass them to configure_make ???

new_rule = rule (
    # all configure_make attrs
    impl = _new_impl,
    ...
)

For now, after reading bazel docs it seems impossible, but I know, that I'm not an expert in bazel, so I could miss something.

Upvotes: 0

Views: 726

Answers (1)

user19185854
user19185854

Reputation: 9

It is impossible in current version.

Upvotes: 0

Related Questions