From 460245569417f19ef8f80bdfb1125f3fedf902c8 Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Thu, 26 Nov 2020 18:31:12 +0100 Subject: [PATCH 1/7] ledger-api: Use `proto_jars`. CHANGELOG_BEGIN - [Ledger API] The Scala JARs containing the gRPC definitions no longer contain the *.proto files used to generate the ScalaPB-based classes. CHANGELOG_END --- bazel_tools/proto.bzl | 61 ++++++++-- .../java/bindings-rxjava/BUILD.bazel | 4 +- language-support/java/bindings/BUILD.bazel | 4 +- language-support/scala/bindings/BUILD.bazel | 4 +- ledger-api/grpc-definitions/BUILD.bazel | 106 ++---------------- ledger-api/testing-utils/BUILD.bazel | 2 +- ledger/ledger-api-akka/BUILD.bazel | 4 +- ledger/ledger-api-auth/BUILD.bazel | 2 +- ledger/participant-state-index/BUILD.bazel | 2 +- ledger/test-common/BUILD.bazel | 2 +- libs-scala/grpc-utils/BUILD.bazel | 2 +- release/artifacts.yaml | 2 +- release/util.bzl | 5 +- 13 files changed, 79 insertions(+), 121 deletions(-) diff --git a/bazel_tools/proto.bzl b/bazel_tools/proto.bzl index 27060d94da46..1bd0e4c54f48 100644 --- a/bazel_tools/proto.bzl +++ b/bazel_tools/proto.bzl @@ -4,6 +4,7 @@ load("//bazel_tools:javadoc_library.bzl", "javadoc_library") load("//bazel_tools:pkg.bzl", "pkg_empty_zip") load("//bazel_tools:pom_file.bzl", "pom_file") +load("//bazel_tools:scala.bzl", "scala_source_jar", "scaladoc_jar") load("@io_bazel_rules_scala//scala:scala.bzl", "scala_library") load("@os_info//:os_info.bzl", "is_windows") load("@rules_pkg//:pkg.bzl", "pkg_tar") @@ -176,6 +177,7 @@ def proto_jars( name, srcs, strip_import_prefix = "", + grpc = False, deps = [], proto_deps = [], java_deps = [], @@ -183,7 +185,8 @@ def proto_jars( javadoc_root_packages = [], maven_group = None, maven_artifact_prefix = None, - maven_java_artifact_suffix = "java-proto"): + maven_artifact_java_suffix = "java-proto", + maven_artifact_scala_suffix = "scala-proto"): # Tarball containing the *.proto files. pkg_tar( name = "%s_src" % name, @@ -205,9 +208,9 @@ def proto_jars( # JAR containing the generated Java bindings. native.java_proto_library( name = "%s_java" % name, - tags = maven_tags(maven_group, maven_artifact_prefix, maven_java_artifact_suffix), + tags = maven_tags(maven_group, maven_artifact_prefix, maven_artifact_java_suffix), visibility = ["//visibility:public"], - deps = [":%s" % name] + java_deps, + deps = [":%s" % name], ) if maven_group and maven_artifact_prefix: @@ -235,11 +238,33 @@ def proto_jars( ) # JAR containing the generated Scala bindings. + all_scala_srcs = [":%s" % name] + ([ + "@com_github_googleapis_googleapis//google/rpc:code_proto", + "@com_github_googleapis_googleapis//google/rpc:status_proto", + "@com_github_grpc_grpc//src/proto/grpc/health/v1:health_proto_descriptor", + ] if grpc else []) + + all_scala_deps = [ + "@maven//:com_google_protobuf_protobuf_java", + "@maven//:com_thesamet_scalapb_lenses_2_12", + "@maven//:com_thesamet_scalapb_scalapb_runtime_2_12", + ] + ([ + "@maven//:com_thesamet_scalapb_scalapb_runtime_grpc_2_12", + "@maven//:io_grpc_grpc_api", + "@maven//:io_grpc_grpc_core", + "@maven//:io_grpc_grpc_protobuf", + "@maven//:io_grpc_grpc_stub", + ] if grpc else []) + [ + "%s_scala" % label + for label in proto_deps + ] + proto_gen( name = "%s_scala_sources" % name, - srcs = [":%s" % name], + srcs = all_scala_srcs, plugin_exec = "//scala-protoc-plugins/scalapb:protoc-gen-scalapb", plugin_name = "scalapb", + plugin_options = ["grpc"] if grpc else [], visibility = ["//visibility:public"], deps = deps + proto_deps, ) @@ -247,11 +272,29 @@ def proto_jars( scala_library( name = "%s_scala" % name, srcs = [":%s_scala_sources" % name], + tags = maven_tags(maven_group, maven_artifact_prefix, maven_artifact_scala_suffix), unused_dependency_checker_mode = "error", visibility = ["//visibility:public"], - deps = [ - "@maven//:com_google_protobuf_protobuf_java", - "@maven//:com_thesamet_scalapb_lenses_2_12", - "@maven//:com_thesamet_scalapb_scalapb_runtime_2_12", - ] + ["%s_scala" % label for label in proto_deps] + scala_deps, + deps = all_scala_deps, + exports = all_scala_deps, + ) + + scala_source_jar( + name = "%s_scala_src" % name, + srcs = [":%s_scala_sources" % name], ) + + scaladoc_jar( + name = "%s_scala_scaladoc" % name, + srcs = [":%s_scala_sources" % name], + tags = ["scaladoc"], + deps = [], + visibility = ["//visibility:public"], + ) if is_windows == False else None + + if maven_group and maven_artifact_prefix: + pom_file( + name = "%s_scala_pom" % name, + target = ":%s_scala" % name, + visibility = ["//visibility:public"], + ) diff --git a/language-support/java/bindings-rxjava/BUILD.bazel b/language-support/java/bindings-rxjava/BUILD.bazel index 4a8ca496b4c0..7ed060d8f56c 100644 --- a/language-support/java/bindings-rxjava/BUILD.bazel +++ b/language-support/java/bindings-rxjava/BUILD.bazel @@ -63,7 +63,7 @@ da_scala_library( ":bindings-rxjava", "//daml-lf/data", "//language-support/java/bindings:bindings-java", - "//ledger-api/grpc-definitions:ledger-api-scalapb", + "//ledger-api/grpc-definitions:ledger_api_proto_scala", "//ledger-api/rs-grpc-bridge", "//ledger/ledger-api-auth", "//ledger/ledger-api-common", @@ -97,7 +97,7 @@ da_scala_test_suite( ":bindings-java-tests-lib", ":bindings-rxjava", "//language-support/java/bindings:bindings-java", - "//ledger-api/grpc-definitions:ledger-api-scalapb", + "//ledger-api/grpc-definitions:ledger_api_proto_scala", "//ledger/ledger-api-auth", "//ledger/ledger-api-common", "//libs-scala/grpc-utils", diff --git a/language-support/java/bindings/BUILD.bazel b/language-support/java/bindings/BUILD.bazel index 572a7c9e3d5f..86a57f7c9b55 100644 --- a/language-support/java/bindings/BUILD.bazel +++ b/language-support/java/bindings/BUILD.bazel @@ -11,7 +11,7 @@ load("//bazel_tools:java.bzl", "da_java_library") proto_gen( name = "ledger-api-java", - srcs = ["//ledger-api/grpc-definitions:protos"], + srcs = ["//ledger-api/grpc-definitions:ledger_api_proto"], plugin_name = "java", visibility = [ "//visibility:public", @@ -51,7 +51,7 @@ java_library( proto_gen( name = "ledger-api-java-grpc", - srcs = ["//ledger-api/grpc-definitions:protos"], + srcs = ["//ledger-api/grpc-definitions:ledger_api_proto"], plugin_exec = "@io_grpc_grpc_java//compiler:grpc_java_plugin", plugin_name = "java-grpc", visibility = [ diff --git a/language-support/scala/bindings/BUILD.bazel b/language-support/scala/bindings/BUILD.bazel index be588bc339e5..46ec0e3c1561 100644 --- a/language-support/scala/bindings/BUILD.bazel +++ b/language-support/scala/bindings/BUILD.bazel @@ -20,13 +20,13 @@ da_scala_library( ], exports = [ "//daml-lf/data", - "//ledger-api/grpc-definitions:ledger-api-scalapb", + "//ledger-api/grpc-definitions:ledger_api_proto_scala", "@maven//:io_grpc_grpc_core", "@maven//:org_scalaz_scalaz_core_2_12", ], deps = [ "//daml-lf/data", - "//ledger-api/grpc-definitions:ledger-api-scalapb", + "//ledger-api/grpc-definitions:ledger_api_proto_scala", "@maven//:io_grpc_grpc_core", "@maven//:org_scalaz_scalaz_core_2_12", ], diff --git a/ledger-api/grpc-definitions/BUILD.bazel b/ledger-api/grpc-definitions/BUILD.bazel index d1c7ffad9c4a..abcd7620c8b5 100644 --- a/ledger-api/grpc-definitions/BUILD.bazel +++ b/ledger-api/grpc-definitions/BUILD.bazel @@ -1,27 +1,26 @@ # Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -load("@rules_pkg//:pkg.bzl", "pkg_tar") load("//bazel_tools:haskell.bzl", "da_haskell_library") -load("//bazel_tools:proto.bzl", "proto_gen") -load("//bazel_tools:pom_file.bzl", "pom_file") -load("@io_bazel_rules_scala//scala:scala.bzl", "scala_library") +load("//bazel_tools:proto.bzl", "proto_gen", "proto_jars") load( "//bazel_tools:scala.bzl", "scala_source_jar", "scaladoc_jar", ) load("@os_info//:os_info.bzl", "is_windows") +load("@rules_pkg//:pkg.bzl", "pkg_tar") ledger_api_proto_source_root = "ledger-api/grpc-definitions" -proto_library( - name = "protos", +proto_jars( + name = "ledger_api_proto", srcs = glob(["**/*.proto"]), + grpc = True, + maven_artifact_prefix = "ledger-api", + maven_artifact_scala_suffix = "scalapb", + maven_group = "com.daml", strip_import_prefix = "/" + ledger_api_proto_source_root, - visibility = [ - "//visibility:public", - ], deps = [ "@com_github_googleapis_googleapis//google/rpc:status_proto", "@com_google_protobuf//:any_proto", @@ -33,40 +32,6 @@ proto_library( ], ) -pkg_tar( - name = "ledger-api-protos", - srcs = glob(["**/*.proto"]) + ["README.md"], - extension = "tar.gz", - strip_prefix = "./", - visibility = [ - "//visibility:public", - ], -) - -proto_gen( - name = "ledger-api-scalapb-sources", - srcs = [ - ":protos", - "@com_github_googleapis_googleapis//google/rpc:code_proto", - "@com_github_googleapis_googleapis//google/rpc:status_proto", - "@com_github_grpc_grpc//src/proto/grpc/health/v1:health_proto_descriptor", - ], - plugin_exec = "//scala-protoc-plugins/scalapb:protoc-gen-scalapb", - plugin_name = "scalapb", - plugin_options = ["grpc"], - visibility = [ - "//visibility:public", - ], - deps = [ - "@com_google_protobuf//:any_proto", - "@com_google_protobuf//:descriptor_proto", - "@com_google_protobuf//:duration_proto", - "@com_google_protobuf//:empty_proto", - "@com_google_protobuf//:timestamp_proto", - "@com_google_protobuf//:wrappers_proto", - ], -) - google_protobuf_src = "external/com_google_protobuf/src" genrule( @@ -272,62 +237,9 @@ da_haskell_library( visibility = ["//visibility:public"], ) -# ScalaPB Ledger API plus protobuf sources for customized compilation -scala_library( - name = "ledger-api-scalapb", - srcs = [":ledger-api-scalapb-sources"], - resource_strip_prefix = ledger_api_proto_source_root, - resources = glob(["**/*.proto"]), - tags = [ - "maven_coordinates=com.daml:ledger-api-scalapb:__VERSION__", - ], - unused_dependency_checker_mode = "error", - visibility = ["//visibility:public"], - exports = [ - "@maven//:com_google_protobuf_protobuf_java", - "@maven//:com_thesamet_scalapb_lenses_2_12", - "@maven//:com_thesamet_scalapb_scalapb_runtime_2_12", - "@maven//:com_thesamet_scalapb_scalapb_runtime_grpc_2_12", - "@maven//:io_grpc_grpc_api", - "@maven//:io_grpc_grpc_core", - "@maven//:io_grpc_grpc_protobuf", - "@maven//:io_grpc_grpc_stub", - ], - deps = [ - "@maven//:com_google_protobuf_protobuf_java", - "@maven//:com_thesamet_scalapb_lenses_2_12", - "@maven//:com_thesamet_scalapb_scalapb_runtime_2_12", - "@maven//:com_thesamet_scalapb_scalapb_runtime_grpc_2_12", - "@maven//:io_grpc_grpc_api", - "@maven//:io_grpc_grpc_core", - "@maven//:io_grpc_grpc_protobuf", - "@maven//:io_grpc_grpc_stub", - ], -) - -pom_file( - name = "ledger-api-scalapb_pom", - target = ":ledger-api-scalapb", -) - -# Create empty Scaladoc JAR for uploading to Maven Central -scaladoc_jar( - name = "ledger-api-scalapb_scaladoc", - srcs = [], - tags = ["scaladoc"], - deps = [], -) if is_windows == False else None - -# Provide protobuf sources -scala_source_jar( - name = "ledger-api-scalapb_src", - srcs = glob(["**/*.proto"]), - strip_upto = ledger_api_proto_source_root, -) - proto_gen( name = "ledger-api-docs", - srcs = [":protos"], + srcs = [":ledger_api_proto"], plugin_exec = "@com_github_pseudomuto_protoc_gen_doc//cmd/protoc-gen-doc:protoc-gen-doc", plugin_name = "doc", plugin_options = [ diff --git a/ledger-api/testing-utils/BUILD.bazel b/ledger-api/testing-utils/BUILD.bazel index a1e250fd1a1b..fa3e6937f7af 100644 --- a/ledger-api/testing-utils/BUILD.bazel +++ b/ledger-api/testing-utils/BUILD.bazel @@ -18,7 +18,7 @@ da_scala_library( "@maven//:org_slf4j_slf4j_api", ], deps = [ - "//ledger-api/grpc-definitions:ledger-api-scalapb", + "//ledger-api/grpc-definitions:ledger_api_proto_scala", "//ledger-api/rs-grpc-akka", "//ledger-api/rs-grpc-bridge", "//libs-scala/concurrent", diff --git a/ledger/ledger-api-akka/BUILD.bazel b/ledger/ledger-api-akka/BUILD.bazel index a04657c7196f..5c03294e972e 100644 --- a/ledger/ledger-api-akka/BUILD.bazel +++ b/ledger/ledger-api-akka/BUILD.bazel @@ -7,7 +7,7 @@ load("//bazel_tools:proto.bzl", "proto_gen") proto_gen( name = "ledger-api-akka-srcs", srcs = [ - "//ledger-api/grpc-definitions:protos", + "//ledger-api/grpc-definitions:ledger_api_proto", "@com_github_grpc_grpc//src/proto/grpc/health/v1:health_proto_descriptor", ], plugin_exec = "//scala-protoc-plugins/scala-akka:protoc-gen-scala-akka", @@ -31,7 +31,7 @@ da_scala_library( "//visibility:public", ], deps = [ - "//ledger-api/grpc-definitions:ledger-api-scalapb", + "//ledger-api/grpc-definitions:ledger_api_proto_scala", "//ledger-api/rs-grpc-akka", "//ledger-api/rs-grpc-bridge", "@maven//:com_typesafe_akka_akka_actor_2_12", diff --git a/ledger/ledger-api-auth/BUILD.bazel b/ledger/ledger-api-auth/BUILD.bazel index 74811c2e78f1..4a6bd60ca08d 100644 --- a/ledger/ledger-api-auth/BUILD.bazel +++ b/ledger/ledger-api-auth/BUILD.bazel @@ -19,7 +19,7 @@ da_scala_library( runtime_deps = [], deps = [ "//daml-lf/data", - "//ledger-api/grpc-definitions:ledger-api-scalapb", + "//ledger-api/grpc-definitions:ledger_api_proto_scala", "//ledger-service/jwt", "//ledger/ledger-api-common", "//libs-scala/concurrent", diff --git a/ledger/participant-state-index/BUILD.bazel b/ledger/participant-state-index/BUILD.bazel index 4dc3fb167099..96b77ef96751 100644 --- a/ledger/participant-state-index/BUILD.bazel +++ b/ledger/participant-state-index/BUILD.bazel @@ -20,7 +20,7 @@ da_scala_library( "//daml-lf/data", "//daml-lf/language", "//daml-lf/transaction", - "//ledger-api/grpc-definitions:ledger-api-scalapb", + "//ledger-api/grpc-definitions:ledger_api_proto_scala", "//ledger/ledger-api-domain", "//ledger/ledger-api-health", "//ledger/participant-state", diff --git a/ledger/test-common/BUILD.bazel b/ledger/test-common/BUILD.bazel index d121c336be22..bd7bfda0125e 100644 --- a/ledger/test-common/BUILD.bazel +++ b/ledger/test-common/BUILD.bazel @@ -25,7 +25,7 @@ da_scala_library( "//visibility:public", ], deps = [ - "//ledger-api/grpc-definitions:ledger-api-scalapb", + "//ledger-api/grpc-definitions:ledger_api_proto_scala", "//libs-scala/timer-utils", "@maven//:ch_qos_logback_logback_classic", "@maven//:ch_qos_logback_logback_core", diff --git a/libs-scala/grpc-utils/BUILD.bazel b/libs-scala/grpc-utils/BUILD.bazel index 90ca255d7305..ec82918374aa 100644 --- a/libs-scala/grpc-utils/BUILD.bazel +++ b/libs-scala/grpc-utils/BUILD.bazel @@ -14,7 +14,7 @@ da_scala_library( "//visibility:public", ], deps = [ - "//ledger-api/grpc-definitions:ledger-api-scalapb", + "//ledger-api/grpc-definitions:ledger_api_proto_scala", "@maven//:io_grpc_grpc_api", ], ) diff --git a/release/artifacts.yaml b/release/artifacts.yaml index cdfe8f615f84..d45d1da56071 100644 --- a/release/artifacts.yaml +++ b/release/artifacts.yaml @@ -57,7 +57,7 @@ type: jar-scala - target: //language-support/scala/codegen:codegen type: jar-scala -- target: //ledger-api/grpc-definitions:ledger-api-scalapb +- target: //ledger-api/grpc-definitions:ledger_api_proto_scala type: jar-scala - target: //ledger-api/rs-grpc-akka:rs-grpc-akka type: jar-scala diff --git a/release/util.bzl b/release/util.bzl index 7eaaa641404f..bf36a314bd54 100644 --- a/release/util.bzl +++ b/release/util.bzl @@ -143,7 +143,10 @@ protos_zip = rule( for version in LF_VERSIONS ], ), - "ledger_api_tarball": attr.label(allow_single_file = True, default = Label("//ledger-api/grpc-definitions:ledger-api-protos.tar.gz")), + "ledger_api_tarball": attr.label( + allow_single_file = True, + default = Label("//ledger-api/grpc-definitions:ledger_api_proto_src.tar.gz"), + ), "zipper": attr.label( default = Label("@bazel_tools//tools/zip:zipper"), cfg = "host", From 46ac42cac25b906c8b39700a00b329ad405c2ea0 Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Fri, 27 Nov 2020 12:38:43 +0100 Subject: [PATCH 2/7] Create a source JAR for *.proto files in `proto_jars`. --- bazel_tools/proto.bzl | 22 ++++++++++++++++++-- daml-lf/archive/BUILD.bazel | 2 +- ledger-api/grpc-definitions/BUILD.bazel | 1 - ledger/participant-state/kvutils/BUILD.bazel | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/bazel_tools/proto.bzl b/bazel_tools/proto.bzl index 1bd0e4c54f48..d30e16f1977b 100644 --- a/bazel_tools/proto.bzl +++ b/bazel_tools/proto.bzl @@ -168,8 +168,9 @@ def _is_windows(ctx): return ctx.configuration.host_path_separator == ";" def maven_tags(group, artifact_prefix, artifact_suffix): - if group and artifact_prefix and artifact_suffix: - return ["maven_coordinates=%s:%s-%s:__VERSION__" % (group, artifact_prefix, artifact_suffix)] + if group and artifact_prefix: + artifact = artifact_prefix + "-" + artifact_suffix if artifact_suffix else artifact_prefix + return ["maven_coordinates=%s:%s:__VERSION__" % (group, artifact)] else: return [] @@ -185,6 +186,7 @@ def proto_jars( javadoc_root_packages = [], maven_group = None, maven_artifact_prefix = None, + maven_artifact_proto_suffix = None, maven_artifact_java_suffix = "java-proto", maven_artifact_scala_suffix = "scala-proto"): # Tarball containing the *.proto files. @@ -196,6 +198,22 @@ def proto_jars( visibility = ["//visibility:public"], ) + # JAR containing the *.proto files. + native.java_library( + name = "%s_proto_jar" % name, + resources = srcs, + resource_strip_prefix = "%s/%s/" % (native.package_name(), strip_import_prefix), + tags = maven_tags(maven_group, maven_artifact_prefix, maven_artifact_proto_suffix), + visibility = ["//visibility:public"], + ) + + if maven_group and maven_artifact_prefix: + pom_file( + name = "%s_proto_jar_pom" % name, + target = ":%s_proto_jar" % name, + visibility = ["//visibility:public"], + ) + # Compiled protobufs. Used in subsequent targets. proto_library( name = name, diff --git a/daml-lf/archive/BUILD.bazel b/daml-lf/archive/BUILD.bazel index 24ff82a86827..365cc5dec37c 100644 --- a/daml-lf/archive/BUILD.bazel +++ b/daml-lf/archive/BUILD.bazel @@ -45,7 +45,7 @@ load("@rules_pkg//:pkg.bzl", "pkg_tar") ], maven_artifact_prefix = "daml-lf-%s-archive" % version, maven_group = "com.daml", - strip_import_prefix = "src/main/protobuf/", + strip_import_prefix = "src/main/protobuf", ), ] for version in LF_VERSIONS diff --git a/ledger-api/grpc-definitions/BUILD.bazel b/ledger-api/grpc-definitions/BUILD.bazel index abcd7620c8b5..f7e09388dfde 100644 --- a/ledger-api/grpc-definitions/BUILD.bazel +++ b/ledger-api/grpc-definitions/BUILD.bazel @@ -20,7 +20,6 @@ proto_jars( maven_artifact_prefix = "ledger-api", maven_artifact_scala_suffix = "scalapb", maven_group = "com.daml", - strip_import_prefix = "/" + ledger_api_proto_source_root, deps = [ "@com_github_googleapis_googleapis//google/rpc:status_proto", "@com_google_protobuf//:any_proto", diff --git a/ledger/participant-state/kvutils/BUILD.bazel b/ledger/participant-state/kvutils/BUILD.bazel index dc929653785a..f26bdf2677ea 100644 --- a/ledger/participant-state/kvutils/BUILD.bazel +++ b/ledger/participant-state/kvutils/BUILD.bazel @@ -166,7 +166,7 @@ proto_jars( "//daml-lf/transaction:value_proto", "//ledger/participant-state/protobuf:ledger_configuration_proto", ], - strip_import_prefix = "src/main/protobuf/", + strip_import_prefix = "src/main/protobuf", deps = [ "@com_google_protobuf//:duration_proto", "@com_google_protobuf//:empty_proto", From 35db022e8a40a58ddab75a4cebd9db42ddb0eed8 Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Fri, 27 Nov 2020 14:19:48 +0100 Subject: [PATCH 3/7] ledger-api: Publish the protobuf sources as "ledger-api-proto". CHANGELOG_BEGIN - [Ledger API] The *.proto files containing the gRPC definitions are now provided by a new Maven Central artifact, with the group "com.daml" and the artifact name "ledger-api-proto". CHANGELOG_END --- bazel_tools/proto.bzl | 27 ++++++++++++++------------- release/artifacts.yaml | 3 +++ release/src/Util.hs | 4 +++- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/bazel_tools/proto.bzl b/bazel_tools/proto.bzl index d30e16f1977b..6d342efdb1fe 100644 --- a/bazel_tools/proto.bzl +++ b/bazel_tools/proto.bzl @@ -1,6 +1,7 @@ # Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. # SPDX-License-Identifier: Apache-2.0 +load("//bazel_tools:java.bzl", "da_java_library") load("//bazel_tools:javadoc_library.bzl", "javadoc_library") load("//bazel_tools:pkg.bzl", "pkg_empty_zip") load("//bazel_tools:pom_file.bzl", "pom_file") @@ -186,7 +187,7 @@ def proto_jars( javadoc_root_packages = [], maven_group = None, maven_artifact_prefix = None, - maven_artifact_proto_suffix = None, + maven_artifact_proto_suffix = "proto", maven_artifact_java_suffix = "java-proto", maven_artifact_scala_suffix = "scala-proto"): # Tarball containing the *.proto files. @@ -198,21 +199,22 @@ def proto_jars( visibility = ["//visibility:public"], ) - # JAR containing the *.proto files. - native.java_library( + # JAR and source JAR containing the *.proto files. + da_java_library( name = "%s_proto_jar" % name, + srcs = None, + deps = None, resources = srcs, resource_strip_prefix = "%s/%s/" % (native.package_name(), strip_import_prefix), tags = maven_tags(maven_group, maven_artifact_prefix, maven_artifact_proto_suffix), visibility = ["//visibility:public"], ) - if maven_group and maven_artifact_prefix: - pom_file( - name = "%s_proto_jar_pom" % name, - target = ":%s_proto_jar" % name, - visibility = ["//visibility:public"], - ) + # Create an empty Javadoc JAR for uploading the source proto JAR to Maven Central. + pkg_empty_zip( + name = "%s_proto_jar_javadoc" % name, + out = "%s_proto_jar_javadoc.jar" % name, + ) # Compiled protobufs. Used in subsequent targets. proto_library( @@ -223,7 +225,7 @@ def proto_jars( deps = deps + proto_deps, ) - # JAR containing the generated Java bindings. + # JAR and source JAR containing the generated Java bindings. native.java_proto_library( name = "%s_java" % name, tags = maven_tags(maven_group, maven_artifact_prefix, maven_artifact_java_suffix), @@ -234,6 +236,7 @@ def proto_jars( if maven_group and maven_artifact_prefix: pom_file( name = "%s_java_pom" % name, + tags = maven_tags(maven_group, maven_artifact_prefix, maven_artifact_java_suffix), target = ":%s_java" % name, visibility = ["//visibility:public"], ) @@ -247,9 +250,7 @@ def proto_jars( deps = ["@maven//:com_google_protobuf_protobuf_java"], ) if not is_windows else None else: - # Create an empty Javadoc JAR for uploading proto JARs to Maven Central. - # We don't need to create an empty JAR file for sources, because `java_proto_library` - # creates a source JAR automatically. + # Create an empty Javadoc JAR for uploading the compiled proto JAR to Maven Central. pkg_empty_zip( name = "%s_java_javadoc" % name, out = "%s_java_javadoc.jar" % name, diff --git a/release/artifacts.yaml b/release/artifacts.yaml index d45d1da56071..14bdc8370182 100644 --- a/release/artifacts.yaml +++ b/release/artifacts.yaml @@ -57,6 +57,9 @@ type: jar-scala - target: //language-support/scala/codegen:codegen type: jar-scala +- target: //ledger-api/grpc-definitions:ledger_api_proto_proto_jar + type: jar-lib + main-jar: libledger_api_proto_proto_jar.jar - target: //ledger-api/grpc-definitions:ledger_api_proto_scala type: jar-scala - target: //ledger-api/rs-grpc-akka:rs-grpc-akka diff --git a/release/src/Util.hs b/release/src/Util.hs index 268cdd7ed907..20cfa7708123 100644 --- a/release/src/Util.hs +++ b/release/src/Util.hs @@ -96,6 +96,7 @@ instance FromJSON ReleaseType where data Artifact c = Artifact { artTarget :: !BazelTarget , artReleaseType :: !ReleaseType + , artMainJar :: !(Maybe (Path Rel File)) , artJavadocJar :: !(Maybe (Path Rel File)) , artSourceJar :: !(Maybe (Path Rel File)) -- artJavadocJar and artSourceJar can be used to specify the path to @@ -111,6 +112,7 @@ instance FromJSON (Artifact (Maybe ArtifactLocation)) where parseJSON = withObject "Artifact" $ \o -> Artifact <$> o .: "target" <*> o .: "type" + <*> o .:? "main-jar" <*> o .:? "javadoc-jar" <*> o .:? "src-jar" <*> o .:? "location" @@ -292,7 +294,7 @@ artifactFiles artifact@Artifact{..} = do -- ^ Note that the Scaladoc is specified with the "javadoc" classifier. mainArtifactPath :: E.MonadThrow m => Text -> Artifact a -> m (Path Rel File) -mainArtifactPath name artifact = parseRelFile $ unpack $ mainFileName (artReleaseType artifact) name +mainArtifactPath name artifact = maybe (parseRelFile $ unpack $ mainFileName (artReleaseType artifact) name) return (artMainJar artifact) pomFilePath :: E.MonadThrow m => Text -> m (Path Rel File) pomFilePath name = parseRelFile $ unpack $ name <> "_pom.xml" From cf0e7873284107ba70c6665535acce745a654047 Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Fri, 27 Nov 2020 16:20:37 +0100 Subject: [PATCH 4/7] release: We don't need the "main-jar" option. --- release/artifacts.yaml | 1 - release/src/Util.hs | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/release/artifacts.yaml b/release/artifacts.yaml index 14bdc8370182..ff271fc5ef7d 100644 --- a/release/artifacts.yaml +++ b/release/artifacts.yaml @@ -59,7 +59,6 @@ type: jar-scala - target: //ledger-api/grpc-definitions:ledger_api_proto_proto_jar type: jar-lib - main-jar: libledger_api_proto_proto_jar.jar - target: //ledger-api/grpc-definitions:ledger_api_proto_scala type: jar-scala - target: //ledger-api/rs-grpc-akka:rs-grpc-akka diff --git a/release/src/Util.hs b/release/src/Util.hs index 20cfa7708123..268cdd7ed907 100644 --- a/release/src/Util.hs +++ b/release/src/Util.hs @@ -96,7 +96,6 @@ instance FromJSON ReleaseType where data Artifact c = Artifact { artTarget :: !BazelTarget , artReleaseType :: !ReleaseType - , artMainJar :: !(Maybe (Path Rel File)) , artJavadocJar :: !(Maybe (Path Rel File)) , artSourceJar :: !(Maybe (Path Rel File)) -- artJavadocJar and artSourceJar can be used to specify the path to @@ -112,7 +111,6 @@ instance FromJSON (Artifact (Maybe ArtifactLocation)) where parseJSON = withObject "Artifact" $ \o -> Artifact <$> o .: "target" <*> o .: "type" - <*> o .:? "main-jar" <*> o .:? "javadoc-jar" <*> o .:? "src-jar" <*> o .:? "location" @@ -294,7 +292,7 @@ artifactFiles artifact@Artifact{..} = do -- ^ Note that the Scaladoc is specified with the "javadoc" classifier. mainArtifactPath :: E.MonadThrow m => Text -> Artifact a -> m (Path Rel File) -mainArtifactPath name artifact = maybe (parseRelFile $ unpack $ mainFileName (artReleaseType artifact) name) return (artMainJar artifact) +mainArtifactPath name artifact = parseRelFile $ unpack $ mainFileName (artReleaseType artifact) name pomFilePath :: E.MonadThrow m => Text -> m (Path Rel File) pomFilePath name = parseRelFile $ unpack $ name <> "_pom.xml" From b4898e2004f8b10657efcee14b63a5b1f205546b Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Fri, 27 Nov 2020 16:21:00 +0100 Subject: [PATCH 5/7] Bazel: Proto JARs will always have a Maven artifact suffix. --- bazel_tools/proto.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bazel_tools/proto.bzl b/bazel_tools/proto.bzl index 6d342efdb1fe..1a94450a9591 100644 --- a/bazel_tools/proto.bzl +++ b/bazel_tools/proto.bzl @@ -170,7 +170,7 @@ def _is_windows(ctx): def maven_tags(group, artifact_prefix, artifact_suffix): if group and artifact_prefix: - artifact = artifact_prefix + "-" + artifact_suffix if artifact_suffix else artifact_prefix + artifact = artifact_prefix + "-" + artifact_suffix return ["maven_coordinates=%s:%s:__VERSION__" % (group, artifact)] else: return [] From 657d0fb54d9d103d8acef5620da14366b00bc437 Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Fri, 27 Nov 2020 16:30:08 +0100 Subject: [PATCH 6/7] Bazel: Simplify Protobuf source file TAR and JAR targets. --- bazel_tools/proto.bzl | 12 ++++++------ release/artifacts.yaml | 2 +- release/util.bzl | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bazel_tools/proto.bzl b/bazel_tools/proto.bzl index 1a94450a9591..523afab52564 100644 --- a/bazel_tools/proto.bzl +++ b/bazel_tools/proto.bzl @@ -192,7 +192,7 @@ def proto_jars( maven_artifact_scala_suffix = "scala-proto"): # Tarball containing the *.proto files. pkg_tar( - name = "%s_src" % name, + name = "%s_tar" % name, srcs = srcs, extension = "tar.gz", strip_prefix = strip_import_prefix, @@ -201,7 +201,7 @@ def proto_jars( # JAR and source JAR containing the *.proto files. da_java_library( - name = "%s_proto_jar" % name, + name = "%s_jar" % name, srcs = None, deps = None, resources = srcs, @@ -210,10 +210,10 @@ def proto_jars( visibility = ["//visibility:public"], ) - # Create an empty Javadoc JAR for uploading the source proto JAR to Maven Central. + # An empty Javadoc JAR for uploading the source proto JAR to Maven Central. pkg_empty_zip( - name = "%s_proto_jar_javadoc" % name, - out = "%s_proto_jar_javadoc.jar" % name, + name = "%s_jar_javadoc" % name, + out = "%s_jar_javadoc.jar" % name, ) # Compiled protobufs. Used in subsequent targets. @@ -250,7 +250,7 @@ def proto_jars( deps = ["@maven//:com_google_protobuf_protobuf_java"], ) if not is_windows else None else: - # Create an empty Javadoc JAR for uploading the compiled proto JAR to Maven Central. + # An empty Javadoc JAR for uploading the compiled proto JAR to Maven Central. pkg_empty_zip( name = "%s_java_javadoc" % name, out = "%s_java_javadoc.jar" % name, diff --git a/release/artifacts.yaml b/release/artifacts.yaml index ff271fc5ef7d..21d6699f9342 100644 --- a/release/artifacts.yaml +++ b/release/artifacts.yaml @@ -57,7 +57,7 @@ type: jar-scala - target: //language-support/scala/codegen:codegen type: jar-scala -- target: //ledger-api/grpc-definitions:ledger_api_proto_proto_jar +- target: //ledger-api/grpc-definitions:ledger_api_proto_jar type: jar-lib - target: //ledger-api/grpc-definitions:ledger_api_proto_scala type: jar-scala diff --git a/release/util.bzl b/release/util.bzl index bf36a314bd54..d0e50b50b115 100644 --- a/release/util.bzl +++ b/release/util.bzl @@ -139,13 +139,13 @@ protos_zip = rule( "daml_lf_tarballs": attr.label_list( allow_files = True, default = [ - Label("//daml-lf/archive:daml_lf_{}_archive_proto_src.tar.gz".format(version)) + Label("//daml-lf/archive:daml_lf_{}_archive_proto_tar.tar.gz".format(version)) for version in LF_VERSIONS ], ), "ledger_api_tarball": attr.label( allow_single_file = True, - default = Label("//ledger-api/grpc-definitions:ledger_api_proto_src.tar.gz"), + default = Label("//ledger-api/grpc-definitions:ledger_api_proto_tar.tar.gz"), ), "zipper": attr.label( default = Label("@bazel_tools//tools/zip:zipper"), From fbe78ed291bfdd0c7bbdc9a95c0be0ae081be83d Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Fri, 27 Nov 2020 17:29:41 +0100 Subject: [PATCH 7/7] Bazel: Extract out Protobuf functions. --- bazel_tools/proto.bzl | 58 +++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/bazel_tools/proto.bzl b/bazel_tools/proto.bzl index 523afab52564..94d696935b98 100644 --- a/bazel_tools/proto.bzl +++ b/bazel_tools/proto.bzl @@ -168,13 +168,36 @@ proto_gen = rule( def _is_windows(ctx): return ctx.configuration.host_path_separator == ";" -def maven_tags(group, artifact_prefix, artifact_suffix): +def _maven_tags(group, artifact_prefix, artifact_suffix): if group and artifact_prefix: artifact = artifact_prefix + "-" + artifact_suffix return ["maven_coordinates=%s:%s:__VERSION__" % (group, artifact)] else: return [] +def _proto_scala_srcs(name, grpc): + return [":%s" % name] + ([ + "@com_github_googleapis_googleapis//google/rpc:code_proto", + "@com_github_googleapis_googleapis//google/rpc:status_proto", + "@com_github_grpc_grpc//src/proto/grpc/health/v1:health_proto_descriptor", + ] if grpc else []) + +def _proto_scala_deps(grpc, proto_deps): + return [ + "@maven//:com_google_protobuf_protobuf_java", + "@maven//:com_thesamet_scalapb_lenses_2_12", + "@maven//:com_thesamet_scalapb_scalapb_runtime_2_12", + ] + ([ + "@maven//:com_thesamet_scalapb_scalapb_runtime_grpc_2_12", + "@maven//:io_grpc_grpc_api", + "@maven//:io_grpc_grpc_core", + "@maven//:io_grpc_grpc_protobuf", + "@maven//:io_grpc_grpc_stub", + ] if grpc else []) + [ + "%s_scala" % label + for label in proto_deps + ] + def proto_jars( name, srcs, @@ -206,7 +229,7 @@ def proto_jars( deps = None, resources = srcs, resource_strip_prefix = "%s/%s/" % (native.package_name(), strip_import_prefix), - tags = maven_tags(maven_group, maven_artifact_prefix, maven_artifact_proto_suffix), + tags = _maven_tags(maven_group, maven_artifact_prefix, maven_artifact_proto_suffix), visibility = ["//visibility:public"], ) @@ -228,7 +251,7 @@ def proto_jars( # JAR and source JAR containing the generated Java bindings. native.java_proto_library( name = "%s_java" % name, - tags = maven_tags(maven_group, maven_artifact_prefix, maven_artifact_java_suffix), + tags = _maven_tags(maven_group, maven_artifact_prefix, maven_artifact_java_suffix), visibility = ["//visibility:public"], deps = [":%s" % name], ) @@ -236,7 +259,7 @@ def proto_jars( if maven_group and maven_artifact_prefix: pom_file( name = "%s_java_pom" % name, - tags = maven_tags(maven_group, maven_artifact_prefix, maven_artifact_java_suffix), + tags = _maven_tags(maven_group, maven_artifact_prefix, maven_artifact_java_suffix), target = ":%s_java" % name, visibility = ["//visibility:public"], ) @@ -257,30 +280,9 @@ def proto_jars( ) # JAR containing the generated Scala bindings. - all_scala_srcs = [":%s" % name] + ([ - "@com_github_googleapis_googleapis//google/rpc:code_proto", - "@com_github_googleapis_googleapis//google/rpc:status_proto", - "@com_github_grpc_grpc//src/proto/grpc/health/v1:health_proto_descriptor", - ] if grpc else []) - - all_scala_deps = [ - "@maven//:com_google_protobuf_protobuf_java", - "@maven//:com_thesamet_scalapb_lenses_2_12", - "@maven//:com_thesamet_scalapb_scalapb_runtime_2_12", - ] + ([ - "@maven//:com_thesamet_scalapb_scalapb_runtime_grpc_2_12", - "@maven//:io_grpc_grpc_api", - "@maven//:io_grpc_grpc_core", - "@maven//:io_grpc_grpc_protobuf", - "@maven//:io_grpc_grpc_stub", - ] if grpc else []) + [ - "%s_scala" % label - for label in proto_deps - ] - proto_gen( name = "%s_scala_sources" % name, - srcs = all_scala_srcs, + srcs = _proto_scala_srcs(name, grpc), plugin_exec = "//scala-protoc-plugins/scalapb:protoc-gen-scalapb", plugin_name = "scalapb", plugin_options = ["grpc"] if grpc else [], @@ -288,10 +290,12 @@ def proto_jars( deps = deps + proto_deps, ) + all_scala_deps = _proto_scala_deps(grpc, proto_deps) + scala_library( name = "%s_scala" % name, srcs = [":%s_scala_sources" % name], - tags = maven_tags(maven_group, maven_artifact_prefix, maven_artifact_scala_suffix), + tags = _maven_tags(maven_group, maven_artifact_prefix, maven_artifact_scala_suffix), unused_dependency_checker_mode = "error", visibility = ["//visibility:public"], deps = all_scala_deps,