Help us shape the future of Go! Take the 2026 Go Developer Survey

cl

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DbgFlagCompileDecl = 1 << iota
	DbgFlagMajorProc
	DbgFlagQuietIgnore
	DbgFlagAll = DbgFlagCompileDecl | DbgFlagMajorProc | DbgFlagQuietIgnore
)
View Source
const (
	QuietIgnore = featQuietIgnore
)

Variables

View Source
var (
	InlineFuncIgnore = featExplicitIgnore
	NoManglingIgnore = featExplicitIgnore
)

Functions

func PubFile added in v0.11.0

func PubFile(entries []Entry) []byte

PubFile generates the byte representation of the public entries, sorted by their serialized lines.

func SetDebug

func SetDebug(flags int)

Types

type Config

type Config struct {
	// Fset provides source position information for syntax trees and types (optional).
	// If Fset is nil, Load will use a new fileset, but preserve Fset's value.
	Fset *token.FileSet

	// An Importer resolves import paths to Packages (optional).
	Importer types.Importer

	// LLGoPackage specifies the value of the LLGoPackage constant in the generated
	// Go package (optional).
	LLGoPackage string

	// GoFiles provides the Go source files by filename, mixing hand-written and generated
	// Go code (optional). See https://github.com/xgo-dev/llcppg/issues/1100.
	GoFiles map[string]*ast.File

	// Language specifies the programming language of the header file (default LanguageC).
	Language Language

	// CFlags specifies the compiler flags to be used when compiling the wrapper file.
	// If not specified, llcppg will skip wrapping inline functions/methods.
	CFlags string

	// WrapFileHeader specifies the header content to be included at the top of the generated
	// wrapper file (optional).
	WrapFileHeader string

	// PackageOf returns the package path for a given header file. If ok is false, it means
	// we don't know the package path for the header file. If not specified, llcppg will
	// assume all header files belong to the same package.
	PackageOf func(headerFile string) (pkgPath string, ok bool)

	// PubFileLookup looks up the public file for a given package path. A public file is
	// a text file that contains a list of public C/C++ names and their corresponding Go
	// names (required).
	PubFileLookup func(pkgPath string) (pubFile string, ok bool)

	// NameLookup looks up the archive path for a given mangling name. It returns the
	// archive path and a boolean indicating whether the lookup was successful. If not
	// specified, llcppg uses a default lookup function that returns an empty archivePath
	// and true (it means any mangling name is considered found).
	NameLookup func(manglingName string) (archivePath string, ok bool)

	// Rename specifies a mapping of C/C++ names to Go names (optional). If a name is present
	// in the map, it will be renamed to the corresponding Go name.
	Rename map[string]string

	// NSIgnore specifies a list of C/C++ namespaces to be ignored (optional).
	NSIgnore []string

	// MacroIgnore specifies a list of C/C++ macro names to be ignored (optional).
	MacroIgnore []string

	// MacroFunc maps a function-like C macro name to the name of a reference
	// function declared in the processed headers (optional). Each listed macro is
	// wrapped as a function the same way static inline functions are: llcppg emits
	// a C wrapper whose body invokes the macro, and a Go declaration linking to it.
	// The reference function supplies the wrapper's return type and the parameter
	// types (matched to the macro's parameters by name, then by position).
	// See https://github.com/xgo-dev/llcppg/issues/1051.
	MacroFunc map[string]string

	// MacroGroup declares groups of related constant macros that are emitted
	// together as a single Go `const ( ... )` block (optional). It maps the
	// first macro of a group to its last macro; every macro definition between
	// them in source order (inclusive) belongs to the group, regardless of blank
	// lines or comments. Names are the original C macro names, before MacroPrefix
	// stripping or renaming. The first and last macro must live in the same
	// header file: a range that crosses a header boundary is a configuration
	// error. Configured groups take priority over automatic detection, which
	// groups runs of adjacent constant macros of the same type.
	// See https://github.com/xgo-dev/llcppg/issues/1064.
	MacroGroup map[string]string

	// TypeIgnore specifies a list of C/C++ type names to be ignored (optional).
	TypeIgnore []string

	// FuncIgnore specifies a list of C/C++ function names to be ignored (optional).
	FuncIgnore []string

	// FieldAlias overrides the Go name and type of C/C++ fields (optional).
	// See https://github.com/xgo-dev/llcppg/issues/1019.
	FieldAlias map[string]string

	// TypeDef is an object whose keys are file names and whose values are arrays of type
	// definitions (optional). It defines Go types that should exist in the generated
	// package but is missing from the C/C++ headers.
	// See https://github.com/xgo-dev/llcppg/issues/1079.
	TypeDef map[string][]TypeDef

	// TypeAlias specifies a mapping of C/C++ type names to a Go type name (alias) in
	// pkgPath.Name format (pkgPath can be empty if Name is in current package), optional.
	//
	// alias = "void (ignore this type, as an empty class)"
	// alias = ".StdBasicString[byte, c.Void, c.Void]"
	// alias = ".Iterator"
	// alias = "[_Derived, _Category, _Tp, _Distance, _Pointer, _Reference] = .Iterator[_Category, _Tp, _Distance, _Pointer, _Reference]"
	//
	// See https://github.com/xgo-dev/llcppg/issues/929.
	TypeAlias map[string]string

	// TypeAbbr specifies abbreviated name for Go type names and will be used in function
	// names (optional). See https://github.com/xgo-dev/llcppg/issues/958.
	TypeAbbr []string

	// TypePrefix/TypeSuffix specifies the prefix/suffix to remove from C/C++ type names
	// when generating Go type names (optional).
	TypePrefix, TypeSuffix []string

	// MethodPrefix specifies a literal prefix to remove from the names of methods associated
	// with a Go type (optional). The key is the Go type name and the value is the prefix in
	// the original C/C++ function name. See https://github.com/xgo-dev/llcppg/issues/1061.
	MethodPrefix map[string]string

	// EnumPrefix specifies the prefix to remove from C/C++ enum value names when generating
	// Go const names (optional).
	EnumPrefix []string

	// MacroPrefix specifies the prefix to remove from C/C++ macro names when generating
	// Go const names (optional).
	MacroPrefix []string

	// Type Creator Detection (optional). See https://github.com/xgo-dev/llcppg/issues/960.
	NewCheck []string

	// Type Method Detection (optional). See https://github.com/xgo-dev/llcppg/issues/955.
	MethodCheck []string

	// FuncPrefix specifies the prefix to remove from C/C++ global function names when
	// generating Go function names (optional).
	FuncPrefix []string

	// VarPrefix specifies the prefix to remove from C/C++ global variable names when
	// generating Go variable names (optional).
	VarPrefix []string

	// NSPrefix specifies the prefix to remove from C/C++ namespace names when generating
	// Go package names (optional).
	NSPrefix []string

	// Class specifies a list of C/C++ typedef names to be treated as classes (optional).
	Class []string

	// 1) for typedef: NonClass specifies a list of C/C++ typedef names to be treated
	//    as non-classes.
	// 2) for global function to method: NonClass specifies a list of Go type names to
	//    be treated as non-classes.
	NonClass []string

	// DefaultGoFile specifies default file name (optional).
	DefaultGoFile string

	// Define specifies user constants to inject into the generated package (optional).
	// See https://github.com/xgo-dev/llcppg/issues/1067.
	Define []ConstDef

	// GoFileOf returns the Go file name for a given header file (optional). If ok is false,
	// it means we don't know the Go file name for the header file and this header file will
	// be skipped. If not specified, llcppg will use the default Go file name (DefaultGoFile)
	// for all header files.
	GoFileOf func(headerFile string) (string, bool)

	// FailFast specifies whether to fail fast on errors (optional). If FailFast is non-zero,
	// llcppg will stop after printing errors `FailFast` times.
	FailFast int

	// EnumAlwaysUntyped specifies whether all enums should be treated as untyped (optional).
	// See https://github.com/xgo-dev/llcppg/issues/1103.
	EnumAlwaysUntyped bool

	// ForceCamelCase converts capitalized, underscore-joined names to camel case (optional),
	// except names whose final segment is all-uppercase (acronyms/macros), which are kept
	// as-is.
	ForceCamelCase bool

	// LoadLibcPubFile specifies whether to load the pubFile for libc package (optional).
	LoadLibcPubFile bool

	// UseStdRecvName specifies whether to use a standard receiver name (self) for C functions
	// converted to Go methods (optional). If false, the receiver name is taken from the first
	// parameter name. This option does not affect C++ instance methods, whose receiver is
	// always named this.
	UseStdRecvName bool
}

Config specifies the configuration for llcppg.

type ConstDef added in v0.13.0

type ConstDef struct {
	Name  string
	Value any
}

ConstDef represents a user constant to be injected into the generated package. See https://github.com/xgo-dev/llcppg/issues/1067.

type Entry added in v0.9.0

type Entry struct {
	Name   string
	GoName string    // optional; omitted names use externName, independent of llcppg.cfg
	Kind   entryKind // 'T' (type), 'f' (func), 'v' (var), 'D' (dependency)
}

Entry represents a C/C++ name and its corresponding Go name.

type Language added in v0.9.0

type Language int

Language specifies the programming language of the header file.

const (
	LanguageC Language = iota
	LanguageCXX
)

type Package

type Package struct {
	*gogen.Package
	Wrap   *WrapFile
	Public []Entry // public entries
}

Package represents a generated Go package from a C/C++ library.

func NewPackage

func NewPackage(pkgPath, pkgName string, files []Source, conf *Config) (ret Package, err error)

NewPackage loads translation units and generates a Go package with the given package path, name and configuration.

type Source added in v0.9.0

type Source = clang.TranslationUnit

Source represents a source file to be processed by llcppg.

type TypeDef added in v0.13.0

type TypeDef struct {
	// Name is the name of the type being defined.
	Name string

	// Fields lists the fields of the type being defined. Each entry in Fields is
	// either an embedded field or a named field, distinguished by its shape:
	// - Embedded field — a single token, the type itself: "Object". This produces
	//   an embedded field. A pointer embed is written "*Object".
	// - Named field — two tokens separated by a space, "Name Type": "name *c.Char",
	//   "dict *Object".
	Fields []string
}

TypeDef represents a type definition.

type WrapFile added in v0.9.0

type WrapFile struct {
	Filename string
	Content  bytes.Buffer
}

Jump to

Keyboard shortcuts

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