Documentation
¶
Index ¶
- Constants
- Variables
- func DisposeSources(sources []cl.Source)
- func LoadGoFiles(fset *token.FileSet, dir string, goFiles []string, mode parser.Mode) (map[string]*ast.File, error)
- func ParseFlags(includeDirs []string, lang, platformDir string) []string
- func ParseSources(index clang.Index, headerFiles, includeDirs []string, lang, platformDir string) ([]cl.Source, error)
- func PlatformDir() string
- func SetDebug(flags int)
- func TargetPlatform() (goos, goarch string)
- type Config
- func (cfg *Config) Apply(parent *Config)
- func (cfg *Config) CheckPlatformDir(workDir string) error
- func (cfg *Config) Lang() (lang cl.Language, ok bool)
- func (cfg *Config) NewPackage(pkgPath, pkgName, destDir, workDir string, index clang.Index, ...) (ret cl.Package, lang cl.Language, err error)
- func (cfg *Config) Platform() (platformDir string, specific bool, err error)
- func (cfg *Config) StdlibDirs(workDir string) []string
- type Module
Constants ¶
const ( DbgFlagSettings = 1 << iota DbgFlagAll = DbgFlagSettings )
Variables ¶
var ( // ErrDirRequired is returned when the Dir field in the configuration is empty. // It indicates that the directory containing the header files is required. ErrDirRequired = errors.New("Dir (contains the header files) is required") )
var (
// GeneratedHeader is the header comment for llcppg generated Go files.
GeneratedHeader = "// Code generated by llcppg; DO NOT EDIT.\n\n"
)
Functions ¶
func DisposeSources ¶ added in v0.9.0
DisposeSources disposes the given translation units.
func LoadGoFiles ¶ added in v0.13.1
func LoadGoFiles(fset *token.FileSet, dir string, goFiles []string, mode parser.Mode) (map[string]*ast.File, error)
LoadGoFiles loads Go source files from the specified directory and returns a map of file names to AST files.
func ParseFlags ¶ added in v0.9.2
ParseFlags constructs the command-line flags for parsing C/C++ source files with clang.
func ParseSources ¶ added in v0.9.0
func ParseSources(index clang.Index, headerFiles, includeDirs []string, lang, platformDir string) ([]cl.Source, error)
ParseSources parses the given source files and returns the translation units corresponding to those files.
func PlatformDir ¶ added in v0.13.7
func PlatformDir() string
PlatformDir returns the $GOOS-$GOARCH directory name for the target platform, e.g. "darwin-arm64".
func TargetPlatform ¶ added in v0.13.7
func TargetPlatform() (goos, goarch string)
TargetPlatform returns the target GOOS and GOARCH for the current conversion. The GOOS and GOARCH environment variables select the target platform; when either is unset it falls back to the host value (runtime.GOOS / runtime.GOARCH), matching Go's own conventions.
Types ¶
type Config ¶
type Config struct {
// Package Name (required). Sub-package name should start with '/'.
Name string `json:"Name"`
// Language (required). c, c++, etc.
Language string `json:"Language"`
// dir or dir/... (recursive), required.
//
// For a platform-specific project (headers differ per OS/arch), Dir must
// start with the literal "$GOOS-$GOARCH/" prefix, e.g.
// "$GOOS-$GOARCH/include" or "$GOOS-$GOARCH/include/...". The prefix opts
// the project into per-platform layout: headers are read from
// <$GOOS-$GOARCH>/... (e.g. darwin-arm64/include) and output is written
// under <dest-dir>/$GOOS-$GOARCH. $GOOS/$GOARCH may appear only as this
// leading segment. See https://github.com/goplus/llcppg/issues/1125.
Dir string `json:"Dir"`
// selected header files relative to Dir; overrides auto-discovery, optional.
Files []string `json:"Files"`
// GoFiles — mixing hand-written and generated Go code (optional).
// See https://github.com/xgo-dev/llcppg/issues/1100.
GoFiles []string
// C stdlib include dir, optional
Stdlib string `json:"Stdlib"`
// LLGoPackage specifies the value of the LLGoPackage constant in the generated
// Go package (optional).
LLGoPackage string `json:"LLGoPackage"`
// 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 `json:"CFlags"`
// dependencies (module paths), optional
Deps []string `json:"Deps"`
// Class specifies a list of C/C++ typedef names to be treated as classes (optional).
Class []string `json:"Class"`
// 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 `json:"NonClass"`
// NSPrefix specifies the prefix to remove from C/C++ namespace names when generating
// Go package names (optional).
NSPrefix []string `json:"NSPrefix"` // C/C++ namespace prefix to remove
// Type Creator Detection (optional). See https://github.com/xgo-dev/llcppg/issues/960.
NewCheck []string `json:"NewCheck"`
// Type Method Detection (optional). See https://github.com/xgo-dev/llcppg/issues/955.
MethodCheck []string `json:"MethodCheck"`
// Method specifies a list of C function names to be treated as methods (optional).
Method []string `json:"Method"`
// FuncPrefix specifies the prefix to remove from C/C++ global function names when
// generating Go function names (optional).
FuncPrefix []string `json:"FuncPrefix"`
// VarPrefix specifies the prefix to remove from C/C++ global variable names when
// generating Go variable names (optional).
VarPrefix []string `json:"VarPrefix"`
// EnumPrefix specifies the prefix to remove from C/C++ enum value names when generating
// Go const names (optional).
EnumPrefix []string `json:"EnumPrefix"`
// MacroPrefix specifies the prefix to remove from C/C++ macro names when generating
// Go const names (optional).
MacroPrefix []string `json:"MacroPrefix"`
// 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 `json:"MethodPrefix"`
// TypePrefix/TypeSuffix specifies the prefix/suffix to remove from C/C++ type names
// when generating Go type names (optional).
TypePrefix []string `json:"TypePrefix"`
TypeSuffix []string `json:"TypeSuffix"`
// 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 `json:"TypeAbbr"`
// 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 `json:"Rename"`
// 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 `json:"FieldAlias"`
// 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][]cl.TypeDef `json:"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 `json:"TypeAlias"`
// TypeIgnore specifies a list of C/C++ type names to be ignored (optional).
TypeIgnore []string `json:"TypeIgnore"`
// FuncIgnore specifies a list of C/C++ function names to be ignored (optional).
FuncIgnore []string `json:"FuncIgnore"`
// MacroIgnore specifies a list of C/C++ macro names to be ignored (optional).
MacroIgnore []string `json:"MacroIgnore"`
// 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.
// See https://github.com/xgo-dev/llcppg/issues/1051.
//
// Function-like macros not listed here are examined by automatic
// forwarding-macro detection: a plain forwarding call to a generated function
// becomes an ordinary Go function calling the callee directly. A listed macro
// is always wrapped and never reinterpreted.
// See https://github.com/xgo-dev/llcppg/issues/1109.
MacroFunc map[string]string `json:"MacroFunc"`
// MacroGroup declares groups of related constant macros 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.
// See https://github.com/xgo-dev/llcppg/issues/1064.
MacroGroup map[string]string `json:"MacroGroup"`
// NSIgnore specifies a list of C/C++ namespaces to be ignored (optional).
NSIgnore []string `json:"NSIgnore"`
// Sub-packages to generate, optional
Pkgs []string `json:"Pkgs"`
// exit on first N errors, optional
FailFast int `json:"FailFast"`
// EnumAlwaysUntyped specifies whether all enums should be treated as untyped (optional).
// See https://github.com/xgo-dev/llcppg/issues/1103.
EnumAlwaysUntyped bool `json:"EnumAlwaysUntyped"`
// 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 `json:"ForceCamelCase"`
// quietly ignore inline functions
IgnoreInline bool `json:"IgnoreInline"`
// quietly ignore functions with no mangled symbol
NoManglingIgnore bool `json:"NoManglingIgnore"`
// treats sub-directory files as a single file.
// Deprecated: use GroupSubdirBy instead.
GroupSubdir bool `json:"GroupSubdir"`
// criterion to group sub-directory files by, e.g., "dir" or "fname". `GroupSubdir = true`
// is equivalent to `GroupSubdirBy = "dir"`.
GroupSubdirBy string `json:"GroupSubdirBy"`
// IncludeDir specifies a function to determine the include directory for a given
// package path (optional).
IncludeDir func(pkgPath string) (includeDir string, err error) `json:"-"`
}
Config represents the configuration for the llcppg tool.
func (*Config) Apply ¶ added in v0.9.2
Apply applies the parent configuration to the current configuration.
func (*Config) CheckPlatformDir ¶ added in v0.13.7
CheckPlatformDir validates, for a platform-specific project, that the source directory selected by Dir for the target platform exists under workDir. It is a no-op for ordinary (non-platform-specific) projects. It lets a caller fail fast — before creating any output — when the headers for the requested platform are not present.
func (*Config) NewPackage ¶ added in v0.9.0
func (cfg *Config) NewPackage(pkgPath, pkgName, destDir, workDir string, index clang.Index, defines ...cl.ConstDef) (ret cl.Package, lang cl.Language, err error)
NewPackage loads the source files and converts them into a Go package according to the configuration.
func (*Config) Platform ¶ added in v0.13.7
Platform reports whether the configuration describes a platform-specific project and, if so, the resolved $GOOS-$GOARCH directory name for the target platform (e.g. "darwin-arm64"). It also validates the Dir field:
- A Dir may reference $GOOS or $GOARCH only as the leading "$GOOS-$GOARCH/" segment; any other usage is an error.
- A Dir without the prefix is an ordinary, platform-independent project (platformDir == "", specific == false).
Detection is driven purely by the Dir prefix.
func (*Config) StdlibDirs ¶ added in v0.9.2
StdlibDirs returns the standard library include directories.
type Module ¶ added in v0.9.0
type Module struct {
// contains filtered or unexported fields
}
Module represents a llcppg module.
func LoadModuleFrom ¶ added in v0.9.0
LoadModuleFrom loads a llcppg module from the specified directory.
func (Module) IncludeDir ¶ added in v0.9.2
IncludeDir returns the include directory for the specified module path. It looks up the module version in the go.mod file and retrieves the include directory from the module cache.
Directories
¶
| Path | Synopsis |
|---|---|
|
_testc
|
|
|
Package initpkg implements `llcppg -init`, which bootstraps a new binding repository from the llcppg template.
|
Package initpkg implements `llcppg -init`, which bootstraps a new binding repository from the llcppg template. |