Documentation
¶
Overview ¶
Package loader discovers and loads the official lance-c shared library without cgo.
Discovery order:
- LANCE_LIB_PATH, which must name an existing regular file. When it is set it is the only candidate; a bad value fails loudly instead of silently falling back to another library.
- In the default (untagged) build, a compiled-in artifact bundle registered by a generated platform selector. The bundle is verified and unpacked into a private user cache before it is loaded. Once a bundle is registered for the running target, cache, extraction, or loading errors fail loudly; the loader does not fall back to the system copy.
- The platform library name (liblance_c.so on Linux, liblance_c.dylib on macOS, lance_c.dll on Windows), resolved by the platform loader. Unix honors LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, ldconfig caches and the usual system directories. Windows applies the process's DLL search policy, which can include the application, system and current directories and PATH.
Builds tagged lance_external_lib omit bundle, cache, and decompression code entirely and use only the environment and system-loader steps.
The loader package does not embed a bundle itself: generated per-platform artifact modules and the selector files that register them are supplied by the module that imports this package. This module ships its platform selectors in internal/bundled, which every public entry point blank-imports; without a selector for the running target, the default build uses the system loader.
The library is loaded at most once per process and is never unloaded. lance-c owns a Tokio runtime, thread-local error state and handles that may outlive a dataset, so unloading the library while native threads or callbacks may still run is not safe. Callers that need a different library must start a new process; changing LANCE_LIB_PATH after a successful Load has no effect.
Platform loading uses purego's dlopen/dlsym bindings on Linux and macOS and LoadLibrary/GetProcAddress on Windows. purego v0.10 does not expose the Windows loading entry points, so the Windows implementation uses golang.org/x/sys/windows directly.
Index ¶
Constants ¶
const EnvCacheDir = "LANCE_CACHE_DIR"
EnvCacheDir names the environment variable that overrides the root of the private bundled-library cache. An empty value falls back to os.UserCacheDir. It is ignored when EnvLibPath is set.
const EnvLibPath = "LANCE_LIB_PATH"
EnvLibPath names the environment variable that points at the liblance_c shared library file.
Variables ¶
var ErrNotFound = errors.New("lance-c shared library not found")
ErrNotFound reports that no lance-c library was configured or found by the platform loader. Errors caused by an explicitly configured but unusable LANCE_LIB_PATH do not wrap ErrNotFound.
Functions ¶
func RegisterBundle ¶
func RegisterBundle(b Bundle)
RegisterBundle installs the descriptor compiled in by a generated platform selector. It must be called during package initialization, before Load.
Linking more than one selector for the same process is a packaging bug, so duplicate registration panics instead of silently choosing one payload.
Types ¶
type Bundle ¶
type Bundle struct {
// Module is the import path of the artifact module that supplied the
// payload. It is used in diagnostics.
Module string
// Target is the Go target the payload was packaged for, as GOOS/GOARCH.
Target string
// LibraryName is the platform shared-library basename for Target.
LibraryName string
// Compressed is a zstd frame containing the shared library bytes.
Compressed []byte
// CompressedSize is len(Compressed) as recorded at packaging time.
CompressedSize int64
// CompressedSHA256 is the lowercase SHA-256 of Compressed.
CompressedSHA256 string
// UncompressedSize is the exact shared-library size.
UncompressedSize int64
// UncompressedSHA256 is the lowercase SHA-256 of the shared library.
UncompressedSHA256 string
// UpstreamCommit is the lance-c commit claimed by the packaging process.
// lance_c_version() reports only the binding release, so the loader cannot
// verify this claim from the shared library itself.
UpstreamCommit string
// HeaderSHA256 is the SHA-256 of the lance.h used during packaging. It is a
// packaging-time claim, not a property verified from the binary.
HeaderSHA256 string
}
Bundle describes one compressed lance-c payload compiled into a generated platform selector. The payload and metadata are data only; importing the artifact module does not link, load, or execute native code.
A Bundle is immutable after registration. Its fields are generated from the exact library and header used during packaging.
type BundleInfo ¶
BundleInfo is the packaging metadata of a compiled-in artifact. The upstream commit and header hash are claims recorded when the artifact was built; they are not read from or verified against the loaded binary.
type Library ¶
type Library struct {
// contains filtered or unexported fields
}
Library is a loaded lance-c shared library.
func Load ¶
Load returns the process-wide lance-c library, opening it on first use. Failed attempts are not cached; a later call retries discovery.
type Source ¶
type Source uint8
Source identifies how a successfully opened library was selected.
const ( // SourceUnknown means this process has not successfully opened a library. SourceUnknown Source = iota // SourceEnv means LANCE_LIB_PATH named the opened file. SourceEnv // SourceBundle means the compiled-in artifact was extracted and opened. SourceBundle // SourceSystem means the platform loader resolved the library name. SourceSystem )
type State ¶
type State struct {
// Loaded reports whether this process has successfully opened a library.
Loaded bool
// Source and Path describe that successful open. Path is the explicit
// path, the extracted bundle cache path, or the platform library name for
// a system lookup.
Source Source
Path string
// Bundle is non-nil only when Source is SourceBundle.
Bundle *BundleInfo
}
State is a side-effect-free snapshot of the loaded library.