compiler

package
v1.33.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 3 Imported by: 0

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

func ResolveProtoFileArg(filePath string, importPaths []string) string

ResolveProtoFileArg returns the proto file path that should be passed to protoc as the input argument, expressed relative to the longest matching --proto_path entry. This avoids the "Input is shadowed in the --proto_path" error when the file is reachable via multiple paths (e.g. the file is given as `proto/foo.proto` while `--proto_path=proto` is also passed, making the file also reachable as `foo.proto`).

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

	// 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

type ProtoFile

type ProtoFile struct {
	Path        string   // Absolute path to the proto file
	Package     string   // Proto package name
	ImportPaths []string // Import paths for dependencies
}

ProtoFile represents a protobuf file to compile

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL