github.com/stackb/rules_proto@v0.0.0-20240221195024-5428336c51f1/pkg/plugin/builtin/objc_plugin.go (about) 1 package builtin 2 3 import ( 4 "path" 5 6 "github.com/bazelbuild/bazel-gazelle/label" 7 "github.com/stackb/rules_proto/pkg/protoc" 8 ) 9 10 func init() { 11 protoc.Plugins().MustRegisterPlugin(&ObjcPlugin{}) 12 } 13 14 // ObjcPlugin implements Plugin for the built-in protoc C# plugin. 15 type ObjcPlugin struct{} 16 17 // Name implements part of the Plugin interface. 18 func (p *ObjcPlugin) Name() string { 19 return "builtin:objc" 20 } 21 22 // Configure implements part of the Plugin interface. 23 func (p *ObjcPlugin) Configure(ctx *protoc.PluginContext) *protoc.PluginConfiguration { 24 return &protoc.PluginConfiguration{ 25 Label: label.New("build_stack_rules_proto", "plugin/builtin", "objc"), 26 Outputs: protoc.FlatMapFiles( 27 objcFileName(ctx.Rel, ctx.PluginConfig), 28 protoc.Always, 29 ctx.ProtoLibrary.Files()..., 30 ), 31 Options: ctx.PluginConfig.GetOptions(), 32 } 33 } 34 35 func objcFileName(rel string, cfg protoc.LanguagePluginConfig) func(*protoc.File) []string { 36 return func(f *protoc.File) []string { 37 // setup the file extension 38 base := path.Join(rel, protoc.ToPascalCase(f.Name)) 39 return []string{base + ".pbobjc.h", base + ".pbobjc.m"} 40 } 41 42 }