dynlib

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 9 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 dynlib isolates all Pure-Go dynamic shared library loading (currently backed by github.com/ebitengine/purego) behind a minimal internal API.

Keeping purego confined to this package allows compute-cuda to migrate to a future Go standard library FFI / dynamic-loading mechanism by replacing only internal/dynlib.

Index

Constants

This section is empty.

Variables

View Source
var ErrLibraryNotFound = stderrors.New("shared library not found")

ErrLibraryNotFound is returned when none of the candidate shared libraries could be opened.

Functions

func LinuxTargetArch

func LinuxTargetArch() string

LinuxTargetArch returns the NVIDIA CUDA targets subdirectory name for the current GOARCH (e.g., "x86_64-linux", "sbsa-linux" / "aarch64-linux").

Types

type Library

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

Library represents a dynamically opened shared library (.so / .dll).

func Open

func Open(candidates []string) (*Library, error)

Open attempts to open the first available shared library from candidates. If none can be opened, it returns an error wrapping ErrLibraryNotFound with details from each attempt.

func OpenWithSearch

func OpenWithSearch(cfg SearchConfig) (*Library, error)

OpenWithSearch locates and opens the first matching shared library according to cfg:

  1. Explicit directories from OverrideEnvVars (e.g., GOMLX_CUDA_LIB_DIR).
  2. Bare LibNames via the OS dynamic linker (LD_LIBRARY_PATH, /etc/ld.so.cache, system paths / Windows PATH).
  3. Library subdirectories under RootEnvVars (e.g., CUDA_PATH, CUDA_HOME, CUDA_ROOT, CONDA_PREFIX).
  4. Standard fallback directories (StandardDirs, including expanded globs newest-first).

If no candidate can be opened, it returns an error wrapping ErrLibraryNotFound that clearly lists candidate filenames, checked environment variables (with their current values), all searched locations, underlying loader errors, and cfg.Hint.

func (*Library) Close

func (l *Library) Close() error

Close closes the underlying shared library handle. Safe to call multiple times.

func (*Library) Handle

func (l *Library) Handle() uintptr

Handle returns the underlying OS library handle.

func (*Library) Path

func (l *Library) Path() string

Path returns the library name or path that succeeded in Open.

func (*Library) RegisterFunc

func (l *Library) RegisterFunc(fnPtr any, name string) error

RegisterFunc resolves symbol name and binds it to the Go function variable pointed to by fnPtr. Unlike purego.RegisterLibFunc, missing symbols return an error rather than panicking.

func (*Library) RegisterFuncFallback

func (l *Library) RegisterFuncFallback(fnPtr any, names ...string) (string, error)

RegisterFuncFallback tries each symbol name in order and binds the first one found to fnPtr. This is useful for versioned ABI symbols such as CUDA's *_v2 suffixes across driver versions.

func (*Library) Sym

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

Sym resolves a symbol address by name in the loaded library.

type SearchConfig

type SearchConfig struct {
	// DisplayName is a human-readable name for the library (e.g., "CUDA driver library").
	DisplayName string
	// LibNames are candidate shared library filenames tried in priority order
	// (e.g., ["libcuda.so.1", "libcuda.so"]).
	LibNames []string
	// OverrideEnvVars are environment variables containing explicit directory lists
	// (separated by os.PathListSeparator) searched BEFORE OS dynamic linker defaults.
	OverrideEnvVars []string
	// LinkerEnvVars are standard OS loader environment variables (e.g., "LD_LIBRARY_PATH"
	// on Unix, "PATH" on Windows) reported in diagnostics alongside OS linker defaults.
	LinkerEnvVars []string
	// RootEnvVars are installation-root environment variables (e.g., "CUDA_PATH", "CUDA_HOME",
	// "CUDA_ROOT", "CONDA_PREFIX", "VIRTUAL_ENV") whose platform library subdirectories are searched.
	RootEnvVars []string
	// RootSubdirs are relative subdirectories appended to each non-empty RootEnvVars entry
	// (e.g., ["lib64", "lib", "targets/x86_64-linux/lib"]). Entries may contain filepath.Glob patterns.
	RootSubdirs []string
	// StandardDirs are OS/distribution fallback directories (may contain filepath.Glob patterns
	// such as "/usr/local/cuda-*/lib64", which are expanded newest-first).
	StandardDirs []string
	// Hint is an actionable remediation message appended when no library is found.
	Hint string
}

SearchConfig configures multi-path shared library discovery and diagnostic error reporting.

Jump to

Keyboard shortcuts

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