layouttest

package
v1.16.3 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package layouttest checks the Go mirrors of C and Objective-C structures that the macOS and iOS backends pass to and get from the system (NSRect, CGPoint, CVTimeStamp, AudioStreamBasicDescription, ...) against the headers of the SDK (SPEC §29.2, §8.1 rule 3).

A test describes what Go believes (the size and field offsets of a mirror read by reflection, the value of each constant). The package writes a C file of _Static_assert lines from the description and compiles it with `xcrun clang -fsyntax-only` against the SDK of the Command Line Tools or Xcode. It starts no process but the compiler; a wrong mirror is a compile error that names the structure and the field. It is skipped, with the install command, when xcrun or a header is missing, which includes every host that is not a Mac.

The package has no OS tag, so it is listed on every OS; its compiler tests run on a Mac only. Windows has its own (internal/platform/windows/win32/layouttest, which uses mingw-w64).

Flutter: no counterpart

Index

Constants

View Source
const DefaultCompiler = "xcrun"

DefaultCompiler is the program that runs the SDK's clang: xcrun finds the SDK of the Command Line Tools or of Xcode.

Flutter: no counterpart

View Source
const InstallCommand = "xcode-select --install"

InstallCommand installs the compiler and the SDK headers.

Flutter: no counterpart

Variables

This section is empty.

Functions

func Check

func Check(t testing.TB, spec Spec)

Check runs the default Checker over spec in a test. A missing compiler or header skips the test with the install command (so does every host that has no xcrun); any other failure fails it, with the compiler's own messages.

Flutter: no counterpart

Types

type Checker

type Checker struct {
	// Compiler is the program to run; empty means DefaultCompiler.
	Compiler string
	// SDK is the name of the SDK that xcrun picks ("macosx", "iphoneos", "iphonesimulator"); empty
	// means "macosx".
	SDK string
	// Args are more arguments for clang, such as the -target of an iOS build.
	Args []string
	// LookPath finds the compiler; nil means exec.LookPath.
	LookPath func(string) (string, error)
	// Run runs the compiler with its arguments and returns its output (standard output and error
	// together) and its exit code; the error is for a compiler that cannot be started, and is returned
	// by Check as it is (it must be tagged). nil runs the program with exec.
	Run func(ctx context.Context, argv []string) (output []byte, exitCode int, err error)
}

Checker compiles a Spec. The zero value uses the real compiler; the fields let a test use a fake runner or another SDK.

Flutter: no counterpart

func (Checker) Check

func (c Checker) Check(ctx context.Context, spec Spec) error

Check writes the C file of spec to a temporary directory and compiles it with -fsyntax-only. It returns nil when every assertion holds, and fails with:

  • DarwinLayoutCompilerMissing when xcrun is not installed (metadata "compiler" and "install");
  • DarwinLayoutHeaderMissing when a header is not found (metadata "header" and "install");
  • DarwinLayoutMismatch when a Go mirror differs from the header (metadata "failed", the messages of the assertions that failed, which name the structure and the field, and "output");
  • DarwinLayoutCompileFailed for any other compiler error, such as a type or member that the header does not have (metadata "output", "exit code" and "command");
  • DarwinLayoutCompilerRunFailed when the compiler cannot be started;
  • DarwinLayoutFileFailed when the C file cannot be written.

Flutter: no counterpart

type Const

type Const struct {
	// Name is the macro or enumerator in the headers.
	Name string
	// Value is the value Go uses.
	Value int64
}

Const is an integer constant, such as an enumerator or a macro, with the value Go uses.

Flutter: no counterpart

type Field

type Field struct {
	// CName is the name of the member in the header.
	CName string
	// Offset is the offset of the Go field.
	Offset uintptr
	// Size is the size of the Go field.
	Size uintptr
}

Field is one member of a structure.

Flutter: no counterpart

type Spec

type Spec struct {
	// Headers are the headers to import, such as "CoreFoundation/CoreFoundation.h" or
	// "AppKit/AppKit.h".
	Headers []string
	// Defines are macros to define.
	Defines []string
	// Structs are the mirrors of C structures.
	Structs []Struct
	// Consts are integer constants (enumerators, macros) with the value that Go uses.
	Consts []Const
}

Spec is what a test believes about the SDK's headers.

Flutter: no counterpart

func (Spec) Source

func (s Spec) Source() string

Source writes the C file that the spec stands for: the imports, then one _Static_assert for each size, offset, field size and constant. The message of each assertion names what it checks ("CGRect.origin: offset"), so the compiler's output names the structure.

Flutter: no counterpart

type Struct

type Struct struct {
	// CName is the name the header gives the type, such as "CGRect" or "CFRunLoopSourceContext".
	CName string
	// Size is the size of the Go type.
	Size uintptr
	// Fields are the fields, in Go's order.
	Fields []Field
}

Struct is the Go mirror of one C structure: its C name, size and fields.

Flutter: no counterpart

func StructOf

func StructOf(cName string, v any) Struct

StructOf reads the size and the fields of a Go struct value by reflection. Each field must carry a `c:"name"` tag with the member's name in the C header; a field named "_" (padding) is skipped, and so is a field tagged `c:"-"`. A value that is not a struct, or a field without the tag, is a mistake of the test and panics.

Flutter: no counterpart

Jump to

Keyboard shortcuts

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