github.com/stackb/rules_proto@v0.0.0-20240221195024-5428336c51f1/pkg/rule/rules_cc/proto_cc_library.go (about) 1 package rules_cc 2 3 import ( 4 "github.com/bazelbuild/bazel-gazelle/rule" 5 6 "github.com/stackb/rules_proto/pkg/protoc" 7 ) 8 9 const ( 10 ProtoCcLibraryRuleName = "proto_cc_library" 11 ProtoCcLibraryRuleSuffix = "_cc_library" 12 ) 13 14 func init() { 15 protoc.Rules().MustRegisterRule("stackb:rules_proto:proto_cc_library", &protoCcLibrary{}) 16 } 17 18 // protoCcLibrary implements LanguageRule for the 'proto_cc_library' rule from 19 // @rules_proto. 20 type protoCcLibrary struct{} 21 22 // Name implements part of the LanguageRule interface. 23 func (s *protoCcLibrary) Name() string { 24 return ProtoCcLibraryRuleName 25 } 26 27 // KindInfo implements part of the LanguageRule interface. 28 func (s *protoCcLibrary) KindInfo() rule.KindInfo { 29 return ccLibraryKindInfo 30 } 31 32 // LoadInfo implements part of the LanguageRule interface. 33 func (s *protoCcLibrary) LoadInfo() rule.LoadInfo { 34 return rule.LoadInfo{ 35 Name: "@build_stack_rules_proto//rules/cc:proto_cc_library.bzl", 36 Symbols: []string{ProtoCcLibraryRuleName}, 37 } 38 } 39 40 // ProvideRule implements part of the LanguageRule interface. 41 func (s *protoCcLibrary) ProvideRule(cfg *protoc.LanguageRuleConfig, pc *protoc.ProtocConfiguration) protoc.RuleProvider { 42 outputs := pc.GetPluginOutputs("builtin:cpp") 43 if len(outputs) == 0 { 44 return nil 45 } 46 return &CcLibrary{ 47 KindName: ProtoCcLibraryRuleName, 48 RuleNameSuffix: ProtoCcLibraryRuleSuffix, 49 Outputs: outputs, 50 RuleConfig: cfg, 51 Config: pc, 52 Resolver: protoc.ResolveDepsAttr("deps", false), 53 } 54 }