Documentation
¶
Overview ¶
Package wasm prepares a project for tarantool-wasm (github.com/tarantool/tarantool-wasm-rs) until tt builds WebAssembly components itself: it turns a released native module into a binary rock in a registry inside the project, declares the wasm dependency on it and puts tarawasm, which builds the components for now, where the project's builds find it.
It is a stopgap, not the shape of the feature: the rock belongs on a rock server and the components to build backends of tt. Until then the releases tt knows about, and the checksums it holds them to, are written down here.
Index ¶
- Constants
- Variables
- func BuildRock(dir string, release Release, platform Platform, module []byte) (string, error)
- func DeclaredVersion(projectDir string) (string, error)
- func DefaultCacheDir() string
- func FormatToolchain(language string, statuses []ToolStatus) string
- func IndexRegistry(dir string) error
- func Languages() []string
- func PackRocks(ctx context.Context, opts PackOptions) ([]string, error)
- func SDKMismatches(components []Component, version string) []string
- func SDKWarnings(projectDir string) []string
- func Templates(language string) []string
- func Versions() []string
- type Component
- type ComponentStatus
- type Fetcher
- type NewOptions
- type NewReport
- type Options
- type PackOptions
- type Platform
- type Release
- type Report
- type StatusReport
- type Tarawasm
- type TarawasmLayout
- type Tool
- type ToolAsset
- type ToolRelease
- type ToolStatus
- type ToolchainOptions
- type ToolchainResult
Constants ¶
const DefaultVersion = "0.1.0"
DefaultVersion is the release a project is prepared for when none is named.
const ( // RegistryDir is the rock server prepare writes the wasm rock to, relative // to the project: under .tarantool, which belongs to the machine rather // than the repository, since the rock is the build for this host. The // dependency names it so, and tt resolves it against the project. RegistryDir = scope.ProjectDirName + "/registry" )
const ReleasesEnv = "TT_WASM_RELEASES"
ReleasesEnv names a JSON file of releases tt uses instead of its own table, by version: the assets of a mirror, say.
const RockName = "wasm"
RockName is the name of the rock the native module is packed as; it is what require('wasm') loads, and what the project declares.
Variables ¶
var ( // ErrUnknownRelease reports a tarantool-wasm version tt has no table entry // for. ErrUnknownRelease = errors.New("unknown release") // ErrUnsupportedPlatform reports a host the release has no native build // for. ErrUnsupportedPlatform = errors.New("unsupported platform") // ErrChecksum reports a downloaded asset whose checksum differs from the // one tt holds the release to. ErrChecksum = errors.New("checksum mismatch") // ErrNoManifest reports a directory that is not a tt project. ErrNoManifest = errors.New("not a tt project") // ErrPython reports a Python that cannot host tarawasm. ErrPython = errors.New("no suitable python") )
var ( // ErrUnknownLanguage reports a language tt knows no toolchain of. ErrUnknownLanguage = errors.New("unknown language") // ErrToolchain reports tools the user has to install first. ErrToolchain = errors.New("the toolchain is not ready") // ErrNoTarawasm reports a command that needs the tarawasm of the project. ErrNoTarawasm = errors.New("no tarawasm in the project") // ErrSDKVersion reports a component built against another SDK than the // runtime the package declares. ErrSDKVersion = errors.New("SDK version mismatch") // ErrComponentExists reports a component the manifest already declares. ErrComponentExists = errors.New("component already declared") )
var ErrNotReady = errors.New("the project is not ready")
ErrNotReady reports a project tt wasm status found something missing in.
Functions ¶
func BuildRock ¶
BuildRock packs module, the native build of platform, as the binary rock of the release in dir, and returns the rock's path. The rock holds the rockspec, lib/<module> and the rock_manifest upstream LuaRocks writes for a binary rock. It is written to a temporary file and renamed into place, so the registry never serves half a rock.
func DeclaredVersion ¶
DeclaredVersion returns the version of the wasm rock the manifest declares, when its constraint names one; empty otherwise.
func DefaultCacheDir ¶
func DefaultCacheDir() string
DefaultCacheDir is where assets are cached: <user cache>/tt/wasm, or nowhere when the system names no cache directory.
func FormatToolchain ¶
func FormatToolchain(language string, statuses []ToolStatus) string
FormatToolchain renders the statuses of a toolchain one tool a line.
func IndexRegistry ¶
IndexRegistry writes the manifest of the rock server dir from the binary rocks it holds, so that a dependency declaring dir as its registry resolves and installs from it. Files that are not binary rocks are left out.
func Languages ¶
func Languages() []string
Languages returns the languages tt knows the toolchains of.
func PackRocks ¶
func PackRocks(ctx context.Context, opts PackOptions) ([]string, error)
PackRocks packs the rock of every platform of a release into a directory and indexes it, so that the directory, served over HTTP or uploaded next to the assets of the release, is the rock server tt wasm prepare --rock-server declares the dependency from: one for every machine, unlike the registry prepare packs for its own.
func SDKMismatches ¶
SDKMismatches returns a line for every component whose SDK is of another release than version, the runtime of the package: a component builds against the WIT of its SDK, and the runtime serves the WIT of its own.
func SDKWarnings ¶
SDKWarnings returns the SDK mismatches of the package in projectDir, for a build to warn of; nothing when it declares no exact wasm version.
Types ¶
type Component ¶
type Component struct {
// Name is the component's name in the manifest.
Name string
// Dir is the absolute directory of the tarawasm project.
Dir string
// Language is the language of the component, from tarawasm.json.
Language string
// Output is the component tarawasm builds, relative to Dir.
Output string
// SDKVersion is the tarantool-wasm release the component's SDK lock pins;
// empty for a project without one.
SDKVersion string
}
Component is a component of the package that tarawasm builds: the directory of its build holds a tarawasm project.
func FindComponents ¶
FindComponents returns the components of the package in projectDir that tarawasm builds, in the order of their names.
type ComponentStatus ¶
type ComponentStatus struct {
Component
// SDKRestored is true when the SDK the component pins is in its
// .tarawasm, as tt wasm prepare puts it.
SDKRestored bool
}
ComponentStatus is what tt wasm status found of a component.
type Fetcher ¶
type Fetcher struct {
// CacheDir holds the assets, by release version; empty disables the cache.
CacheDir string
// Client is the HTTP client; nil is http.DefaultClient.
Client *http.Client
}
Fetcher downloads release assets, keeping each one, once its checksum is right, in a cache directory, so that preparing another project, or the same one again, does not download it again.
type NewOptions ¶
type NewOptions struct {
// ProjectDir is the package the component is added to.
ProjectDir string
// Name is the component's name in the manifest.
Name string
// Dir is its directory, relative to the project; empty is Name.
Dir string
// Language is the language of the component.
Language string
// World names its WIT world, and so the component it builds:
// dist/<world>.wasm. Empty is the name of the component.
World string
// Template, when set, is the template laid over the component.
Template string
// Fetcher downloads the tools tt installs.
Fetcher Fetcher
// Tarawasm runs the tarawasm of the project.
Tarawasm Tarawasm
// Resolve re-resolves the lock after the manifest changed.
Resolve func(ctx context.Context) error
// Progress receives one line per step.
Progress io.Writer
}
NewOptions configure NewComponent.
type NewReport ¶
type NewReport struct {
// Dir is the component's directory, relative to the project.
Dir string
// Output is the component it builds, relative to Dir.
Output string
// Module is the Lua module the template uses the component with; empty
// without a template.
Module string
}
NewReport is what NewComponent did.
func NewComponent ¶
func NewComponent(ctx context.Context, opts NewOptions) (*NewReport, error)
NewComponent adds a WebAssembly component to the package:
- puts the toolchain of the language in place, as Prepare does;
- has tarawasm create the project of the component, on the SDK of the wasm release the package declares, leaving the module to the rock;
- writes its .gitignore, of what tarawasm generates;
- declares it in the manifest, built by tarawasm all, and re-resolves the lock.
The project has to have been prepared: tarawasm comes from tt wasm prepare.
type Options ¶
type Options struct {
// ProjectDir is the project to prepare: the directory of its manifest.
ProjectDir string
// Version is the tarantool-wasm release; empty is DefaultVersion.
Version string
// Fetcher downloads the release assets.
Fetcher Fetcher
// Tarawasm installs tarawasm; SkipTarawasm leaves it out.
Tarawasm Tarawasm
SkipTarawasm bool
// Language, when set, has tarawasm set up the toolchain of that language.
Language string
// RockServer, when set, is a rock server that serves the rocks of the
// release, which tt wasm rock packs: the dependency is declared from it,
// and nothing is packed in the project.
RockServer string
// Declare declares the dependency rock on the registry and re-resolves the
// lock. It reports whether the manifest already declared it, in which case
// the declaration was left alone.
Declare func(ctx context.Context, name, constraint, registry string) (bool, error)
// PrepareEnv writes the project's .env/activate.sh, when it is missing.
PrepareEnv func() error
// Progress receives one line per step.
Progress io.Writer
}
Options configure Prepare.
type PackOptions ¶
type PackOptions struct {
// Dir is the directory the rocks and their index go to: a rock server.
Dir string
// Version is the release; empty is DefaultVersion.
Version string
// Fetcher downloads the assets.
Fetcher Fetcher
// Progress receives one line per rock.
Progress io.Writer
}
PackOptions configure PackRocks.
type Platform ¶
type Platform struct {
// GOOS and GOARCH name the hosts the build runs on.
GOOS string `json:"goos"`
GOARCH string `json:"goarch"`
// Asset is the file name of the release asset.
Asset string `json:"asset"`
// SHA256 is the asset's checksum, as GitHub publishes it for the asset.
SHA256 string `json:"sha256"`
// RockArch is the LuaRocks arch of the rock: what go-luarocks accepts as
// the host's (linux-x86_64, macosx-aarch64).
RockArch string `json:"rock_arch"`
// Module is the file the rock carries under lib/: wasm.so, or wasm.dylib
// on macOS, where Tarantool looks for C modules as ?.dylib only.
Module string `json:"module"`
}
Platform is one native build of a release.
type Release ¶
type Release struct {
// Version is the release version, without the v of its tag.
Version string `json:"version"`
// RockRevision is the revision of the rockspec tt writes for it.
RockRevision int `json:"rock_revision"`
// SDKAsset and SDKMD5 name the release's SDK archive: the source the
// rockspec points at. It is the one asset all platforms share, so the
// rockspec, and the checksum the lock records from it, is the same on
// every host.
SDKAsset string `json:"sdk_asset"`
SDKMD5 string `json:"sdk_md5"`
// Platforms are the native builds of the release.
Platforms []Platform `json:"platforms"`
// BaseURL is where the assets are: <base>/v<version>/<asset>. Empty is
// the releases of tarantool-wasm-rs on GitHub.
BaseURL string `json:"base_url,omitempty"`
}
Release is a tarantool-wasm-rs release tt can prepare a project for.
func LookupRelease ¶
LookupRelease returns the release of version.
func (Release) HostPlatform ¶
HostPlatform returns the build of the release for the host tt runs on.
func (Release) RockFileName ¶
RockFileName is the file name of the binary rock of platform.
func (Release) RockVersion ¶
RockVersion is the version of the rock: <version>-<revision>.
type Report ¶
type Report struct {
// Release and Platform are what the project was prepared with.
Release Release
Platform Platform
// Rock is the path of the rock in the project's registry; empty when the
// rock comes from RockServer.
Rock string
// Registry is the registry the dependency is declared from.
Registry string
// Declared is false when the manifest already declared the dependency.
Declared bool
// Tarawasm is where tarawasm went; nil when it was skipped.
Tarawasm *TarawasmLayout
// TarawasmInstalled is false when an installed tarawasm was kept.
TarawasmInstalled bool
// Languages are the languages whose toolchains were checked.
Languages []string
// Components are the components whose SDK was restored.
Components []string
}
Report is what Prepare did.
func Prepare ¶
Prepare prepares the project for tarantool-wasm:
- downloads the host's native module of the release, checked against the sha256 tt holds it to, and packs it as a binary rock into the project's registry (RegistryDir), indexing the registry;
- declares wasm = { version = <release>, registry = RegistryDir } and re-resolves the lock, so the next tt package build installs it into .rocks/lib/tarantool, where require('wasm') finds it;
- installs tarawasm into .tarantool and links it as .tarantool/bin/tarawasm, which component builds find by name;
- checks that the components tarawasm builds use the SDK of the release;
- for the language of each such component, and Language, installs the tools tt installs into .tarantool, checks the tools the user installs and selects the toolchain for tarawasm (see EnsureToolchain);
- restores the SDK of each such component, which a checkout lacks;
- writes .env/activate.sh, which puts .tarantool/bin on the shell's PATH.
Every step can be run again: an unchanged rock is rewritten byte for byte, a declaration is kept, an installed tarawasm is relinked.
type StatusReport ¶
type StatusReport struct {
// Declared and Registry are the wasm rock the manifest declares; empty
// when it declares none, or no exact version.
Declared string
Registry string
// Rock is the rock of this host in the registry; empty when it is not
// there.
Rock string
// Tarawasm is the tarawasm of the project; empty when it is not there.
Tarawasm string
// Components are the components tarawasm builds.
Components []ComponentStatus
// Languages and Toolchains are their languages and what was found of the
// toolchain of each.
Languages []string
Toolchains map[string][]ToolStatus
// Problems are what keeps the project from building, one a line.
Problems []string
}
StatusReport is what tt wasm status found, changing nothing.
type Tarawasm ¶
type Tarawasm struct {
// Python is the interpreter the environment is made with.
Python string
// Source is what pip installs; empty is the pinned commit.
Source string
// Reinstall makes the environment anew even when it is there.
Reinstall bool
// Output receives the output of python and pip.
Output io.Writer
// contains filtered or unexported fields
}
Tarawasm installs tarawasm into a virtual environment of the project and links it into the project's bin directory.
func (Tarawasm) Install ¶
Install installs tarawasm under root and returns where it went. An environment already holding tarawasm is kept unless Reinstall is set; the link is always pointed at it.
func (Tarawasm) UseToolchain ¶
func (t Tarawasm) UseToolchain( ctx context.Context, program, language string, unlinked map[string]string, ) error
UseToolchain selects the local toolchain of language for tarawasm's builds: tarawasm toolchain use saves it in tarawasm's user settings, refusing a toolchain that is not ready. EnsureToolchain has put the tools in place or told what to install first; tarawasm's own installation, which runs sudo apt-get install on Linux, is never run.
program is the link in the project's bin directory, and the directory goes in front of tarawasm's PATH, as it does for the project's builds, after the directories of the programs tt installed without linking them.
type TarawasmLayout ¶
type TarawasmLayout struct {
// Env is the virtual environment.
Env string
// Link is the link the project's builds find tarawasm by.
Link string
}
TarawasmLayout is where a project's tarawasm lives.
type Tool ¶
type Tool struct {
// Name is the program, as the builds find it on PATH.
Name string
// VersionArgs make it print its version.
VersionArgs []string
// Minimum and Below bound the version it must have: at least Minimum,
// below Below; either may be empty.
Minimum string
Below string
// Hint says how to get it, for a tool the user installs.
Hint string
// Dir, when set, is an environment variable naming the directory whose
// bin/ holds the tool, as WASI_SDK_PATH does for clang; PATH is the
// fallback.
Dir string
// Release is the build tt installs into the project; nil for a tool the
// user installs. tt installs nothing into the system.
Release *ToolRelease
}
Tool is a program the components of a language are built with: one tt installs into the project, or one the user installs and tt only checks.
func (Tool) Requirement ¶
Requirement renders the versions the tool must have.
type ToolRelease ¶
type ToolRelease struct {
// Version is the version tt installs.
Version string
// Assets are its downloads, by host: GOOS/GOARCH.
Assets map[string]ToolAsset
// Wheel is true for a tool whose assets are Python wheels, which pip
// installs into the environment of tarawasm from the file tt downloaded.
Wheel bool
// Tree is the path of the program in an archive tt keeps whole: the
// archive is unpacked into the version directory, its top directory
// stripped. Empty for an asset that is, or holds, the program alone.
Tree string
// Overlays are more archives of each host unpacked over the tree, as
// Binaryen is over TinyGo.
Overlays map[string][]ToolAsset
// Links are more programs of the tree linked into the project's bin.
Links []string
// Unlinked keeps the program out of the project's bin, where it would
// stand in for a tool of the system in every build: clang. tarawasm is
// told where it is instead, in each component (see Tool.ProjectSetting).
Unlinked bool
// Dir names the version directory; empty is the name of the tool.
Dir string
}
ToolRelease is the build of a tool tt installs into the project.
type ToolStatus ¶
type ToolStatus struct {
Tool Tool
// Path is where it was found; empty when it was not.
Path string
// Version is the version it reports; empty when it was not found.
Version string
// OK is true for a tool found in a version it may have.
OK bool
}
ToolStatus is what a check found of a tool.
func CheckTool ¶
func CheckTool(ctx context.Context, tool Tool, path string) ToolStatus
CheckTool finds tool in the directories of path (a PATH value), runs it for its version and checks the version against the bounds of the tool.
func (ToolStatus) Problem ¶
func (s ToolStatus) Problem() string
Problem says what is wrong with the tool; empty when nothing is.
type ToolchainOptions ¶
type ToolchainOptions struct {
// Root is the .tarantool of the project.
Root string
// Language is the language whose toolchain is ensured.
Language string
// Fetcher downloads the tools tt installs.
Fetcher Fetcher
// TarawasmEnv is the environment of tarawasm, where pip installs; empty
// when the project has no tarawasm.
TarawasmEnv string
// Output receives the output of pip.
Output io.Writer
}
ToolchainOptions configure EnsureToolchain.
type ToolchainResult ¶
type ToolchainResult struct {
// Statuses are the tools of the toolchain, as checked.
Statuses []ToolStatus
// Unlinked are the programs tt installed without linking them into the
// project's bin, by tool: tarawasm is told of them in each component.
Unlinked map[string]string
}
ToolchainResult is what EnsureToolchain found and installed.
func EnsureToolchain ¶
func EnsureToolchain(ctx context.Context, opts ToolchainOptions) (*ToolchainResult, error)
EnsureToolchain installs the tools of the language that tt installs into the project, and checks every tool of the language: a tool tt installed where it installed it, a tool the user installs as a build finds it, in the project's bin directory first and then on PATH. A tool the user has to install, or to upgrade, is an error wrapping ErrToolchain; nothing is installed into the system.