Documentation
¶
Overview ¶
Package rawlib contains the per-construct emitters that convert [meta] structures into the raw CGo library Go source files and bridge files.
Each top-level function writes one logical output unit:
- [Classes] — one .go file per ObjC class, using struct embedding to model the superclass chain.
- [ClassInterfaces] — one <Name>able Go interface per ObjC class, enabling mock implementations for testing and polymorphic acceptance.
- [Bridge] — a C header (.h) and Objective-C implementation (.m) with thin wrapper functions for every bridged method. Bridge files are compiled with -fno-objc-arc; returned objects are +1 retained.
- [Enums] — typed Go const blocks; bitmask enums receive a bitwise String method.
- [Structs] — value-type wrappers for C structs (CGRect, CGSize, etc.).
- [Protocols] — Go interface types for ObjC @protocols.
- [Externs] — package-level constants for extern symbols.
- [Functions] — Go wrappers for free C functions.
- [Blocks] — named Go func types for ObjC block signatures.
- [BlockTrampolines] — CGo trampoline header and implementation.
- [ForeignExtensions] — package-level functions for ObjC categories that extend a class owned by a different framework.
- [FoundationVariadicWrappers] — hand-authored Go variadic overloads for Foundation methods whose ObjC signature is variadic.
Emitters discover their import requirements as a side effect of type resolution: they populate a usedImports map during body generation, then write the file header (with import block) followed by the body in a single pass.
Index ¶
- func EmitBSDPackage(w io.Writer) error
- func EmitEnums(w io.Writer, framework *macosplatformmetadata.FrameworkMeta) error
- func EmitProtocols(w io.Writer, pkgName string, framework *macosplatformmetadata.FrameworkMeta, ...) error
- func EmitPuregoExterns(w io.Writer, pkgName string, framework *macosplatformmetadata.FrameworkMeta, ...) (hasExterns bool, err error)
- func EmitPuregoManual(w io.Writer, pkgName, frameworkName string) error
- func EmitPuregoRuntime(w io.Writer, pkgName, frameworkName, dylibPath string, ...) error
- func EmitStructs(w io.Writer, framework *macosplatformmetadata.FrameworkMeta, m *typemap.Mapper, ...) (typemap.ImportSet, error)
- func EmittableFunctions(framework *macosplatformmetadata.FrameworkMeta) []macosplatformmetadata.Function
- func EnumsNeedImports(framework *macosplatformmetadata.FrameworkMeta) (needsFmt, needsStrings bool)
- func FunctionGoName(framework *macosplatformmetadata.FrameworkMeta, ...) string
- func HasPuregoManual(framework string) bool
- type PuregoRegistration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EmitBSDPackage ¶
EmitBSDPackage writes the static bsd support package source. The type mapper resolves POSIX/BSD C structs (see typemap's bsdStructTypes) to bsd.TypeName references, so the package must exist alongside the generated C library packages. Because the libraries output tree is wiped on every run, the package is re-emitted by the generator rather than hand-crafted.
func EmitEnums ¶
func EmitEnums(w io.Writer, framework *macosplatformmetadata.FrameworkMeta) error
Enums writes all enum types and their constants to w.
func EmitProtocols ¶
func EmitProtocols(w io.Writer, pkgName string, framework *macosplatformmetadata.FrameworkMeta, m *typemap.Mapper, knownClasses map[string]bool, knownProtocols map[string]string, allClasses map[string]macosplatformmetadata.Class) error
Protocols writes a complete _protocols.go file with Go interface definitions for all ObjC protocols in the framework.
func EmitPuregoExterns ¶ added in v0.19.0
func EmitPuregoExterns( w io.Writer, pkgName string, framework *macosplatformmetadata.FrameworkMeta, m *typemap.Mapper, knownClasses map[string]bool, ) (hasExterns bool, err error)
EmitPuregoExterns writes a purego-backed _externs.go: the SAME package vars the CGo emission declares (buildExternsModel is the shared authority), plus an _initExterns(lib uintptr) the runtime file calls after Dlopen. Init shapes mirror externInitExpr with the bridge address getter replaced by the Dlsym'd symbol address.
func EmitPuregoManual ¶ added in v0.19.0
EmitPuregoManual writes the <pkg>_manual file: hand-written Go bodies for the framework's header-inline functions (manualPuregoFuncs), which have no exported dylib symbol to bind. The bodies are generator-owned (regenerated each run) so they survive the output-tree wipe. They share the runtime file's dylib handle (_<pkg>Lib) and _loadOnce.
func EmitPuregoRuntime ¶ added in v0.19.0
func EmitPuregoRuntime( w io.Writer, pkgName, frameworkName, dylibPath string, regs []PuregoRegistration, hasExterns bool, ) error
EmitPuregoRuntime writes <pkg>_runtime.go for a purego-backed library: Dlopen of the library's dylib, per-symbol registration through a tolerant _register (a missing symbol must not prevent the remaining bindings), a SymbolAvailable probe, and extern population.
func EmitStructs ¶
func EmitStructs(w io.Writer, framework *macosplatformmetadata.FrameworkMeta, m *typemap.Mapper, knownClasses map[string]bool) (typemap.ImportSet, error)
Structs writes all C struct type definitions and struct typedef aliases to w. It returns a map of Go package alias → import path for any cross-framework imports required by struct fields (e.g. corefoundation for CF-typed fields).
func EmittableFunctions ¶
func EmittableFunctions(framework *macosplatformmetadata.FrameworkMeta) []macosplatformmetadata.Function
buildFunctionsModel filters eligible functions, maps their types and arguments, and collects all imports. The complex return-path dispatch is resolved here (in buildFunctionCallBody) so the template stays a structural description. EmittableFunctions returns the plain C functions that EmitFunctions emits as Go wrappers for framework, in declaration order, after applying the same skip and de-duplication rules (inline/variadic/unavailable/builtin/UPP/va_list/by-value unknown filters, plus collision with package-level type names). The idiomatic library layer uses this so it only ever wraps raw functions that actually exist.
func EnumsNeedImports ¶
func EnumsNeedImports(framework *macosplatformmetadata.FrameworkMeta) (needsFmt, needsStrings bool)
EnumsNeedImports reports which stdlib imports the enum file will need.
func FunctionGoName ¶ added in v0.15.0
func FunctionGoName(framework *macosplatformmetadata.FrameworkMeta, fn macosplatformmetadata.Function) string
FunctionGoName returns the Go wrapper name EmitFunctions gives fn. C permits a struct and a function to share a name (e.g. mach_time.h declares both a mach_timebase_info struct and function); the natural Go name then collides with the emitted type, so the wrapper gains an "Fn" suffix (Mach_timebase_infoFn) instead of being silently dropped. The idiomatic layer resolves its raw call targets through this same rule. The spelling is backend-independent: the purego backend swaps only function bodies, never the Go surface.
func HasPuregoManual ¶ added in v0.19.0
HasPuregoManual reports whether framework has any hand-written purego function bodies (i.e. EmitPuregoManual would write a non-empty file).
Types ¶
type PuregoRegistration ¶ added in v0.19.0
type PuregoRegistration struct {
Symbol string // C symbol name
VarName string // package-level func var
Type string // Go func type of the var
}
PuregoRegistration is one RegisterLibFunc call the runtime file makes after a successful Dlopen.
func EmitPuregoFunctions ¶ added in v0.19.0
func EmitPuregoFunctions( w io.Writer, pkgName string, framework *macosplatformmetadata.FrameworkMeta, m *typemap.Mapper, knownClasses map[string]bool, ) ([]PuregoRegistration, error)
EmitPuregoFunctions writes a purego-backed _functions.go: package-level func vars plus exported wrappers with signatures IDENTICAL to the CGo emission. The returned registrations are embedded in the runtime file's _loadLibrary. A function whose body cannot be expressed without the bridge (block args, ObjC object returns) is skipped with a diagnostic — none exist in the currently migrated libraries; blocks arrive with dispatch/xpc.