// Copyright 2016 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.cpp.proto; import static com.google.devtools.build.lib.packages.Attribute.attr; import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; 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; /** Declaration part of cc_proto_library. */ public class CcProtoLibraryRule implements RuleDefinition { private final CcProtoAspect ccProtoAspect; public CcProtoLibraryRule(CcProtoAspect ccProtoAspect) { this.ccProtoAspect = ccProtoAspect; } @Override public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment environment) { return builder /* The list of proto_library rules to generate C++ code for. */ .override( attr("deps", LABEL_LIST) .allowedRuleClasses("proto_library") .allowedFileTypes() .aspect(ccProtoAspect)) .build(); } @Override public Metadata getMetadata() { return RuleDefinition.Metadata.builder() .name("cc_proto_library") .factoryClass(CcProtoLibrary.class) .ancestors(BaseRuleClasses.RuleBase.class) .build(); } } /*

cc_proto_library generates C++ code from .proto files.

deps must point to proto_library rules.

Example:

cc_library(
    name = "lib",
    deps = [":foo_cc_proto"],
)

cc_proto_library(
    name = "foo_cc_proto",
    deps = [":foo_proto"],
)

proto_library(
    name = "foo_proto",
)
*/