Documentation
¶
Overview ¶
Package mactool builds Glutter apps for macOS, for glutter-macos (SPEC §29.1): it writes the Info.plist of an app bundle, the .icns icon from a PNG, one Mach-O file with an arm64 and an amd64 slice (what `lipo` makes), the bundle's directories, and signs the bundle ad hoc with /usr/bin/codesign. All of it but the signing is plain Go with no OS tag, so it is tested on any host; it runs on the developer's Mac, never inside an app, and needs no Xcode, no C compiler and no lipo.
Flutter: no counterpart (flutter build macos)
Index ¶
- Constants
- func BuildEnv(environ []string, arch, minMacOS string) []string
- func DefaultID(name string) string
- func DefaultIcon() ([]byte, error)
- func DefaultName(pkg, dir string) string
- func DefaultUsage(name string) map[string]string
- func Entitlements() []byte
- func Fat(slices []FatSlice) ([]byte, error)
- func ICNS(pngData []byte) ([]byte, error)
- func InfoPlist(i Info) ([]byte, error)
- func MinOSOf(data []byte) (string, bool)
- func Sign(ctx context.Context, app string, o SignOptions) error
- func Verify(ctx context.Context, app string, o SignOptions) error
- type BuildOptions
- type BuildResult
- type Bundle
- type DocumentType
- type FatSlice
- type Info
- type Layout
- type SignOptions
Constants ¶
const ( // DefaultVersion is the version of an app that does not say. // // Flutter: no counterpart DefaultVersion = "1.0.0" // MinSystemVersion is the LSMinimumSystemVersion of a bundle that names none (Info.MinSystemVersion), and the lowest // one a bundle can name. // // Flutter: no counterpart MinSystemVersion = "13.0" )
The defaults of an app's identity and the lowest macOS that runs it (D34: macOS 13 is the minimum since step 51.1, the go toolchain's: Go 1.27's linker builds its own objects for macOS 13.0).
const ( // RoleViewer is the role of an app that reads the files of a type; it is also the role of the app for its URL schemes. // // Flutter: no counterpart RoleViewer = "Viewer" // RoleEditor is the role of an app that reads and writes the files of a type. // // Flutter: no counterpart RoleEditor = "Editor" )
The roles of a DocumentType.
const ( // TagMacOSBuildFailed is the tag of the error for a package that does not build for macOS, or a build that cannot start. // // Flutter: no counterpart TagMacOSBuildFailed = "MacOSBuildFailed" )
The tags of the errors that this file makes (rm4n0s/errors, R5).
const TagMacOSBundleInvalid = "MacOSBundleInvalid"
TagMacOSBundleInvalid is the tag of the error for a name, identifier or version that a bundle cannot have, a layout that cannot be written, or a bundle with a problem.
Flutter: no counterpart
const ( // TagMacOSIconInvalid is the tag of the error for an icon that is not a square PNG of at least 16 pixels, or that cannot be // encoded. // // Flutter: no counterpart TagMacOSIconInvalid = "MacOSIconInvalid" )
The tags of the errors that this file makes (rm4n0s/errors, R5).
const ( // TagMacOSMachOInvalid is the tag of the error for a file that is not a thin Mach-O, or slices that cannot make a universal // file. // // Flutter: no counterpart TagMacOSMachOInvalid = "MacOSMachOInvalid" )
The tags of the errors that this file makes (rm4n0s/errors, R5).
const ( // TagMacOSSignFailed is the tag of the error for a bundle that codesign cannot sign or verify. // // Flutter: no counterpart TagMacOSSignFailed = "MacOSSignFailed" )
The tags of the errors that this file makes (rm4n0s/errors, R5).
Variables ¶
This section is empty.
Functions ¶
func BuildEnv ¶
BuildEnv is the environment of the go command that builds an app for macOS: environ with GOOS=darwin, GOARCH=arch (when arch is not empty), CGO_ENABLED=0 unless environ sets CGO_ENABLED (an app whose packages need cgo is built with CGO_ENABLED=1 in the environment), and the minimum (MinSystemVersion when empty) as MACOSX_DEPLOYMENT_TARGET and as -mmacosx-version-min after the CGO_CFLAGS and CGO_LDFLAGS of environ (go's own -O2 -g when it has none), so that clang compiles the cgo code and links for the macOS that the plist names, not for the macOS of the machine that builds; the flags are there because the go command's cache does not tell objects apart by MACOSX_DEPLOYMENT_TARGET.
Flutter: no counterpart
func DefaultID ¶
DefaultID is the identifier of an app that has none: "dev.glutter." and the name in letters, digits and hyphens.
Flutter: no counterpart
func DefaultIcon ¶
DefaultIcon returns Glutter's icon as a PNG of 1024 pixels: a white ring with a gap and a bar, the shape of a "G", on the blue of the Material seed color, in a rounded square with the margin that macOS app icons have.
Flutter: no counterpart
func DefaultName ¶
DefaultName is the name of an app that has none: the last element of its package path, or of the directory for ".".
Flutter: no counterpart
func DefaultUsage ¶
DefaultUsage are the usage strings that every bundle has: the system asks for the microphone only when an app records, and shows the string then.
Flutter: no counterpart
func Entitlements ¶
func Entitlements() []byte
Entitlements writes the entitlements file that the hardened runtime needs for what the app does: the microphone.
Flutter: no counterpart
func Fat ¶
Fat writes a universal Mach-O file with the thin files as its slices, as `lipo -create` does: the header of big-endian numbers (the magic, the number of slices, and for each slice its CPU type and subtype, offset, size and alignment), then the slices at the offsets that their alignment gives (2^14 for arm64 and 2^12 for the rest, which are what lipo uses). The CPU type of a slice is read from its own header, so a file that is not a thin Mach-O, or two slices of one architecture, is MacOSMachOInvalid.
Flutter: no counterpart
func ICNS ¶
ICNS makes the .icns file of an icon from a PNG that is square and at least 16 pixels wide: each size of the file is the picture scaled (Catmull-Rom) and stored as a PNG, which every macOS that Glutter runs on reads. It fails with MacOSIconInvalid for a picture that is not that.
Flutter: no counterpart
func InfoPlist ¶
InfoPlist writes the Info.plist of the bundle as XML, with the keys in a fixed order (so a build is the same file every time) and the usage strings sorted by key. It fails with MacOSBundleInvalid for an identity that a bundle cannot have.
Flutter: no counterpart
func MinOSOf ¶
MinOSOf reads the oldest macOS that a thin Mach-O executable runs on, from its LC_BUILD_VERSION (or its older LC_VERSION_MIN_MACOSX), as "13.0" or "14.2.1". It reports false for data that is not a Mach-O or has neither command.
Flutter: no counterpart
func Sign ¶
func Sign(ctx context.Context, app string, o SignOptions) error
Sign signs the bundle with codesign: a signature on the bundle binds its Info.plist and resources to the executable, which Gatekeeper and the system's permission prompts read (an ad-hoc signature has no identity, so Gatekeeper still warns about an app that was downloaded). It fails with MacOSSignFailed, with codesign's output, when codesign cannot be run or says no.
Flutter: no counterpart
Types ¶
type BuildOptions ¶
type BuildOptions struct {
// Package is the main package to build, as `go build` takes it: "./examples/counter".
Package string
// Dir is the directory to run the go command in, which Package is relative to. The default is the current directory.
Dir string
// Out is the bundle to write, which ends in ".app"; "<Name>.app" in the current directory when empty.
Out string
// Archs are the architectures to build, "arm64" and "amd64"; with both the executable is one universal Mach-O. The default is
// the architecture of this machine (arm64 on a host that is not a Mac).
Archs []string
// Debug builds with -tags debug_mode (foundation.DebugMode) and does not strip the program; without it the build
// is a release, stripped with -ldflags=-s -w.
Debug bool
// Hardened signs with the hardened runtime and the entitlements of Entitlements().
Hardened bool
// ID, Name and Version go into the Info.plist; the defaults are DefaultID, the name of the package, and DefaultVersion.
ID, Name, Version string
// Icon is a PNG for the icon; Glutter's icon when empty.
Icon string
// Usage are usage strings added to those of DefaultUsage (a key of the plist and its text).
Usage map[string]string
// Env is added to the environment of the go command, after BuildEnv.
Env []string
// MinMacOS is the oldest macOS the app runs on, "14.0": it goes into the plist (LSMinimumSystemVersion) and is the
// MACOSX_DEPLOYMENT_TARGET of the go command, for the cgo code and the external linker. MinSystemVersion when empty;
// a version under it fails with MacOSBundleInvalid.
MinMacOS string
// URLSchemes and DocumentTypes are the URL schemes the app handles and the types of the files it opens (Info.URLSchemes,
// Info.DocumentTypes): the system then sends the app the links and the files as open requests (ui.OpenRequest).
URLSchemes []string
DocumentTypes []DocumentType
// Sign says how to sign the bundle; the zero value signs it ad hoc.
Sign SignOptions
}
BuildOptions are the parameters of Build (the flags of `glutter-macos build`, SPEC §29.1).
Flutter: no counterpart
type BuildResult ¶
type BuildResult struct {
// Layout has the paths of the bundle.
Layout Layout
// Archs are the architectures of the executable, in the order asked for.
Archs []string
// Info is what went into the plist, with the defaults filled in.
Info Info
// Size is the size of the executable in bytes.
Size int64
// Thin are the sizes of the thin files, by architecture.
Thin map[string]int64
}
BuildResult says what Build wrote.
Flutter: no counterpart
func Build ¶
func Build(ctx context.Context, o BuildOptions) (BuildResult, error)
Build compiles the package for each architecture (without cgo unless the environment sets CGO_ENABLED, BuildEnv), makes the executable (universal when there are two), the icon and the bundle, and signs it. It fails with MacOSBuildFailed, with the output of the go command, when the package does not build, and with the tags of the pieces (MacOSIconInvalid, MacOSMachOInvalid, MacOSBundleInvalid, MacOSSignFailed) otherwise.
Flutter: no counterpart
type Bundle ¶
type Bundle struct {
Info Info
// Executable is the Mach-O file, which is written with mode 0755 as Contents/MacOS/<Info.Executable>.
Executable []byte
// Icon is the .icns file; nil leaves the bundle without one.
Icon []byte
}
Bundle is what goes into an app bundle.
Flutter: no counterpart
type DocumentType ¶
type DocumentType struct {
// Name is what the Finder calls a file of the type ("BitTorrent file"; CFBundleTypeName).
Name string
// Extensions are the file extensions of the type, without the dot ("torrent"; CFBundleTypeExtensions): letters, digits,
// "_", "+" and "-". "*" alone is every file.
Extensions []string
// Role is what the app does with the file (CFBundleTypeRole): RoleViewer, also when empty, or RoleEditor.
Role string
}
DocumentType is a type of file that an app opens: one entry of the plist's CFBundleDocumentTypes.
Flutter: no counterpart
type FatSlice ¶
type FatSlice struct {
// Name says which file it is, for the errors ("arm64").
Name string
// Data is the thin Mach-O file.
Data []byte
}
FatSlice is a thin Mach-O file that goes into a universal one.
Flutter: no counterpart
type Info ¶
type Info struct {
// Executable is the name of the file in Contents/MacOS (CFBundleExecutable).
Executable string
// ID is the bundle identifier (CFBundleIdentifier), in reverse DNS form.
ID string
// Name is what the Dock and the menu bar call the app (CFBundleName and CFBundleDisplayName).
Name string
// Version is CFBundleShortVersionString and CFBundleVersion.
Version string
// IconFile is the name of the icon file in Contents/Resources (CFBundleIconFile); empty for none.
IconFile string
// Usage are the usage strings that the system shows when the app first asks for something: the keys are those of the plist
// ("NSMicrophoneUsageDescription"), the values the text.
Usage map[string]string
// MinSystemVersion is the oldest macOS that runs the app (LSMinimumSystemVersion), "major.minor" or
// "major.minor.patch"; MinSystemVersion (the constant) when empty.
MinSystemVersion string
// URLSchemes are the URL schemes the app handles ("magnet"; CFBundleURLTypes): a click on such a link starts the app, or
// reaches the running one, as a ui.OpenRequest. A scheme is letters, digits, "+", "-" and ".", and starts with a letter.
URLSchemes []string
// DocumentTypes are the types of the files the app opens (CFBundleDocumentTypes): a double click on such a file, or a drop
// on the app's icon, starts the app, or reaches the running one, as a ui.OpenRequest.
DocumentTypes []DocumentType
}
Info is what goes into the Info.plist of an app bundle.
Flutter: no counterpart
type Layout ¶
type Layout struct {
App, Contents, MacOS, Resources, Plist, Executable, Icon string
}
Layout names the paths of a bundle that is at app (a directory ending in ".app").
Flutter: no counterpart
func Write ¶
Write makes the bundle at app, replacing a bundle that is there. It writes Contents/MacOS/<executable>, Contents/Info.plist, Contents/PkgInfo and, with an icon, Contents/Resources/<IconFile>.icns. A file at app that is not a bundle is not removed: it is MacOSBundleInvalid. It fails with MacOSBundleInvalid for an identity that a bundle cannot have and for a path that cannot be written.
Flutter: no counterpart
type SignOptions ¶
type SignOptions struct {
// Hardened turns the hardened runtime on (`--options runtime`) with the entitlements of Entitlements(), which a bundle needs to be
// notarized; the owner does the notarization (docs/GUIDE.md), the tool only prepares for it.
Hardened bool
// Identity is the signing identity; "-" (ad hoc) when empty. A Developer ID is the owner's.
Identity string
// Tool is the codesign program; /usr/bin/codesign when empty.
Tool string
}
SignOptions are what Sign is asked for.
Flutter: no counterpart