-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make the scala_protobuf aspect based #700
Changes from 30 commits
f1ae21f
aca15a5
abf490b
bd3e18b
83f621c
73d7fbb
444fc79
a66e78b
537d227
2a76e57
8ecb252
82a46a3
db9bd47
016a403
08c2261
683d724
2a2c386
4e09ac9
1b20ad5
5ddb70c
fbe0a10
9495931
53edf1c
119ecbe
b70967c
5d3b4cb
86dd7b5
85b9d4d
a47135d
ddf87f9
215d89d
31d70ad
e8574fe
83914f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
load("//scala_proto:scala_proto_toolchain.bzl", "scala_proto_toolchain") | ||
|
||
toolchain_type( | ||
name = "toolchain_type", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
scala_proto_toolchain( | ||
name = "default_toolchain_impl", | ||
with_grpc = True, | ||
with_flat_package=False, | ||
with_single_line_to_string=False, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
toolchain( | ||
name = "default_toolchain", | ||
toolchain = ":default_toolchain_impl", | ||
toolchain_type = "@io_bazel_rules_scala//scala_proto:toolchain_type", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
|
||
scala_proto_toolchain( | ||
name = "enable_all_options_toolchain_impl", | ||
with_grpc = True, | ||
with_flat_package=True, | ||
# with_java=True, | ||
with_single_line_to_string=True, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
toolchain( | ||
name = "enable_all_options_toolchain", | ||
toolchain = ":enable_all_options_toolchain_impl", | ||
toolchain_type = "@io_bazel_rules_scala//scala_proto:toolchain_type", | ||
visibility = ["//visibility:public"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
SCALAPB_DEPS = [ | ||
"//external:io_bazel_rules_scala/dependency/proto/scalapb_runtime", | ||
"//external:io_bazel_rules_scala/dependency/com_google_protobuf/protobuf_java", | ||
"//external:io_bazel_rules_scala/dependency/proto/scalapb_lenses", | ||
"//external:io_bazel_rules_scala/dependency/proto/scalapb_fastparse", | ||
] | ||
|
||
GRPC_DEPS = [ | ||
"//external:io_bazel_rules_scala/dependency/proto/scalapb_runtime_grpc", | ||
"//external:io_bazel_rules_scala/dependency/proto/grpc_core", | ||
"//external:io_bazel_rules_scala/dependency/proto/grpc_stub", | ||
"//external:io_bazel_rules_scala/dependency/proto/grpc_protobuf", | ||
"//external:io_bazel_rules_scala/dependency/proto/grpc_netty", | ||
"//external:io_bazel_rules_scala/dependency/proto/grpc_context", | ||
"//external:io_bazel_rules_scala/dependency/proto/guava", | ||
"//external:io_bazel_rules_scala/dependency/proto/opencensus_api", | ||
"//external:io_bazel_rules_scala/dependency/proto/opencensus_contrib_grpc_metrics", | ||
"//external:io_bazel_rules_scala/dependency/proto/google_instrumentation", | ||
"//external:io_bazel_rules_scala/dependency/proto/netty_codec", | ||
"//external:io_bazel_rules_scala/dependency/proto/netty_codec_http", | ||
"//external:io_bazel_rules_scala/dependency/proto/netty_codec_http2", | ||
"//external:io_bazel_rules_scala/dependency/proto/netty_codec_socks", | ||
"//external:io_bazel_rules_scala/dependency/proto/netty_handler", | ||
"//external:io_bazel_rules_scala/dependency/proto/netty_buffer", | ||
"//external:io_bazel_rules_scala/dependency/proto/netty_transport", | ||
"//external:io_bazel_rules_scala/dependency/proto/netty_resolver", | ||
"//external:io_bazel_rules_scala/dependency/proto/netty_common", | ||
"//external:io_bazel_rules_scala/dependency/proto/netty_handler_proxy", | ||
] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
load( | ||
"//scala/private:common.bzl", | ||
"write_manifest_file", | ||
) | ||
load("//scala/private:rule_impls.bzl", "compile_scala") | ||
load("//scala_proto/private:dep_sets.bzl", "SCALAPB_DEPS", "GRPC_DEPS") | ||
|
||
|
||
def _root_path(f): | ||
if f.is_source: | ||
return f.owner.workspace_root | ||
return "/".join([f.root.path, f.owner.workspace_root]) | ||
|
||
|
||
def _colon_paths(data): | ||
return ":".join([ | ||
f.path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you seem to have reverted (maybe by mistake) this change: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've just handled this differently, the external locations all work right in the tests i've done. Instead of a big chain of imports in the rule i just move things to where they are expected. For me it removed a bunch of warnings about |
||
for f in sorted(data) | ||
]) | ||
|
||
|
||
def proto_to_scala_src(ctx, label, code_generator, compile_proto, include_proto, transitive_proto_paths, flags, jar_output): | ||
worker_content = "{output}\n{included_proto}\n{flags_arg}\n{transitive_proto_paths}\n{inputs}\n{protoc}".format( | ||
output = jar_output.path, | ||
included_proto = "-" + ":".join(sorted(["%s,%s" % (f.root.path, f.path) for f in include_proto])), | ||
# Command line args to worker cannot be empty so using padding | ||
flags_arg = "-" + ",".join(flags), | ||
transitive_proto_paths = "-" + ":".join(sorted(transitive_proto_paths)), | ||
# Command line args to worker cannot be empty so using padding | ||
# Pass inputs seprately because they doesn't always match to imports (ie blacklisted protos are excluded) | ||
inputs = _colon_paths(compile_proto), | ||
protoc = ctx.executable._protoc.path | ||
) | ||
argfile = ctx.actions.declare_file( | ||
"%s_worker_input" % label.name, | ||
sibling = jar_output, | ||
) | ||
ctx.actions.write(output = argfile, content = worker_content) | ||
ctx.actions.run( | ||
executable = code_generator.files_to_run, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @johnynek even after registering the default toolchain in my WORKSPACE, I'm getting the following error:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gseitz FYI There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tferi-da This needs a fix from a bazel update -- the latest rules require bazel 0.23 or above now i'm afraid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ianoc thanks for the tip! |
||
inputs = compile_proto + include_proto + [argfile, ctx.executable._protoc], | ||
outputs = [jar_output], | ||
mnemonic = "ProtoScalaPBRule", | ||
progress_message = "creating scalapb files %s" % ctx.label, | ||
execution_requirements = {"supports-workers": "1"}, | ||
arguments = ["@" + argfile.path], | ||
) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I freely admit to not understanding this stuff. It seems really weird to me the whole toolchain_type, toolchain, impl of the toolchain.... but I guess maybe they are mapping a typed system onto dynamic values in skylark.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really know about how much of this is required/needed tbh. I cargo culted this from the scala tool chain