Skip to content

Commit

Permalink
[bazel] Move Java runtime/toolchains into //java (#7190)
Browse files Browse the repository at this point in the history
* [bazel] Move Java runtime/toolchains into //java

This change moves `java_library` targets from the top-level BUILD file
into `//java/{core,lite,util}` and declares `alias` targets to point to
their new locations (hence, this is not a breaking change).

This will allow users that don't use Java to stop depending on
`@rules_java` (e.g. as requested in
bazelbuild/rules_scala#989 (comment)).

Note that there is no intention to deprecate + remove the top-level
targets in the foreseeable future.

* Add BUILD files in //java to java_EXTRA_DIST
  • Loading branch information
Yannic authored Feb 13, 2020
1 parent 10c48c9 commit f0cb9cd
Show file tree
Hide file tree
Showing 12 changed files with 295 additions and 177 deletions.
199 changes: 48 additions & 151 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Bazel (https://bazel.build/) BUILD file for Protobuf.

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library", native_cc_proto_library = "cc_proto_library")
load("@rules_java//java:defs.bzl", "java_library")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
load("@rules_proto//proto/private:native.bzl", "native_proto_common")
load("@rules_python//python:defs.bzl", "py_library")
Expand All @@ -11,17 +10,6 @@ licenses(["notice"])

exports_files(["LICENSE"])

################################################################################
# Java 9 configuration
################################################################################

config_setting(
name = "jdk9",
values = {
"java_toolchain": "@bazel_tools//tools/jdk:toolchain_jdk9",
},
)

################################################################################
# ZLIB configuration
################################################################################
Expand Down Expand Up @@ -70,27 +58,43 @@ load(":compiler_config_setting.bzl", "create_compiler_config_setting")
create_compiler_config_setting(
name = "msvc",
value = "msvc-cl",
visibility = [
# Public, but Protobuf only visibility.
"//:__subpackages__",
],
)

config_setting(
name = "android",
values = {
"crosstool_top": "//external:android/crosstool",
},
visibility = [
# Public, but Protobuf only visibility.
"//:__subpackages__",
],
)

config_setting(
name = "android-libcpp",
values = {
"crosstool_top": "@androidndk//:toolchain-libcpp",
},
visibility = [
# Public, but Protobuf only visibility.
"//:__subpackages__",
],
)

config_setting(
name = "android-gnu-libstdcpp",
values = {
"crosstool_top": "@androidndk//:toolchain-gnu-libstdcpp",
},
visibility = [
# Public, but Protobuf only visibility.
"//:__subpackages__",
],
)

# Android and MSVC builds do not need to link in a separate pthread library.
Expand Down Expand Up @@ -653,144 +657,43 @@ cc_test(
################################################################################
# Java support
################################################################################

internal_gen_well_known_protos_java(
srcs = WELL_KNOWN_PROTOS,
name = "gen_well_known_protos_java",
deps = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
visibility = [
"//java:__subpackages__",
],
)

java_library(
alias(
name = "protobuf_java",
srcs = glob([
"java/core/src/main/java/com/google/protobuf/*.java",
]) + [
":gen_well_known_protos_java",
],
javacopts = select({
"//:jdk9": ["--add-modules=jdk.unsupported"],
"//conditions:default": [
"-source 7",
"-target 7",
],
}),
actual = "//java/core",
visibility = ["//visibility:public"],
)

java_library(
alias(
name = "protobuf_javalite",
srcs = [
# Keep in sync with java/lite/pom.xml
"java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java",
"java/core/src/main/java/com/google/protobuf/AbstractParser.java",
"java/core/src/main/java/com/google/protobuf/AbstractProtobufList.java",
"java/core/src/main/java/com/google/protobuf/AllocatedBuffer.java",
"java/core/src/main/java/com/google/protobuf/Android.java",
"java/core/src/main/java/com/google/protobuf/ArrayDecoders.java",
"java/core/src/main/java/com/google/protobuf/BinaryReader.java",
"java/core/src/main/java/com/google/protobuf/BinaryWriter.java",
"java/core/src/main/java/com/google/protobuf/BooleanArrayList.java",
"java/core/src/main/java/com/google/protobuf/BufferAllocator.java",
"java/core/src/main/java/com/google/protobuf/ByteBufferWriter.java",
"java/core/src/main/java/com/google/protobuf/ByteOutput.java",
"java/core/src/main/java/com/google/protobuf/ByteString.java",
"java/core/src/main/java/com/google/protobuf/CodedInputStream.java",
"java/core/src/main/java/com/google/protobuf/CodedInputStreamReader.java",
"java/core/src/main/java/com/google/protobuf/CodedOutputStream.java",
"java/core/src/main/java/com/google/protobuf/CodedOutputStreamWriter.java",
"java/core/src/main/java/com/google/protobuf/DoubleArrayList.java",
"java/core/src/main/java/com/google/protobuf/ExperimentalApi.java",
"java/core/src/main/java/com/google/protobuf/ExtensionLite.java",
"java/core/src/main/java/com/google/protobuf/ExtensionRegistryFactory.java",
"java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java",
"java/core/src/main/java/com/google/protobuf/ExtensionSchema.java",
"java/core/src/main/java/com/google/protobuf/ExtensionSchemaLite.java",
"java/core/src/main/java/com/google/protobuf/ExtensionSchemas.java",
"java/core/src/main/java/com/google/protobuf/FieldInfo.java",
"java/core/src/main/java/com/google/protobuf/FieldSet.java",
"java/core/src/main/java/com/google/protobuf/FieldType.java",
"java/core/src/main/java/com/google/protobuf/FloatArrayList.java",
"java/core/src/main/java/com/google/protobuf/GeneratedMessageInfoFactory.java",
"java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java",
"java/core/src/main/java/com/google/protobuf/IntArrayList.java",
"java/core/src/main/java/com/google/protobuf/Internal.java",
"java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java",
"java/core/src/main/java/com/google/protobuf/IterableByteBufferInputStream.java",
"java/core/src/main/java/com/google/protobuf/JavaType.java",
"java/core/src/main/java/com/google/protobuf/LazyField.java",
"java/core/src/main/java/com/google/protobuf/LazyFieldLite.java",
"java/core/src/main/java/com/google/protobuf/LazyStringArrayList.java",
"java/core/src/main/java/com/google/protobuf/LazyStringList.java",
"java/core/src/main/java/com/google/protobuf/ListFieldSchema.java",
"java/core/src/main/java/com/google/protobuf/LongArrayList.java",
"java/core/src/main/java/com/google/protobuf/ManifestSchemaFactory.java",
"java/core/src/main/java/com/google/protobuf/MapEntryLite.java",
"java/core/src/main/java/com/google/protobuf/MapFieldLite.java",
"java/core/src/main/java/com/google/protobuf/MapFieldSchema.java",
"java/core/src/main/java/com/google/protobuf/MapFieldSchemaLite.java",
"java/core/src/main/java/com/google/protobuf/MapFieldSchemas.java",
"java/core/src/main/java/com/google/protobuf/MessageInfo.java",
"java/core/src/main/java/com/google/protobuf/MessageInfoFactory.java",
"java/core/src/main/java/com/google/protobuf/MessageLite.java",
"java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java",
"java/core/src/main/java/com/google/protobuf/MessageLiteToString.java",
"java/core/src/main/java/com/google/protobuf/MessageSchema.java",
"java/core/src/main/java/com/google/protobuf/MessageSetSchema.java",
"java/core/src/main/java/com/google/protobuf/MutabilityOracle.java",
"java/core/src/main/java/com/google/protobuf/NewInstanceSchema.java",
"java/core/src/main/java/com/google/protobuf/NewInstanceSchemaLite.java",
"java/core/src/main/java/com/google/protobuf/NewInstanceSchemas.java",
"java/core/src/main/java/com/google/protobuf/NioByteString.java",
"java/core/src/main/java/com/google/protobuf/OneofInfo.java",
"java/core/src/main/java/com/google/protobuf/Parser.java",
"java/core/src/main/java/com/google/protobuf/PrimitiveNonBoxingCollection.java",
"java/core/src/main/java/com/google/protobuf/ProtoSyntax.java",
"java/core/src/main/java/com/google/protobuf/Protobuf.java",
"java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java",
"java/core/src/main/java/com/google/protobuf/ProtobufLists.java",
"java/core/src/main/java/com/google/protobuf/ProtocolStringList.java",
"java/core/src/main/java/com/google/protobuf/RawMessageInfo.java",
"java/core/src/main/java/com/google/protobuf/Reader.java",
"java/core/src/main/java/com/google/protobuf/RopeByteString.java",
"java/core/src/main/java/com/google/protobuf/Schema.java",
"java/core/src/main/java/com/google/protobuf/SchemaFactory.java",
"java/core/src/main/java/com/google/protobuf/SchemaUtil.java",
"java/core/src/main/java/com/google/protobuf/SmallSortedMap.java",
"java/core/src/main/java/com/google/protobuf/StructuralMessageInfo.java",
"java/core/src/main/java/com/google/protobuf/TextFormatEscaper.java",
"java/core/src/main/java/com/google/protobuf/UninitializedMessageException.java",
"java/core/src/main/java/com/google/protobuf/UnknownFieldSchema.java",
"java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java",
"java/core/src/main/java/com/google/protobuf/UnknownFieldSetLiteSchema.java",
"java/core/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java",
"java/core/src/main/java/com/google/protobuf/UnsafeUtil.java",
"java/core/src/main/java/com/google/protobuf/Utf8.java",
"java/core/src/main/java/com/google/protobuf/WireFormat.java",
"java/core/src/main/java/com/google/protobuf/Writer.java",
],
javacopts = select({
"//:jdk9": ["--add-modules=jdk.unsupported"],
"//conditions:default": [
"-source 7",
"-target 7",
],
}),
actual = "//java/lite",
visibility = ["//visibility:public"],
)

java_library(
alias(
name = "protobuf_java_util",
srcs = glob([
"java/util/src/main/java/com/google/protobuf/util/*.java",
]),
javacopts = [
"-source 7",
"-target 7",
],
actual = "//java/util",
visibility = ["//visibility:public"],
)

alias(
name = "java_toolchain",
actual = "//java/core:toolchain",
visibility = ["//visibility:public"],
)

alias(
name = "javalite_toolchain",
actual = "//java/lite:toolchain",
visibility = ["//visibility:public"],
deps = [
"protobuf_java",
"//external:error_prone_annotations",
"//external:gson",
"//external:guava",
],
)

################################################################################
Expand Down Expand Up @@ -859,13 +762,21 @@ config_setting(
values = {
"define": "use_fast_cpp_protos=true",
},
visibility = [
# Public, but Protobuf only visibility.
"//:__subpackages__",
],
)

config_setting(
name = "allow_oversize_protos",
values = {
"define": "allow_oversize_protos=true",
},
visibility = [
# Public, but Protobuf only visibility.
"//:__subpackages__",
],
)

# Copy the builtin proto files from src/google/protobuf to
Expand Down Expand Up @@ -1011,20 +922,6 @@ proto_lang_toolchain(
visibility = ["//visibility:public"],
)

proto_lang_toolchain(
name = "java_toolchain",
command_line = "--java_out=$(OUT)",
runtime = ":protobuf_java",
visibility = ["//visibility:public"],
)

proto_lang_toolchain(
name = "javalite_toolchain",
command_line = "--java_out=lite:$(OUT)",
runtime = ":protobuf_javalite",
visibility = ["//visibility:public"],
)

alias(
name = "objectivec",
actual = ":protobuf_objc",
Expand Down
8 changes: 7 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,10 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf/UnknownFieldSet.cs

java_EXTRA_DIST= \
java/BUILD \
java/README.md \
java/bom/pom.xml \
java/core/BUILD \
java/core/generate-sources-build.xml \
java/core/generate-test-sources-build.xml \
java/core/pom.xml \
Expand Down Expand Up @@ -504,6 +506,7 @@ java_EXTRA_DIST=
java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto \
java/core/src/test/proto/com/google/protobuf/wrappers_test.proto \
java/lite.md \
java/lite/BUILD \
java/lite/generate-sources-build.xml \
java/lite/generate-test-sources-build.xml \
java/lite/lite.awk \
Expand All @@ -512,6 +515,7 @@ java_EXTRA_DIST=
java/lite/src/test/java/com/google/protobuf/LiteTest.java \
java/lite/src/test/java/com/google/protobuf/Proto2MessageLiteInfoFactory.java \
java/pom.xml \
java/util/BUILD \
java/util/pom.xml \
java/util/src/main/java/com/google/protobuf/util/Durations.java \
java/util/src/main/java/com/google/protobuf/util/FieldMaskTree.java \
Expand Down Expand Up @@ -1298,7 +1302,7 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \
WORKSPACE \
cmake/CMakeLists.txt \
cmake/README.md \
cmake/conformance.cmake \
cmake/conformance.cmake \
cmake/examples.cmake \
cmake/extract_includes.bat.in \
cmake/install.cmake \
Expand All @@ -1315,6 +1319,8 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \
cmake/tests.cmake \
cmake/version.rc.in \
compiler_config_setting.bzl \
build_files_updated_unittest.sh \
cc_proto_blacklist_test.bzl \
editors/README.txt \
editors/proto.vim \
editors/protobuf-mode.el \
Expand Down
4 changes: 3 additions & 1 deletion compiler_config_setting.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Creates config_setting that allows selecting based on 'compiler' value."""

def create_compiler_config_setting(name, value):
def create_compiler_config_setting(name, value, visibility = None):
# The "do_not_use_tools_cpp_compiler_present" attribute exists to
# distinguish between older versions of Bazel that do not support
# "@bazel_tools//tools/cpp:compiler" flag_value, and newer ones that do.
Expand All @@ -13,9 +13,11 @@ def create_compiler_config_setting(name, value):
flag_values = {
"@bazel_tools//tools/cpp:compiler": value,
},
visibility = visibility,
)
else:
native.config_setting(
name = name,
values = {"compiler": value},
visibility = visibility,
)
2 changes: 2 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore the bazel symlinks
/bazel-*
9 changes: 9 additions & 0 deletions java/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
config_setting(
name = "jdk9",
values = {
"java_toolchain": "@bazel_tools//tools/jdk:toolchain_jdk9",
},
visibility = [
"//java:__subpackages__",
],
)
Loading

0 comments on commit f0cb9cd

Please sign in to comment.