Nested Rules with Bazel

44 views Asked by At

I just started working with Bazel a week ago. I'm trying to declare multiple rules within the same .bzl file. The top rule calls the other ones. I get an error saying " A rule can only be instantiated in a BUILD file, or a macro invoked from a BUILD file". Is there a way to do nested rules? Doing this on windows. The build file only loads and uses the first rule. Nothing on workspace. ex. .bzl file (I'm aware there may be other things not properly used, however, I'm trying to get over this hiccup first. Thank you!


"""This module extracts the --- files"""

def _rule_one_impl(ctx):
    """This rule blah"""
    ctx.actions.declare_directory("directory path")
    ctx.actions.declare_directory("second directory for testing/learning")
    unzip_files(file = ":files/to_unzip.zip",)

rule_one = rule(
    implementation = _rule_one_impl,
)




def _unzip_files_impl(ctx):
    """This rule extracts the zipped"""
    ctx.extract(
        archive = ctx.attr.file,
        output = ":RIII2",
        executable=True, 
        legacy_utf8=True,

    )


unzip_files = rule(
    implementation = _unzip_files_impl,
    attrs = {
        "file": attr.string(),
    }
)

0

There are 0 answers