Skip to content

Commit

Permalink
Use standard bazel proto toolchain
Browse files Browse the repository at this point in the history
This CL switches rules_closure to use Bazel's built-in
java_proto_library rule instead of a custom Skylark rule. It also
switches the protoc binary to the standard
@com_google_protobuf//:protoc instead of a custom-downloaded
dependency.

This CL is a port that fixes bazelbuild#231 and bazelbuild#232.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177367734
  • Loading branch information
Brendan Linn authored and ptmphuong committed Dec 9, 2022
1 parent ae0c4a5 commit a228504
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 168 deletions.
81 changes: 0 additions & 81 deletions closure/private/java_proto_library.bzl

This file was deleted.

1 change: 0 additions & 1 deletion closure/protobuf/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ closure_js_library(
"JSC_NULLABLE_RETURN_WITH_NAME",
"JSC_OPTIONAL_PARAM_NOT_MARKED_OPTIONAL",
"JSC_UNKNOWN_EXPR_TYPE",
"strictMissingRequire",
],
deps = ["//closure/library"],
)
2 changes: 1 addition & 1 deletion closure/protobuf/closure_js_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def closure_js_proto_library(
testonly = None,
binary = 1,
import_style = None,
protocbin = Label("@com_google_protobuf_protoc"),
protocbin = Label("@com_google_protobuf//:protoc"),
**kwargs):
cmd = ["$(location %s)" % protocbin]
js_out_options = ["library=%s,error_on_name_conflict" % name]
Expand Down
97 changes: 28 additions & 69 deletions closure/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def closure_repositories(
omit_com_google_javascript_closure_library=False,
omit_com_google_javascript_incremental_dom=False,
omit_com_google_jsinterop_annotations=False,
omit_com_google_protobuf=False,
omit_com_google_protobuf_java=False,
omit_com_google_protobuf_js=False,
omit_com_google_protobuf_protoc=False,
omit_com_google_template_soy=False,
omit_com_google_template_soy_jssrc=False,
omit_com_ibm_icu_icu4j=False,
Expand Down Expand Up @@ -113,12 +113,12 @@ def closure_repositories(
com_google_javascript_incremental_dom()
if not omit_com_google_jsinterop_annotations:
com_google_jsinterop_annotations()
if not omit_com_google_protobuf:
com_google_protobuf()
if not omit_com_google_protobuf_java:
com_google_protobuf_java()
if not omit_com_google_protobuf_js:
com_google_protobuf_js()
if not omit_com_google_protobuf_protoc:
com_google_protobuf_protoc()
if not omit_com_google_template_soy:
com_google_template_soy()
if not omit_com_google_template_soy_jssrc:
Expand Down Expand Up @@ -401,7 +401,7 @@ def com_google_common_html_types():
"@com_google_errorprone_error_prone_annotations",
"@com_google_guava",
"@com_google_jsinterop_annotations",
"@com_google_protobuf_java",
"@com_google_protobuf_java//:protobuf_java",
"@javax_annotation_jsr250_api",
],
)
Expand Down Expand Up @@ -589,7 +589,7 @@ def com_google_javascript_closure_compiler():
"@com_google_code_gson",
"@com_google_guava",
"@com_google_code_findbugs_jsr305",
"@com_google_protobuf_java",
"@com_google_protobuf_java//:protobuf_java",
],
extra_build_file_content = "\n".join([
"java_binary(",
Expand Down Expand Up @@ -645,81 +645,40 @@ def com_google_jsinterop_annotations():
],
)

def com_google_protobuf():
native.http_archive(
name = "com_google_protobuf",
strip_prefix = "protobuf-3.5.0",
sha256 = "0cc6607e2daa675101e9b7398a436f09167dffb8ca0489b0307ff7260498c13c",
urls = [
"https://mirror.bazel.build/github.com/google/protobuf/archive/v3.5.0.tar.gz",
"https://github.com/google/protobuf/archive/v3.5.0.tar.gz",
],
)

def com_google_protobuf_java():
java_import_external(
native.http_archive(
name = "com_google_protobuf_java",
jar_sha256 = "f3411ade77523d5f0d013d4f25c36879e66f0c5e1e4310f7096d54d0d2553554",
jar_urls = [
"https://mirror.bazel.build/repo1.maven.org/maven2/com/google/protobuf/protobuf-java/3.3.0/protobuf-java-3.3.0.jar",
"https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java/3.3.0/protobuf-java-3.3.0.jar",
sha256 = "0cc6607e2daa675101e9b7398a436f09167dffb8ca0489b0307ff7260498c13c",
strip_prefix = "protobuf-3.5.0",
urls = [
"https://mirror.bazel.build/github.com/google/protobuf/archive/v3.5.0.tar.gz",
"https://github.com/google/protobuf/archive/v3.5.0.tar.gz",
],
licenses = ["notice"], # New BSD and Apache 2.0
)

def com_google_protobuf_js():
native.new_http_archive(
name = "com_google_protobuf_js",
urls = [
# 3.3.0 has a Closure Compiler bug because it references Node's Buffer
# type. This was fixed in f00e06c95bc117fb2ed0ca56c96041c93039f1fe.
#
# TODO(jart): Update when https://github.com/google/protobuf/pull/3387
# is merged.
"https://mirror.bazel.build/github.com/google/protobuf/archive/33545583286a31940b6a732b1888e639cdf2e3c4.tar.gz",
"https://github.com/google/protobuf/archive/33545583286a31940b6a732b1888e639cdf2e3c4.tar.gz", # 2017-07-17
],
sha256 = "ecd9f92f137e75d140a8b611cd2c0d6c0f34f561946dc5f7fcecde631bb13c25",
strip_prefix = "protobuf-33545583286a31940b6a732b1888e639cdf2e3c4/js",
"https://mirror.bazel.build/github.com/google/protobuf/archive/v3.5.0.tar.gz",
"https://github.com/google/protobuf/archive/v3.5.0.tar.gz",
],
sha256 = "0cc6607e2daa675101e9b7398a436f09167dffb8ca0489b0307ff7260498c13c",
strip_prefix = "protobuf-3.5.0/js",
build_file = str(Label("//closure/protobuf:protobuf_js.BUILD")),
)

def com_google_protobuf_protoc():
filegroup_external(
name = "com_google_protobuf_protoc",
licenses = ["notice"], # BSD
sha256_urls_extract_macos = {
"d752ba0ea67239e327a48b2f23da0e673928a9ff06ee530319fc62200c0aff89": [
"https://mirror.bazel.build/github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-osx-x86_64.zip",
"https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-osx-x86_64.zip",
],
},
sha256_urls_extract_windows = {
"19ec3d3853c1181912dc442840b3a76bfe0607ecc67d0854b323fdd1fdd8ab77": [
"https://mirror.bazel.build/github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-win32.zip",
"https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-win32.zip",
],
},
sha256_urls_extract = {
"feb112bbc11ea4e2f7ef89a359b5e1c04428ba6cfa5ee628c410eccbfe0b64c3": [
"https://mirror.bazel.build/github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-linux-x86_64.zip",
"https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-linux-x86_64.zip",
],
},
generated_rule_name = "files",
extra_build_file_content = "\n".join([
"filegroup(",
" name = \"com_google_protobuf_protoc\",",
" srcs = select({",
" \":windows\": [\"bin/protoc.exe\"],",
" \":windows_msvc\": [\"bin/protoc.exe\"],",
" \"//conditions:default\": [\"bin/protoc\"],",
" }),",
")",
"",
"config_setting(",
" name = \"windows\",",
" values = {\"cpu\": \"x64_windows\"},",
" visibility = [\"//visibility:private\"],",
")",
"",
"config_setting(",
" name = \"windows_msvc\",",
" values = {\"cpu\": \"x64_windows_msvc\"},",
" visibility = [\"//visibility:private\"],",
")",
]),
)

def com_google_template_soy():
java_import_external(
name = "com_google_template_soy",
Expand All @@ -738,7 +697,7 @@ def com_google_template_soy():
"@com_google_inject_extensions_guice_assistedinject",
"@com_google_inject_extensions_guice_multibindings",
"@com_google_inject_guice",
"@com_google_protobuf_java",
"@com_google_protobuf_java//:protobuf_java",
"@com_ibm_icu_icu4j",
"@javax_inject",
"@org_json",
Expand Down
2 changes: 1 addition & 1 deletion java/com/google/javascript/jscomp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ java_library(
"@com_google_dagger",
"@com_google_guava",
"@com_google_javascript_closure_compiler",
"@com_google_protobuf_java",
"@com_google_protobuf_java//:protobuf_java",
],
)
9 changes: 6 additions & 3 deletions java/io/bazel/rules/closure/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("//closure/private:java_proto_library.bzl", "java_proto_library")

licenses(["notice"]) # Apache 2.0

java_binary(
Expand Down Expand Up @@ -59,8 +57,13 @@ java_library(
],
)

proto_library(
name = "build_info_proto",
srcs = ["build_info.proto"],
)

java_proto_library(
name = "build_info_java_proto",
src = "build_info.proto",
visibility = ["//visibility:public"],
deps = [":build_info_proto"],
)
11 changes: 7 additions & 4 deletions java/io/bazel/rules/closure/webfiles/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("//closure/private:java_proto_library.bzl", "java_proto_library")

licenses(["notice"]) # Apache 2.0

java_library(
Expand All @@ -31,14 +29,19 @@ java_library(
"@com_google_code_findbugs_jsr305",
"@com_google_dagger",
"@com_google_guava",
"@com_google_protobuf_java",
"@com_google_protobuf_java//:protobuf_java",
"@javax_inject",
"@org_jsoup",
],
)

proto_library(
name = "build_info_proto",
srcs = ["build_info.proto"],
)

java_proto_library(
name = "build_info_java_proto",
src = "build_info.proto",
visibility = ["//visibility:public"],
deps = [":build_info_proto"],
)
10 changes: 7 additions & 3 deletions java/io/bazel/rules/closure/webfiles/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

load("//closure:defs.bzl", "closure_java_template_library")
load("//closure/private:java_proto_library.bzl", "java_proto_library")

licenses(["notice"]) # Apache 2.0

Expand All @@ -32,7 +31,7 @@ java_library(
"@com_google_code_findbugs_jsr305",
"@com_google_dagger",
"@com_google_guava",
"@com_google_protobuf_java",
"@com_google_protobuf_java//:protobuf_java",
"@com_google_template_soy",
],
)
Expand All @@ -44,10 +43,15 @@ java_binary(
runtime_deps = [":server"],
)

proto_library(
name = "build_info_proto",
srcs = ["build_info.proto"],
)

java_proto_library(
name = "build_info_java_proto",
src = "build_info.proto",
visibility = ["//visibility:public"],
deps = [":build_info_proto"],
)

closure_java_template_library(
Expand Down
11 changes: 7 additions & 4 deletions java/io/bazel/rules/closure/worker/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("//closure/private:java_proto_library.bzl", "java_proto_library")

licenses(["notice"]) # Apache 2.0

java_library(
Expand All @@ -31,12 +29,17 @@ java_library(
"@com_google_code_findbugs_jsr305",
"@com_google_dagger",
"@com_google_guava",
"@com_google_protobuf_java",
"@com_google_protobuf_java//:protobuf_java",
],
)

proto_library(
name = "worker_protocol_proto",
srcs = ["worker_protocol.proto"],
)

java_proto_library(
name = "worker_protocol_java_proto",
src = "worker_protocol.proto",
visibility = ["//javatests/io/bazel/rules/closure/worker:__pkg__"],
deps = [":worker_protocol_proto"],
)
2 changes: 1 addition & 1 deletion javatests/io/bazel/rules/closure/worker/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ java_test(
"@com_google_dagger",
"@com_google_guava",
"@com_google_jimfs",
"@com_google_protobuf_java",
"@com_google_protobuf_java//:protobuf_java",
"@com_google_truth",
"@junit",
"@org_mockito_all",
Expand Down

0 comments on commit a228504

Please sign in to comment.