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 under <config-root>/state/pigsdk/sdk{,-py,-rs}.
The SDK bytes are embedded in the pig binary, so a staged copy always matches the running binary. Each language's stage is keyed on a content hash: any change to the embedded SDK re-stages on the next start; warm starts do a single marker read per language.
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/ go.mod + *.go (Go) sdk-py/ pig_sdk/__init__.py + ... (Python) sdk-rs/ Cargo.toml + src/*.rs (Rust) each with a .pig-sdk-version content-hash marker.
Index ¶
- func EnsureSynced(configRoot string) error
- func EnsureSyncedContext(ctx context.Context, configRoot string) error
- func EnsureSyncedLang(configRoot, lang string) error
- func LiveFingerprints(configRoot string) (map[string]string, error)
- func Prune(configRoot string, _ bool, dryRun bool) (runtimecell.CacheReport, error)
- func RunCommand(args []string, stdout, stderr io.Writer) int
- func SDKDir(configRoot string) string
- func SDKDirFor(configRoot, lang string) (string, error)
- func Sync(configRoot string) (map[string]int, error)
- func VerifyStaged(configRoot string) func(stagedDir, buildType string) error
- type StageStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureSynced ¶
EnsureSynced stages every language SDK whose on-disk marker is missing or stale, then drops builds the new SDK can no longer select.
Staging is the event that strands builds: the cache key folds the SDK in, so the moment a re-stage happens every build against the previous SDK becomes unreachable. Pruning here rather than on a timer means the cache is bounded by how often the SDK actually changes.
func EnsureSyncedContext ¶
EnsureSyncedContext is EnsureSynced with a caller-owned lock-wait lifetime.
func EnsureSyncedLang ¶
EnsureSyncedLang stages a single language SDK. Used by scaffolders that only need one language on disk.
func LiveFingerprints ¶
LiveFingerprints returns the staged-SDK fingerprint per build type. A cached extension build is reachable only while its recorded fingerprint appears here, 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 the staged SDKs can no longer select.
func RunCommand ¶
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 their fingerprint proves came from an older SDK, 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 SDKDir ¶
SDKDir returns the staged Go SDK directory. Kept for callers that scaffold Go extensions (pig extension init).
func SDKDirFor ¶
SDKDirFor returns the staged directory for a language, or an error for an unknown language.
func VerifyStaged ¶
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 staged directory
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. A staged copy that does not match the binary silently builds extensions against the wrong SDK, so the mismatch has to be observable rather than inferred from an extension misbehaving.
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.