Skip to content

Commit

Permalink
Include Bazel Genrule for Fast SSZ (#5070)
Browse files Browse the repository at this point in the history
* rem slasher proto
* Merge branch 'master' of github.com:prysmaticlabs/prysm
* Merge branch 'master' of github.com:prysmaticlabs/prysm
* Merge branch 'master' of github.com:prysmaticlabs/prysm
* Merge branch 'master' of github.com:prysmaticlabs/prysm
* Merge branch 'master' of github.com:prysmaticlabs/prysm
* Merge branch 'master' of github.com:prysmaticlabs/prysm
* Merge branch 'master' of github.com:prysmaticlabs/prysm
* Merge branch 'master' of github.com:prysmaticlabs/prysm
* Merge branch 'master' of github.com:prysmaticlabs/prysm
* Merge branch 'master' of github.com:prysmaticlabs/prysm
* Merge branch 'master' of github.com:prysmaticlabs/prysm
* included new ssz bzl rule
* Merge branch 'master' into add-in-starlark-rule
* Update tools/ssz.bzl

Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com>
  • Loading branch information
rauljordan and prestonvanloon committed Mar 11, 2020
1 parent 7b30845 commit 663d919
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
7 changes: 7 additions & 0 deletions WORKSPACE
Expand Up @@ -1591,3 +1591,10 @@ go_repository(
sum = "h1:J1gHJRNFEk7NdiaPQQqAvxEy+7hhCsVv3uzduWybmqY=",
version = "v0.0.0-20200302201340-8c54356e12c9",
)

go_repository(
name = "com_github_ferranbt_fastssz",
importpath = "github.com/ferranbt/fastssz",
sum = "h1:oUQredbOIzWIMmeGR9dTLzSi4DqRVwxrPzSDiLJBp4Q=",
version = "v0.0.0-20200310214500-3283b9706406",
)
70 changes: 70 additions & 0 deletions tools/ssz.bzl
@@ -0,0 +1,70 @@
load(
"@io_bazel_rules_go//go:def.bzl",
"GoLibrary",
)

def _ssz_go_proto_library_impl(ctx):
go_proto = ctx.attr.go_proto

generated_pb_go_files = go_proto[OutputGroupInfo].go_generated_srcs

# Run the tool on the generated files
package_path = generated_pb_go_files.to_list()[0].dirname
output = ctx.outputs.out
args = [
"--output=%s" % output.path,
"--path=%s" % package_path,
]
if len(ctx.attr.objs) > 0:
args += ["--objs=%s" % ",".join(ctx.attr.objs)]
ctx.actions.run(
executable = ctx.executable.sszgen,
progress_message = "Generating ssz marshal and unmarshal functions",
inputs = generated_pb_go_files,
arguments = args,
outputs = [output],
)

"""
A rule that uses the generated pb.go files from a go_proto_library target to generate SSZ marshal
and unmarshal functions as pointer receivers on the specified objects. To use this rule, provide a
go_proto_library target and specify the structs to generate methods in the "objs" field. Lastly,
include your new target as a source for the go_library that embeds the go_proto_library.
Example:
go_proto_library(
name = "example_go_proto",
...
)
ssz_gen_marshal(
name = "ssz_generated_sources",
go_proto = ":example_go_proto",
objs = [ # omit this field to generate for all structs in the package.
"AddressBook",
"Person",
],
)
go_library(
name = "go_default_library",
srcs = [":ssz_generated_sources"],
embed = [":example_go_proto"],
deps = SSZ_DEPS,
)
"""
ssz_gen_marshal = rule(
implementation = _ssz_go_proto_library_impl,
attrs = {
"go_proto": attr.label(providers = [GoLibrary]),
"sszgen": attr.label(
default = Label("@com_github_ferranbt_fastssz//sszgen:sszgen"),
executable = True,
cfg = "host",
),
"objs": attr.string_list(),
},
outputs = {"out": "generated.ssz.go"},
)

SSZ_DEPS = ["@com_github_ferranbt_fastssz//:go_default_library"]

0 comments on commit 663d919

Please sign in to comment.