native

package
v0.0.0-...-831ccf3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: GPL-3.0 Imports: 24 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 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

View Source
const (
	InputsPath = "native/inputs.json"
	RecipeDir  = "native/recipe"
	LockPath   = "native/lock.json"
)
View Source
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.

View Source
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.

View Source
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"
View Source
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.

View Source
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

func CacheRoot() (string, error)

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

func ExportLines(vars []EnvVar) string

ExportLines renders vars as POSIX shell export lines for eval.

func Fetch

func Fetch(ctx context.Context, cacheRoot string, l Layer) (string, error)

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

func FetchFile(ctx context.Context, cacheRoot string, d Download) (string, error)

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

func LayerDir(cacheRoot string, l Layer) string

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

func LibsDigest(in Inputs, t Target, recipe fs.FS) (string, error)

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 Program

func Program(t Target, name string) string

Program is the file name of a tool's program on t.

func Published

func Published(ctx context.Context, base string, id LayerID) (bool, error)

func StaleLock

func StaleLock(root string) ([]string, error)

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

func ToolchainDigest(in Inputs, t Target, recipe fs.FS) (string, error)

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.

func WantRepo

func WantRepo(root string) (Inputs, []LayerID, error)

Types

type Bundle

type Bundle struct {
	Libs  Layer
	Tools []string
	Env   []EnvVar
}

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.

func FetchedBundle

func FetchedBundle(root, cacheRoot string, in Inputs, t Target) (Bundle, error)

type Compilers

type Compilers struct {
	CC  string `json:"cc"`
	CXX string `json:"cxx"`
}

Compilers is a toolchain layer's metadata.

func ReadCompilers

func ReadCompilers(layerDir string) (Compilers, error)

ReadCompilers reads the compilers of the toolchain layer at layerDir as absolute paths.

type Component

type Component struct {
	Source
	License string `json:"license"`
}

Component is a source the libs layer builds and the binary links.

type DebianTool

type DebianTool struct {
	Dir      string              `json:"dir"`
	Packages map[string]Download `json:"packages"`
}

DebianTool is a tool's Debian package for each Linux target, which installs Programs into Dir.

type Download

type Download struct {
	URL    string `json:"url"`
	SHA256 string `json:"sha256"`
}

Download is a file pinned by its content.

type EnvVar

type EnvVar struct {
	Name, Value string
}

func CgoEnv

func CgoEnv(layerDir string, md Metadata, cc Compilers, t Target) []EnvVar

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.

const (
	GatePR     Gate = "pr"
	GateNative Gate = "native"
)

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 LoadInputs(path string) (Inputs, error)

func ParseInputs

func ParseInputs(data []byte) (Inputs, error)

func (Inputs) Component

func (in Inputs) Component(name string) (Component, error)

func (Inputs) Layers

func (in Inputs) Layers(t Target, recipe fs.FS) ([]LayerID, error)

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) Packager

func (in Inputs) Packager(name, target string) (Packager, error)

func (Inputs) Target

func (in Inputs) Target(name string) (Target, error)

func (Inputs) Tool

func (in Inputs) Tool(name string) (Tool, error)

func (Inputs) ToolArchives

func (in Inputs) ToolArchives() []ToolArchive

ToolArchives lists every tool's archive for every target, in input order.

func (Inputs) Toolchain

func (in Inputs) Toolchain(t Target) (Toolchain, error)

type Kind

type Kind string

Kind names what a layer holds.

const (
	KindToolchain Kind = "toolchain"
	KindLibs      Kind = "libs"
)

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.

func Want

func Want(in Inputs, recipe fs.FS) ([]LayerID, error)

Want lists the layers of every target in the table.

func (LayerID) AssetName

func (id LayerID) AssetName() string

func (LayerID) Tag

func (id LayerID) Tag() string

func (LayerID) URL

func (id LayerID) URL(base string) string

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 LoadLock

func LoadLock(path string) (Lock, error)

func Pin

func Pin(ctx context.Context, base string, ids []LayerID) (Lock, error)

Pin hashes the published asset of each layer under base.

func (Lock) Pinned

func (l Lock) Pinned(id LayerID) (Layer, error)

func (Lock) PinnedTool

func (l Lock) PinnedTool(a ToolArchive) (PinnedTool, error)

func (Lock) Stale

func (l Lock) Stale(want []LayerID) []string

func (Lock) StaleTools

func (l Lock) StaleTools(want []ToolArchive) []string

StaleTools describes each way the lock's tool archives differ from want.

func (Lock) Write

func (l Lock) Write(path string) error

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

func ReadMetadata(layerDir string) (Metadata, error)

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.

func (Toolchain) Layered

func (tc Toolchain) Layered() bool

func (Toolchain) Source

func (tc Toolchain) Source(name string) Source

Jump to

Keyboard shortcuts

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