Documentation
¶
Overview ¶
Package fetch brings a C library of lib/ into a Go project before it is built, so that the cgo, ccgo and purego drivers find it there. It reads a library.Citation, downloads each target's published archive (checking its SHA-256 before it uses a byte of it), and lays out a Go package in the project's folder:
cgo include/ and lib/<goos>_<goarch>/<static library>, with a cgo file whose #cgo
directives name them through ${SRCDIR}, so no CGO_* variable and no system install is
needed
c2go the translated Go source of each target, copied as published
purego lib/<goos>_<goarch>/<shared library>, embedded into the program and registered with
library.Provide, so it travels inside the binary
The project imports that package once (a blank import) to use it. Go runs no code before a build, so this is a step the project runs first: go generate with `go tool ext bundle fetch`.
Index ¶
Constants ¶
const ( CGo = "cgo" C2Go = "c2go" PureGo = "purego" )
The drivers fetch lays out.
Variables ¶
var ErrOffline = errors.New("fetch: not cached and offline")
ErrOffline is an archive that is not cached when Options.Offline is set.
Functions ¶
func Fetch ¶
Fetch lays the library out in o.Dir for every target and driver, replacing what fetch wrote there before. It writes nothing until every archive has been downloaded and verified.
func HTTPS ¶
HTTPS is the download fetch uses when Options.Fetch is nil: a GET over HTTPS that follows only HTTPS redirects. A caller that wraps Fetch, to report a download, calls it.
func Shared ¶
func Shared(ctx context.Context, so SharedOptions) (string, error)
Shared returns the path of the purego shared library the citation publishes for o.Target, verified against the citation. A copy kept by an earlier call is used when it still matches its digest; otherwise the archive is taken from the archive cache or downloaded, checked against the citation's SHA-256, and the library is extracted again. It writes by renaming complete files into place, so processes that bring in the same library at once agree on its contents.
Types ¶
type Limits ¶
type Limits struct {
ArchiveBytes int64 // the downloaded archive; default 256 MiB
FileBytes int64 // one extracted file; default 256 MiB
Files int // files extracted from one archive; default 10000
}
Limits bound what an archive may hold.
type Options ¶
type Options struct {
Citation library.Citation
// Drivers to lay out: CGo, C2Go and PureGo. At least one.
Drivers []string
// Targets are "goos/goarch" pairs; at least one.
Targets []string
// Dir is the package directory to write, inside the project's module.
Dir string
// Package is the package name of the files written; default the library name without "ext_".
Package string
// Fetch downloads a URL; nil uses an HTTPS GET with http.DefaultClient. A program with its own
// downloader (ext has one) passes it here.
Fetch func(ctx context.Context, url string) (io.ReadCloser, error)
// Cache is a directory of verified archives, reused across runs; empty is the user cache's
// ext-go/archives. Offline refuses any download not already there.
Cache string
Offline bool
Limits Limits
}
Options say what to fetch and where.
type Selection ¶
type Selection struct {
Target string `json:"target"`
Driver string `json:"driver"`
Asset library.Asset `json:"asset"`
}
Selection is the exact pinned asset used for one target and driver.
type SharedOptions ¶
type SharedOptions struct {
Target string
// Dir/<library>/<archive sha256>/<file>, beside <file>.sha256, the digest of the file itself.
Dir string
// Fetch, Cache, Offline and Limits are as in Options.
}
SharedOptions say which shared library to bring in at run time and where to keep it.