pigsdk

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package pigsdk stages Pig's extension SDKs (Go, Python, and Rust) into the config root so out-of-tree extension builds and packed runtime cells can use the API that matches the running binary.

Why this exists

An extension resolves its SDK through a local filesystem path: Go via a go.mod `replace`, Python via sys.path, Rust via a Cargo `path` dependency. Those SDK modules are nested/unpublished, so a machine with only the pig binary has nothing to point at and packed cells fail to build. The host SDK resolvers (coding/extension/host/runtimecell) use the staged copy, found through pigsdklock.StagedSDKDir.

The SDK bytes are embedded in the pig binary, so a staged copy always matches the running binary. Each build stages each language into its own directory named for the SDK's content hash, so PiG builds that share a config root (two installed versions, or stock PiG beside a Piglet Binary) never restage each other's SDKs or strand each other's extension builds. A warm start does a single marker read per language.

After a stage, the least recently used SDK directories of other builds beyond contentdirs.Keep per language are removed, and extension builds whose SDK is no longer staged are pruned. The unhashed directories a PiG that predates per-build directories stages into are never removed, and their builds are kept.

Boundary

Staging only writes source files to disk. It does not install or require a language toolchain. This is generic extension-host infrastructure in Stock Pig, not an optional product extension.

<config-root>/state/pigsdk/
  sdk-<hash16>/      go.mod + *.go              (Go)
  sdk-py-<hash16>/   pig_sdk/__init__.py + ...  (Python)
  sdk-rs-<hash16>/   Cargo.toml + src/*.rs      (Rust)
each with a .pig-sdk-version content-hash marker.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureSynced

func EnsureSynced(configRoot string) error

EnsureSynced stages every language SDK whose marker in this build's staged directory is missing or stale, then evicts the least recently used staged SDKs of other builds and drops the builds no remaining SDK can select.

Staging is the event that changes which builds are reachable, so eviction and pruning run only after a stage rather than on a timer. A warm start only records that this build's directories are in use.

func EnsureSyncedContext

func EnsureSyncedContext(ctx context.Context, configRoot string) error

EnsureSyncedContext is EnsureSynced with a caller-owned lock-wait lifetime.

func EnsureSyncedLang

func EnsureSyncedLang(configRoot, lang string) error

EnsureSyncedLang stages a single language SDK. Used by scaffolders that only need one language on disk.

func LiveFingerprints

func LiveFingerprints(configRoot string) (map[string]struct{}, error)

LiveFingerprints returns the fingerprints of every staged SDK still on disk: this build's, the other builds' retained ones, and the unhashed ones an older PiG uses. A cached extension build stays reachable while its recorded fingerprint is among them, because the build's cache key folds the SDK in.

func Prune

func Prune(configRoot string, _ bool, dryRun bool) (runtimecell.CacheReport, error)

Prune drops extension builds no staged SDK can select.

func RunCommand

func RunCommand(args []string, stdout, stderr io.Writer) int

RunCommand is the pre-session bundled command entrypoint. Returns -1 when the args do not target this command so the dispatcher can try the next.

It implements `pig reload`, the pre-session counterpart to the interactive /reload.

Both mean the same thing: make what is loaded match what is on disk. The interactive one reloads a live session's resources; this one stages the SDKs this binary embeds and drops extension builds no staged SDK can select, so the next build compiles against the current source. Staging also happens at startup and inside /reload, so this is the explicit form for a shell, not a step a user has to remember.

Reporting lives in `pig diagnose`, which already covers staged-versus-embedded alongside paths, auth, models, and environment. Splitting a second report out here would mean two places to look for one answer.

func SDKDirFor

func SDKDirFor(configRoot, lang string) (string, error)

SDKDirFor returns the directory this binary stages a language's SDK in, or an error for an unknown language.

func Sync

func Sync(configRoot string, _ bool) (map[string]int, runtimecell.CacheReport, error)

Sync force-stages every language SDK into this build's directories, then evicts and prunes as EnsureSynced does after a stage, all under the SDK stage lock. It returns the count written per language and the prune report.

func VerifyStaged

func VerifyStaged(configRoot string) func(stagedDir, buildType string) error

VerifyStaged reports whether the staged SDK for a build type matches the SDK embedded in this binary. Build types map to languages: "go" and "rust" stage an SDK, anything else needs none. Suitable for subprocess.Builder.SetStagedSDKVerifier.

Types

type StageStatus

type StageStatus struct {
	Lang     string // "go" | "python" | "rust"
	Dir      string // absolute directory this build stages the SDK in
	Staged   bool   // a marker file exists
	Current  bool   // the marker matches the embedded SDK
	Embedded string // hash of the SDK compiled into this binary
	OnDisk   string // hash recorded by the staged copy, "" when unstaged
}

StageStatus reports one language SDK's staged state against the SDK embedded in the running binary. This build reads only its own staged directory, so it is either current or not staged yet.

func Status

func Status(configRoot string) ([]StageStatus, error)

Status reports the staged state of every language SDK without changing anything. Used by diagnostics and by the extension builder to prove the staged SDK matches the binary before compiling against it.

Jump to

Keyboard shortcuts

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