Documentation
¶
Overview ¶
Package compiler defines the common interface for language-specific compilers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MergeImportPaths ¶ added in v1.0.0
func MergeImportPaths(opts CompileOptions, file ProtoFile) []string
MergeImportPaths merges import paths from options and file, removing duplicates
func ResolveProtoFileArg ¶ added in v1.33.6
ResolveProtoFileArg returns the proto file path that should be passed to protoc as the input argument, expressed relative to the first matching --proto_path entry. Matching protoc's import path order is important because the resolved input name becomes the FileDescriptorProto name embedded in generated code; choosing a later, narrower root can make generated files register a different descriptor name than dependent protos import.
If no import path is a prefix of filePath, filePath is returned unchanged.
Types ¶
type CompileOptions ¶
type CompileOptions struct {
// OutputDir is the directory where generated files will be placed
OutputDir string
// ImportPaths are additional import paths for proto files
ImportPaths []string
// ProtoPaths are source roots scanned for project proto files.
// They are distinct from import-only paths and may be stripped from generated
// Python module imports when PreserveProtoStructure is enabled.
ProtoPaths []string
// Plugins are additional plugins to use (e.g., "grpc")
Plugins []string
// CustomOptions are compiler-specific options
CustomOptions map[string]string
// Verbose enables detailed logging
Verbose bool
// PreserveProtoStructure preserves the proto directory structure in output
PreserveProtoStructure bool
// ProjectDir is the project root directory used for calculating relative paths.
// If empty, os.Getwd() is used as fallback.
ProjectDir string
}
CompileOptions contains options for compilation
type CompileResult ¶
type CompileResult struct {
// GeneratedFiles are the paths to generated files
GeneratedFiles []string
// Warnings are non-fatal issues encountered during compilation
Warnings []string
// Success indicates whether compilation was successful
Success bool
}
CompileResult contains the results of compilation
type Compiler ¶
type Compiler interface {
// Name returns the name of the compiler (e.g., "python", "go", "rust")
Name() string
// Compile compiles the given proto files
Compile(ctx context.Context, files []ProtoFile, opts CompileOptions) (*CompileResult, error)
// Validate checks if the compiler is properly configured and available
Validate() error
// GetOutputPath returns the output path for the given proto file
GetOutputPath(protoFile ProtoFile, opts CompileOptions) string
// RequiredTools returns a list of external tools required by this compiler
RequiredTools() []string
}
Compiler is the interface that all language-specific compilers must implement
Directories
¶
| Path | Synopsis |
|---|---|
|
Package python implements the Python protobuf compiler.
|
Package python implements the Python protobuf compiler. |
|
Package typescript implements the TypeScript protobuf compiler.
|
Package typescript implements the TypeScript protobuf compiler. |