diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java index 998c8b8e3093e0..e3b2b062e4daf5 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java @@ -106,6 +106,7 @@ import com.google.devtools.build.lib.rules.proto.ProtoConfiguration; import com.google.devtools.build.lib.rules.proto.ProtoInfo; import com.google.devtools.build.lib.rules.proto.ProtoLangToolchainRule; +import com.google.devtools.build.lib.rules.proto.ProtoToolchainRule; import com.google.devtools.build.lib.rules.python.PyInfo; import com.google.devtools.build.lib.rules.python.PyRuleClasses.PySymlink; import com.google.devtools.build.lib.rules.python.PyRuntimeInfo; @@ -291,6 +292,7 @@ public void init(ConfiguredRuleClassProvider.Builder builder) { builder.addConfigurationFragment(new ProtoConfiguration.Loader()); builder.addRuleDefinition(new BazelProtoLibraryRule()); builder.addRuleDefinition(new ProtoLangToolchainRule()); + builder.addRuleDefinition(new ProtoToolchainRule()); ProtoBootstrap bootstrap = new ProtoBootstrap( diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java index 4e28aba2235a60..fbb4a27fe121ba 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java @@ -476,6 +476,8 @@ public void initializeRuleClasses(ConfiguredRuleClassProvider.Builder builder) { ResourceFileLoader.loadResource(BazelRulesModule.class, "xcode_configure.WORKSPACE")); builder.addWorkspaceFileSuffix( ResourceFileLoader.loadResource(BazelShRuleClasses.class, "sh_configure.WORKSPACE")); + builder.addWorkspaceFileSuffix( + ResourceFileLoader.loadResource(BazelRulesModule.class, "proto.WORKSPACE")); } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/proto.WORKSPACE b/src/main/java/com/google/devtools/build/lib/bazel/rules/proto.WORKSPACE new file mode 100644 index 00000000000000..f0ae8f86a08196 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/proto.WORKSPACE @@ -0,0 +1 @@ +register_toolchains("@bazel_tools//tools/proto:toolchain") diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/BUILD b/src/main/java/com/google/devtools/build/lib/rules/proto/BUILD index bd3120d43e52f2..2f6d79fbef9766 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/proto/BUILD +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/BUILD @@ -40,6 +40,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/analysis:rule_definition_environment", "//src/main/java/com/google/devtools/build/lib/analysis:transitive_info_collection", "//src/main/java/com/google/devtools/build/lib/analysis:transitive_info_provider", + "//src/main/java/com/google/devtools/build/lib/analysis/platform", "//src/main/java/com/google/devtools/build/lib/analysis/stringtemplate", "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/collect/nestedset", diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoToolchain.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoToolchain.java new file mode 100644 index 00000000000000..9922ff5fec8a8d --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoToolchain.java @@ -0,0 +1,38 @@ +// Copyright 2020 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.rules.proto; + +import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; +import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; +import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory; +import com.google.devtools.build.lib.analysis.RuleContext; +import com.google.devtools.build.lib.analysis.Runfiles; +import com.google.devtools.build.lib.analysis.RunfilesProvider; + +/** The implementation of the proto_toolchain rule. */ +public class ProtoToolchain implements RuleConfiguredTargetFactory { + @Override + public ConfiguredTarget create(RuleContext ruleContext) + throws ActionConflictException, RuleErrorException, InterruptedException { + ProtoToolchainInfo toolchain = new ProtoToolchainInfo(); + RuleConfiguredTargetBuilder builder = + new RuleConfiguredTargetBuilder(ruleContext) + .addNativeDeclaredProvider(toolchain) + .addProvider(RunfilesProvider.class, RunfilesProvider.simple(Runfiles.EMPTY)); + + return builder.build(); + } +} diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoToolchainInfo.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoToolchainInfo.java new file mode 100644 index 00000000000000..9764929d3f904d --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoToolchainInfo.java @@ -0,0 +1,33 @@ +// Copyright 2020 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.rules.proto; + +import com.google.common.collect.ImmutableMap; +import com.google.devtools.build.lib.analysis.platform.ToolchainInfo; +import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.starlarkbuildapi.proto.ProtoToolchainInfoApi; + +/** + * Information about the tools used by the proto_* and LANG_proto_* rules. + */ +@Immutable +@AutoCodec +public class ProtoToolchainInfo extends ToolchainInfo implements ProtoToolchainInfoApi { + @AutoCodec.Instantiator + public ProtoToolchainInfo() { + super(ImmutableMap.of()); + } +} diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoToolchainRule.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoToolchainRule.java new file mode 100644 index 00000000000000..e1b4e412320cab --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoToolchainRule.java @@ -0,0 +1,40 @@ +// Copyright 2020 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.rules.proto; + +import com.google.devtools.build.lib.analysis.BaseRuleClasses; +import com.google.devtools.build.lib.analysis.RuleDefinition; +import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; +import com.google.devtools.build.lib.packages.RuleClass; + +/** Rule definition of the proto_toolchain rule. */ +public class ProtoToolchainRule implements RuleDefinition { + @Override + public RuleClass build(RuleClass.Builder builder, final RuleDefinitionEnvironment env) { + return builder + .requiresConfigurationFragments(ProtoConfiguration.class) + .advertiseProvider(ProtoToolchainInfo.class) + .build(); + } + + @Override + public Metadata getMetadata() { + return RuleDefinition.Metadata.builder() + .name("proto_toolchain") + .ancestors(BaseRuleClasses.BaseRule.class) + .factoryClass(ProtoToolchain.class) + .build(); + } +} diff --git a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/proto/BUILD b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/proto/BUILD index 96d1179e4c5d26..1c0c6f432bdb39 100644 --- a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/proto/BUILD +++ b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/proto/BUILD @@ -25,6 +25,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/packages/semantics", "//src/main/java/com/google/devtools/build/lib/starlarkbuildapi", "//src/main/java/com/google/devtools/build/lib/starlarkbuildapi/core", + "//src/main/java/com/google/devtools/build/lib/starlarkbuildapi/platform", "//src/main/java/net/starlark/java/annot", "//src/main/java/net/starlark/java/eval", "//third_party:guava", diff --git a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/proto/ProtoToolchainInfoApi.java b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/proto/ProtoToolchainInfoApi.java new file mode 100644 index 00000000000000..7d1ec1efb0be01 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/proto/ProtoToolchainInfoApi.java @@ -0,0 +1,26 @@ +// Copyright 2020 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.starlarkbuildapi.proto; + +import com.google.devtools.build.docgen.annot.DocCategory; +import com.google.devtools.build.lib.starlarkbuildapi.platform.ToolchainInfoApi; +import net.starlark.java.annot.StarlarkBuiltin; + +/** Provides access to information about the Protobuf toolchain rule. */ +@StarlarkBuiltin( + name = "ProtoToolchainInfo", + category = DocCategory.PROVIDER, + doc = "Provides access to information about the Protobuf toolchain rule.") +public interface ProtoToolchainInfoApi extends ToolchainInfoApi {} diff --git a/tools/BUILD b/tools/BUILD index 803dc05fdd8ceb..7bd360bd5c1f28 100644 --- a/tools/BUILD +++ b/tools/BUILD @@ -27,6 +27,7 @@ filegroup( "//tools/test:srcs", "//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:srcs", "//tools/test/CoverageOutputGenerator/javatests/com/google/devtools/coverageoutputgenerator:srcs", + "//tools/proto:srcs", "//tools/python:srcs", "//tools/runfiles:srcs", "//tools/sh:srcs", @@ -56,6 +57,7 @@ filegroup( "//tools/def_parser:srcs", "//tools/platforms:srcs", "//tools/objc:srcs", + "//tools/proto:srcs", "//tools/python:embedded_tools", "//tools/runfiles:embedded_tools", "//tools/test:embedded_tools", diff --git a/tools/proto/BUILD b/tools/proto/BUILD new file mode 100644 index 00000000000000..6e93efc1fd3218 --- /dev/null +++ b/tools/proto/BUILD @@ -0,0 +1,22 @@ +# Copyright 2020 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) # Apache 2.0 + +filegroup( + name = "srcs", + srcs = glob(["**"]), +) diff --git a/tools/proto/BUILD.tools b/tools/proto/BUILD.tools new file mode 100644 index 00000000000000..9b01d0d07868b4 --- /dev/null +++ b/tools/proto/BUILD.tools @@ -0,0 +1,34 @@ +# Copyright 2020 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) # Apache 2.0 + +# The toolchain type used to distinguish proto toolchains. +toolchain_type( + name = "toolchain_type", + visibility = ["//visibility:public"], +) + +# buildifier: disable=native-proto +proto_toolchain( + name = "default_toolchain", +) + +toolchain( + name = "toolchain", + toolchain = ":default_toolchain", + toolchain_type = ":toolchain_type", +)