loader

package
v0.1.0-preview.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package loader discovers and loads the official lance-c shared library without cgo.

Discovery order:

  1. 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.
  2. 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.
  3. 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

View Source
const EnvLibPath = "LANCE_LIB_PATH"

EnvLibPath names the environment variable that points at the liblance_c shared library file.

Variables

View Source
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 exposes no runtime version symbol, 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 Library

type Library struct {
	// contains filtered or unexported fields
}

Library is a loaded lance-c shared library.

func Load

func Load() (*Library, error)

Load returns the process-wide lance-c library, opening it on first use. Failed attempts are not cached; a later call retries discovery.

func (*Library) Lookup

func (l *Library) Lookup(name string) (uintptr, error)

Lookup resolves an exported C symbol.

func (*Library) Path

func (l *Library) Path() string

Path returns the configured path when LANCE_LIB_PATH was used, the cache path when a compiled-in bundle was used, or the platform library name when the system loader resolved the library.

Jump to

Keyboard shortcuts

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