Documentation
¶
Overview ¶
Package nativelib is what the CLI and packages ffi and native share about the native libraries that Go packages bind: golet-plugin.json, the file names of libraries on each platform, and where libraries are built and cached.
A package names its libraries in golet-plugin.json, next to its sources:
{"libraries": [{
"name": "adder",
"build": {"cargo": "./rust"},
"release": "https://github.com/me/app/releases/download/adder-v1",
"files": {"darwin-arm64": {"name": "libadder.dylib", "url": "…", "sha256": "…"}, …}
}]}
build is how the CLI builds the library from its sources (a Rust crate with cargo, a Zig package with zig build, a Swift package with swift build, on macOS); files are the published builds, one per platform (GOOS-GOARCH), which `golet native build` writes and apps download when they do not build the library themselves.
Index ¶
- Constants
- Variables
- func CachePath(f File) (string, error)
- func Ext(goos string) string
- func FileName(name, goos string) string
- func IsArchive(name string) bool
- func LocalDir(root, goos, goarch string) string
- func ModuleRoot(dir string) (string, error)
- func Skipped(name string) bool
- func SourceHash(dir string, b *Build) (string, error)
- type Build
- type File
- type Library
- type Manifest
Constants ¶
const ManifestFile = "golet-plugin.json"
ManifestFile is the file that names a package's native libraries.
const Universal = "darwin-universal"
Universal is the key of Library.Files for a build of macOS's two architectures in one file, as Swift libraries are published.
Variables ¶
var Targets = []string{"darwin-arm64", "darwin-amd64", "linux-amd64", "linux-arm64", "windows-amd64", "windows-arm64"}
Targets are the platforms Golet builds libraries for, as GOOS-GOARCH.
Functions ¶
func CachePath ¶
CachePath returns where a published file is kept in the user's cache: <cache>/golet/natives/<sha256>/<name>.
func FileName ¶
FileName returns the file of the library named name on goos when no published file names another: lib<name>.dylib, lib<name>.so and <name>.dll, as cargo and zig build them.
func IsArchive ¶
IsArchive reports whether a published file is a .tar.gz of the library and the files that go next to it, as the frameworks a Swift package brings, rather than the library itself.
func LocalDir ¶
LocalDir returns where the CLI puts the libraries it builds from sources in the module at root for goos/goarch, which programs that are not packaged apps look into too: <root>/.golet/native/<goos>-<goarch>.
func ModuleRoot ¶
ModuleRoot returns the directory of the go.mod that dir is in.
func Skipped ¶
Skipped reports whether a file or directory of a library's sources is left out of them: hidden ones, and those cargo, zig and npm write (target, zig-out, zig-cache, zig-pkg, node_modules).
func SourceHash ¶
SourceHash returns the hash of the sources of a library built in dir (the build's directory), which its arguments and macOS version are part of: the SHA-256 of the paths and contents of its files, but Skipped ones, with line endings as LF, so that checkouts on every platform agree.
Types ¶
type Build ¶
type Build struct {
// Cargo is the directory of the Rust crate (its Cargo.toml), whose
// crate-type includes "cdylib".
Cargo string `json:"cargo,omitempty"`
// Zig is the directory of the Zig package (its build.zig), which
// installs a dynamic library.
Zig string `json:"zig,omitempty"`
// Swift is the directory of the Swift package (its Package.swift),
// whose product named as the library is a dynamic library. Swift
// libraries build on macOS, universal, and go into the app's
// Frameworks with the frameworks they bring.
Swift string `json:"swift,omitempty"`
// Args are more arguments of `cargo build`, `zig build` or `swift
// build`.
Args []string `json:"args,omitempty"`
// MacOS is the oldest macOS the library runs on, when it needs a later
// one than the app's minimum or 12.0, as "13.0".
MacOS string `json:"macOS,omitempty"`
}
Build is how a library is built from its sources: exactly one of Cargo, Zig and Swift, a directory relative to the package's, written "./rust" to read as one.
type File ¶
type File struct {
Name string `json:"name"`
URL string `json:"url,omitempty"`
SHA256 string `json:"sha256"`
// SourceHash is the hash of the sources the file was built from (see
// SourceHash): the CLI builds the library of a local package from its
// sources only when they changed since, so that the package's own
// published files serve it until then, without Rust or Zig.
SourceHash string `json:"sourceHash,omitempty"`
}
File is a published build of a library.
type Library ¶
type Library struct {
// Name names the library, as ffi.New does: its files are
// lib<name>.dylib, lib<name>.so and <name>.dll by default (a leading
// "lib" is not doubled, and dropped on Windows).
Name string `json:"name"`
// Build builds the library from sources next to the package.
Build *Build `json:"build,omitempty"`
// Release is the URL of the directory the files are published in,
// as https://github.com/<owner>/<repo>/releases/download/<tag>.
Release string `json:"release,omitempty"`
// Files are the published builds, by GOOS-GOARCH, or Universal for
// one that serves both architectures of macOS.
Files map[string]File `json:"files,omitempty"`
}
Library is a native library a package binds.