Skip to content

Loading macros from buckaroo dependencies #371

@roey-e

Description

@roey-e

Description

My goal is to use macros defined in a dependency's "bzl" file. This is even more useful when using Bazel, as Bazel provides custom rules in addition to macros.

From my understanding, labels of buckaroo cells should be use with the buckaroo macros and not written explicitly.

protobuf_cell = buckaroo_cell('github.com/roey-e/protobuf')  # buckaroo.github.roey-e.protobuf

In Bazel mode, some hash is added to the workspaces' names. This makes the use of the macros mandatory.

def buckaroo_setup():
  native.local_repository(
    name = "buckaroo_github_com_roey_e_protobuf_a367be9a",  # Can't guess the repo name
    path = "buckaroo/github/roey-e/protobuf"
  )

def buckaroo_workspace(package_name):
  if package_name == "github.com/roey-e/protobuf":
    return "@buckaroo_github_com_roey_e_protobuf_a367be9a"

  fail(package_name + " is not a recognized package")

The problem here is that the load statement in Buck and in Bazel accept string literal only.

Examples:
In Buck:

load('//:buckaroo_macros.bzl', 'buckaroo_cell')

# The cell name of the Protobuf package
protobuf_cell = buckaroo_cell('github.com/roey-e/protobuf')

load(protobuf_cell+'//:buck_protobuf.bzl', 'proto_gen')

In Bazel:

load("//buckaroo:defs.bzl", "buckaroo_workspace")

protobuf_workspace = buckaroo_workspace("github.com/roey-e/protobuf")

load(protobuf_workspace + '//:protobuf.bzl', 'proto_gen')

Expected Behavior

Is there a proper way for loading macros with Buckaroo? How can I make it work?

Actual Behavior

In Buck:

Starting new Buck daemon...
Buck daemon started.
Using additional configuration options from .buckconfig.d/.buckconfig.buckaroo
ERROR: /home/roey/git/nanopb/generator/BUCK:6:6: syntax error at 'protobuf_cell': expected string literal
Cannot parse /home/roey/git/nanopb/generator/BUCK.  It was referenced from //generator:BUCK

In Bazel:

ERROR: /home/roey/git/nanopb/examples/simple/BUILD:5:6: in load statement: empty package-relative label
ERROR: Skipping '//examples/simple:protobuf_workspace': error loading package 'examples/simple': malformed load statements
WARNING: Target pattern parsing failed.
ERROR: error loading package 'examples/simple': malformed load statements
INFO: Elapsed time: 0.222s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded)

Context

Specifically, I'm trying to use protobuf's "proto_gen" rule/macro.

Your Environment

  • Version used: Buckaroo 3.0.1; Buck version dfd6587a6290c638bac2e5e8e1c0e1d25baf2632; Bazel version 3.0.0
  • Operating System and Architecture: WSL 1's Ubuntu 18.04 on top of Windows 10 1909, intel

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions