Skip to content
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

Proposal: Deps Toolchain Infrastructure #1067

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions scala_proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ toolchain(
visibility = ["//visibility:public"],
)

java_library(
load("//scala_proto/toolchain:toolchain.bzl", "proto_toolchain_deps")

proto_toolchain_deps(
name = "default_scalapb_compile_dependencies",
provider_id = "compile_deps",
visibility = ["//visibility:public"],
exports = DEFAULT_SCALAPB_COMPILE_DEPS,
)

java_library(
proto_toolchain_deps(
name = "default_scalapb_grpc_dependencies",
provider_id = "grpc_deps",
visibility = ["//visibility:public"],
exports = DEFAULT_SCALAPB_GRPC_DEPS,
)
4 changes: 2 additions & 2 deletions scala_proto/private/scalapb_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ scalapb_aspect = aspect(
attrs = {
"_protoc": attr.label(executable = True, cfg = "host", default = "@com_google_protobuf//:protoc"),
"_implicit_compile_deps": attr.label_list(cfg = "target", default = [
"//external:io_bazel_rules_scala/dependency/proto/implicit_compile_deps",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a breaking change, right?
it might be acceptable but I just want to understand the impact.
If someone doesn't use the repositories and just binds by themselves then they'll need to introduce the customization pattern, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if users do not use repositories, they will have to define scalapb deps toolchain.

"@io_bazel_rules_scala//scala_proto:default_scalapb_compile_dependencies",
]),
"_grpc_deps": attr.label_list(cfg = "target", default = [
"//external:io_bazel_rules_scala/dependency/proto/grpc_deps",
"@io_bazel_rules_scala//scala_proto:default_scalapb_grpc_dependencies",
]),
},
toolchains = [
Expand Down
13 changes: 2 additions & 11 deletions scala_proto/scala_proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,8 @@ load(
)

def register_default_proto_dependencies():
if native.existing_rule("io_bazel_rules_scala/dependency/proto/grpc_deps") == None:
native.bind(
name = "io_bazel_rules_scala/dependency/proto/grpc_deps",
actual = "@io_bazel_rules_scala//scala_proto:default_scalapb_grpc_dependencies",
)

if native.existing_rule("io_bazel_rules_scala/dependency/proto/implicit_compile_deps") == None:
native.bind(
name = "io_bazel_rules_scala/dependency/proto/implicit_compile_deps",
actual = "@io_bazel_rules_scala//scala_proto:default_scalapb_compile_dependencies",
)
# for backwards compatibility register toolchain for deps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this.
Will this be forever? Is this temporary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wait with this discussion when we have separate PR for proto deps toolchain

native.register_toolchains("@io_bazel_rules_scala//scala_proto/toolchain:proto_toolchain")

def scala_proto_repositories(
scala_version = _default_scala_version(),
Expand Down
37 changes: 37 additions & 0 deletions scala_proto/toolchain/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
load("@io_bazel_rules_scala//scala:providers.bzl", "declare_deps_provider")
load("//scala/toolchains:toolchains.bzl", "declare_deps_toolchain")
load(":toolchain.bzl", "proto_toolchain_deps")
load("//scala_proto:default_dep_sets.bzl", "DEFAULT_SCALAPB_COMPILE_DEPS", "DEFAULT_SCALAPB_GRPC_DEPS")

toolchain_type(
name = "proto_toolchain_type",
visibility = ["//visibility:public"],
)

toolchain(
name = "proto_toolchain",
toolchain = ":proto_toolchain_impl",
toolchain_type = ":proto_toolchain_type",
visibility = ["//visibility:public"],
)

declare_deps_provider(
name = "scalapb_compile_deps_provider",
visibility = ["//visibility:public"],
deps = DEFAULT_SCALAPB_COMPILE_DEPS,
)

declare_deps_provider(
name = "scalapb_grpc_deps_provider",
visibility = ["//visibility:public"],
deps = DEFAULT_SCALAPB_GRPC_DEPS,
)

declare_deps_toolchain(
name = "proto_toolchain_impl",
dep_providers = {
":scalapb_compile_deps_provider": "compile_deps",
":scalapb_grpc_deps_provider": "grpc_deps",
},
visibility = ["//visibility:public"],
)
16 changes: 16 additions & 0 deletions scala_proto/toolchain/toolchain.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@io_bazel_rules_scala//scala:providers.bzl", "DepsInfo")
load("//scala/private/toolchain_deps:toolchain_deps.bzl", "expose_toolchain_deps")

def _toolchain_deps(ctx):
toolchain_type_label = "@io_bazel_rules_scala//scala_proto/toolchain:proto_toolchain_type"
return expose_toolchain_deps(ctx, toolchain_type_label)

proto_toolchain_deps = rule(
implementation = _toolchain_deps,
attrs = {
"provider_id": attr.string(
mandatory = True,
),
},
toolchains = ["@io_bazel_rules_scala//scala_proto/toolchain:proto_toolchain_type"],
)