def get_output_dir(ctx, owner):
    """
    Finds the proper root bin directory for the protoc tool.

    In the case of a local build, the bin-dir is sufficient. However,
    since the aspect runs in the context of external dependencies,
    it needs to account for this. For example, an external workspace
    with the following structure

    protos
    |- api
    |- |- service.proto
    |- |- BUILD
    |- WORKSPACE

    would have a package @protos//api/service.proto. In this case,
    the declared_output's directory would be bazel-bin/external/protos/api/
    and the package label would be api/. Since the protoc tool places
    its outputs based on the directory structure, we need to specify the
    proper external root. Using the raw bin_dir would end up placing this
    output file in bazel-bin/api, which is not what was declared.
    """

    # Default to using bin_dir
    return ctx.bin_dir.path + "/" + owner.workspace_root