Documentation
¶
Overview ¶
Package native holds the native bundle's inputs, its layer digests, the lock that pins published layers, the per-machine layer cache and the cgo environment a layer provides.
Index ¶
- Constants
- func BuildLibs(ctx context.Context, in Inputs, t Target, recipeDir, cacheRoot, archive string, ...) error
- func BuildToolchain(ctx context.Context, in Inputs, t Target, recipeDir, cacheRoot, archive string, ...) error
- func CacheRoot() (string, error)
- func ExportLines(vars []EnvVar) string
- func Fetch(ctx context.Context, cacheRoot string, l Layer) (string, error)
- func FetchFile(ctx context.Context, cacheRoot string, d Download) (string, error)
- func FetchTool(ctx context.Context, cacheRoot string, p PinnedTool, t Target, ...) (string, error)
- func HostTargetName() string
- func LayerDir(cacheRoot string, l Layer) string
- func LibsDigest(in Inputs, t Target, recipe fs.FS) (string, error)
- func Program(t Target, name string) string
- func Published(ctx context.Context, base string, id LayerID) (bool, error)
- func StaleLock(root string) ([]string, error)
- func ToolDir(cacheRoot string, p PinnedTool) string
- func ToolchainDigest(in Inputs, t Target, recipe fs.FS) (string, error)
- func WantRepo(root string) (Inputs, []LayerID, error)
- type Bundle
- type Compilers
- type Component
- type DebianTool
- type Download
- type EnvVar
- type Gate
- type Inputs
- func (in Inputs) Component(name string) (Component, error)
- func (in Inputs) Layers(t Target, recipe fs.FS) ([]LayerID, error)
- func (in Inputs) Packager(name, target string) (Packager, error)
- func (in Inputs) Target(name string) (Target, error)
- func (in Inputs) Tool(name string) (Tool, error)
- func (in Inputs) ToolArchives() []ToolArchive
- func (in Inputs) Toolchain(t Target) (Toolchain, error)
- type Kind
- type Layer
- type LayerID
- type Lock
- type Metadata
- type Packager
- type PinnedTool
- type Runtime
- type Source
- type Target
- type Tool
- type ToolArchive
- type Toolchain
Constants ¶
const ( InputsPath = "native/inputs.json" RecipeDir = "native/recipe" LockPath = "native/lock.json" )
const CacheRootEnv = "SLIPSTREAM_NATIVE_CACHE"
CacheRootEnv names a directory that replaces the default cache root. CI points it at the runner's temp drive, which on Windows extracts the cached layers about four times faster than the user profile's drive.
const MetadataFile = "slipstream-native.json"
MetadataFile sits at every layer's root. The recipe writes it, and every path in it is relative to the layer root, so the layer can live anywhere.
const PublishHint = "dispatch the bundle workflow at this branch " +
"(gh workflow run layers.yml -R jatassi/slipstream-native -f ref=<branch-or-sha>, " +
"or https://github.com/jatassi/slipstream-native/actions/workflows/layers.yml), " +
"then run scripts/native-deps pin"
const ReleasesURL = "https://github.com/jatassi/slipstream-native/releases/download"
ReleasesURL is where the bundle workflow publishes each layer as the asset of its own release.
const ToolsEnv = "SLIPSTREAM_NATIVE_TOOLS"
ToolsEnv lists the path of every tool program the fetched bundle ships, separated by the OS path list separator, so whatever builds a binary outside cmd/release can place the programs beside it.
Variables ¶
This section is empty.
Functions ¶
func BuildLibs ¶
func BuildLibs(ctx context.Context, in Inputs, t Target, recipeDir, cacheRoot, archive string, log io.Writer) error
BuildLibs builds the libs layer for t with its recipe and t's toolchain, and writes it to archive like BuildToolchain.
func BuildToolchain ¶
func BuildToolchain(ctx context.Context, in Inputs, t Target, recipeDir, cacheRoot, archive string, log io.Writer) error
BuildToolchain builds the toolchain layer for t with its recipe and writes it to archive as a gzipped tar whose paths are relative to the layer root.
func CacheRoot ¶
CacheRoot is the per-machine native cache that every worktree shares. Its name differs from SlipStream v1's data folder, %LOCALAPPDATA%\SlipStream, in more than case, since Windows paths ignore case.
func ExportLines ¶
ExportLines renders vars as POSIX shell export lines for eval.
func Fetch ¶
Fetch makes the layer present in the cache and returns its directory. It downloads the asset beside the final directory, checks its SHA-256 against the lock, extracts it and renames it into place, so the cache never holds a layer that is partial or does not match the lock. A present layer costs no request.
func FetchFile ¶
FetchFile makes d present in the cache, named by its SHA-256 like a layer, and returns its path. The file keeps the base name of its URL.
func FetchTool ¶
func FetchTool(ctx context.Context, cacheRoot string, p PinnedTool, t Target, programs []string) (string, error)
FetchTool makes the tool archive present in the cache and returns its directory, the way Fetch does a layer. The archive must hold each of programs, as named for t, at its root.
func HostTargetName ¶
func HostTargetName() string
func LayerDir ¶
LayerDir is where a fetched layer lives under the cache root. The path holds the asset's SHA-256, so a bump moves every cgo flag that points into the layer and Go's build cache rebuilds the cgo packages.
func LibsDigest ¶
LibsDigest names a libs layer by the target row, every component, every file under the recipe's libs directory and the toolchain that compiles it: the digest of its toolchain layer, or the pinned Xcode version. A toolchain bump rebuilds the libs.
func StaleLock ¶
StaleLock describes each way the lock in the checkout at root differs from the layers its inputs and recipe build and the tool archives its inputs list, each with how to bring the lock up to date.
func ToolDir ¶
func ToolDir(cacheRoot string, p PinnedTool) string
ToolDir is where a fetched tool archive lives under the cache root, named by the archive's SHA-256 like a layer.
func ToolchainDigest ¶
ToolchainDigest names a toolchain layer by everything that goes into building it: the target and its triple, the toolchain's sources, and the path and content of every file under the toolchain's recipe directory. Two inputs that hash alike build the same layer, so an existing layer with this digest is never rebuilt.
Types ¶
type Bundle ¶
Bundle is a target's fetched layers and tools as the lock pins them for the current inputs and recipe: the libs layer, whose digest names the whole bundle, the path of every tool program, and the environment that builds against the libs with the target's toolchain and names the programs in ToolsEnv.
type Compilers ¶
Compilers is a toolchain layer's metadata.
func ReadCompilers ¶
ReadCompilers reads the compilers of the toolchain layer at layerDir as absolute paths.
type DebianTool ¶
DebianTool is a tool's Debian package for each Linux target, which installs Programs into Dir.
type EnvVar ¶
type EnvVar struct {
Name, Value string
}
func CgoEnv ¶
CgoEnv is the environment that builds cgo packages for t against the libs layer at layerDir with cc. The flags start with cgo's own defaults, -O2 -g, which setting the variables would otherwise drop, and define SLIPSTREAM_NATIVE_BUNDLE, which the shim's header requires. The layer's defines go to C++ only: only C++ includes libtorrent's headers, and C packages such as runtime/cgo define some of them themselves.
The go command records CGO_LDFLAGS in every cgo package it builds, runtime/cgo included, and the Go linker hands each copy to the host linker, so the libraries reach it more than once. ld64 drops the repeats; on darwin the flags tell it to do so without a warning per library.
type Gate ¶
type Gate string
Gate says which CI runs build a target: every PR, or only main, nightly, release and PRs that touch native code.
type Inputs ¶
type Inputs struct {
Targets []Target `json:"targets"`
Toolchains []Toolchain `json:"toolchains"`
Components []Component `json:"components"`
Tools []Tool `json:"tools"`
Packagers []Packager `json:"packagers"`
}
func LoadInputs ¶
func ParseInputs ¶
func (Inputs) Layers ¶
Layers names the layers t ships by the digest of the current inputs and recipe, in build order: its toolchain layer when its toolchain has one, then its libs layer.
func (Inputs) ToolArchives ¶
func (in Inputs) ToolArchives() []ToolArchive
ToolArchives lists every tool's archive for every target, in input order.
type Layer ¶
type Layer struct {
LayerID
Asset string `json:"asset"`
URL string `json:"url"`
SHA256 string `json:"sha256"`
}
Layer is a published layer as the lock pins it.
type LayerID ¶
type LayerID struct {
Kind Kind `json:"kind"`
Target string `json:"target"`
Digest string `json:"digest"`
}
LayerID names a layer by what builds it.
type Lock ¶
type Lock struct {
Layers []Layer `json:"layers"`
Tools []PinnedTool `json:"tools"`
}
Lock pins every layer the inputs build to its published asset, and every tool archive the inputs list to its content. Only `release deps pin` writes it.
func (Lock) PinnedTool ¶
func (l Lock) PinnedTool(a ToolArchive) (PinnedTool, error)
func (Lock) StaleTools ¶
func (l Lock) StaleTools(want []ToolArchive) []string
StaleTools describes each way the lock's tool archives differ from want.
type Metadata ¶
type Metadata struct {
IncludeDirs []string `json:"include_dirs"`
Defines []string `json:"defines"`
// StaticLibs are in link order.
StaticLibs []string `json:"static_libs"`
SystemLibs []string `json:"system_libs"`
}
Metadata is a libs layer's metadata: what cgo needs to build against it.
func ReadMetadata ¶
type Packager ¶
type Packager struct {
Name string `json:"name"`
Version string `json:"version"`
Target string `json:"target"`
Download
}
Packager is a program the release runs to build a package, never ships.
type PinnedTool ¶
type PinnedTool struct {
ToolArchive
SHA256 string `json:"sha256"`
}
PinnedTool is a tool archive as the lock pins it.
func PinTools ¶
func PinTools(ctx context.Context, archives []ToolArchive) ([]PinnedTool, error)
PinTools hashes each tool archive.
type Runtime ¶
type Runtime struct {
Name string `json:"name"`
Source string `json:"source"`
License string `json:"license"`
}
Runtime is a library a toolchain links statically into every binary of the targets that use it, shipped from one of the toolchain's sources.
type Source ¶
type Source struct {
Name string `json:"name"`
Version string `json:"version"`
URL string `json:"url"`
SHA256 string `json:"sha256"`
}
Source is a pinned source archive a recipe builds from.
type Target ¶
type Target struct {
Name string `json:"name"`
GOOS string `json:"goos"`
GOARCH string `json:"goarch"`
Runner string `json:"runner"`
// Toolchain names the entry of Inputs.Toolchains that compiles the
// target's libs layer and its cgo packages.
Toolchain string `json:"toolchain"`
// Triple is the target triple the toolchain compiles for.
Triple string `json:"triple,omitempty"`
MinOS string `json:"min_os"`
Gate Gate `json:"gate"`
// GoTags are build tags every build against the target's bundle needs.
GoTags []string `json:"go_tags,omitempty"`
// Env is the environment every C and C++ compile for the target runs
// in, both in the libs layer build and in cgo.
Env map[string]string `json:"env,omitempty"`
// OpenSSLTarget is the target name OpenSSL's Configure takes.
OpenSSLTarget string `json:"openssl_target"`
// SystemLibs are linker arguments after the static libraries.
SystemLibs []string `json:"system_libs"`
}
type Tool ¶
type Tool struct {
Name string `json:"name"`
Version string `json:"version"`
License string `json:"license"`
// Source is where the tool's source for Version is published, for the
// notices.
Source string `json:"source"`
Programs []string `json:"programs"`
// Archives maps each target name to the URL of its archive.
Archives map[string]string `json:"archives"`
// SourceArchive is the published source of Version, which a release
// ships beside its packages to meet a copyleft license's source offer.
SourceArchive *Download `json:"source_archive,omitempty"`
// Debian is the tool as Debian packages, which the Docker image
// installs in place of the archive.
Debian *DebianTool `json:"debian,omitempty"`
}
Tool is a prebuilt program the release ships beside the binary and runs as a separate process. Each target fetches its own published archive of it, which holds Programs at its root.
type ToolArchive ¶
type ToolArchive struct {
Tool string `json:"tool"`
Target string `json:"target"`
URL string `json:"url"`
}
ToolArchive is one tool's published archive for one target.
type Toolchain ¶
type Toolchain struct {
Name string `json:"name"`
Sources []Source `json:"sources,omitempty"`
Runtimes []Runtime `json:"runtimes,omitempty"`
Xcode string `json:"xcode,omitempty"`
}
Toolchain is the C and C++ compiler a target builds with. A toolchain with sources is a layer its recipe, native/recipe/toolchain/<name>, builds or mirrors from them. A toolchain with an Xcode version is the runner's own Xcode at that version and has no layer.