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 ¶
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 ¶
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:
- Explicit directories from OverrideEnvVars (e.g., GOMLX_CUDA_LIB_DIR).
- Bare LibNames via the OS dynamic linker (LD_LIBRARY_PATH, /etc/ld.so.cache, system paths / Windows PATH).
- Library subdirectories under RootEnvVars (e.g., CUDA_PATH, CUDA_HOME, CUDA_ROOT, CONDA_PREFIX).
- 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 ¶
Close closes the underlying shared library handle. Safe to call multiple times.
func (*Library) RegisterFunc ¶
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 ¶
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.
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.