patchpkg

package
v0.0.0-...-c3cab01 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

patchpkg patches packages to fix common linker errors.

Index

Constants

This section is empty.

Variables

View Source
var (
	// SystemLibSearchPaths match the system library paths for common Linux
	// distributions.
	SystemLibSearchPaths = []string{
		"/lib*/*-linux-gnu",
		"/lib*",
		"/var/lib*/*/lib*",
	}

	// EnvLibrarySearchPath matches the paths in the LIBRARY_PATH
	// environment variable.
	EnvLibrarySearchPath = filepath.SplitList(os.Getenv("LIBRARY_PATH"))

	// EnvLDLibrarySearchPath matches the paths in the LD_LIBRARY_PATH
	// environment variable.
	EnvLDLibrarySearchPath = filepath.SplitList(os.Getenv("LD_LIBRARY_PATH"))

	// CUDALibSearchPaths match the common installation directories for CUDA
	// libraries.
	CUDALibSearchPaths = []string{

		"/opt/cuda/lib*",
		"/opt/nvidia/lib*",
		"/usr/local/cuda/lib*",
		"/usr/local/nvidia/lib*",

		"/lib*/nvidia",
		"/lib*/cuda",
		"/usr/lib*/nvidia",
		"/usr/lib*/cuda",
		"/usr/local/lib*",
		"/usr/local/lib*/nvidia",
		"/usr/local/lib*/cuda",
	}
)

Functions

func FindSharedLibrary

func FindSharedLibrary(name string, searchPath ...string) iter.Seq[SharedLibrary]

FindSharedLibrary searches the directories in searchPath for a shared library. It yields any libraries in the search path directories that have name as a prefix. For example, "libcuda.so" will match "libcuda.so", "libcuda.so.1", and "libcuda.so.550.107.02". The underlying file is only valid for a single iteration, after which it is closed.

The search path may contain filepath.Glob patterns. See SystemLibSearchPaths for some predefined search paths. If name is an absolute path, then FindSharedLibrary opens it directly and doesn't perform any searching.

Types

type DerivationBuilder

type DerivationBuilder struct {
	// Out is the output directory that will contain the built derivation.
	// If empty it defaults to $out, which is typically set by Nix.
	Out string

	// Glibc is an optional store path to an alternative glibc version. If
	// it's set, the builder will patch ELF binaries to use its shared
	// libraries and dynamic linker.
	Glibc string

	// Gcc is an optional store path to an alternative gcc version. If
	// it's set, the builder will patch ELF binaries to use its shared
	// libraries (such as libstdc++.so).
	Gcc string

	RestoreRefs bool
	// contains filtered or unexported fields
}

DerivationBuilder patches an existing package.

func NewDerivationBuilder

func NewDerivationBuilder() (*DerivationBuilder, error)

NewDerivationBuilder initializes a new DerivationBuilder from the current Nix build environment.

func (*DerivationBuilder) Build

func (d *DerivationBuilder) Build(ctx context.Context, pkgStorePath string) error

Build applies patches to a package store path and puts the result in the d.Out directory.

type SharedLibrary

type SharedLibrary struct {
	*os.File

	// LinkerName is the soname without any version suffix (libfoo.so). It
	// is typically a symlink pointing to Soname. The build-time linker
	// looks for this name by default.
	LinkerName string

	// Soname is the shared object name from the library's DT_SONAME field.
	// It usually includes a version number suffix (libfoo.so.1). Other ELF
	// binaries that depend on this library typically specify this name in
	// the DT_NEEDED field.
	Soname string

	// RealName is the absolute path to the file that actually contains the
	// library code. It is typically the soname plus a minor version and
	// release number (libfoo.so.1.0.0).
	RealName string
}

SharedLibrary describes an ELF shared library (object).

Note that the various name fields document the common naming and versioning conventions, but it is possible for a library to deviate from them.

For an introduction to Linux shared libraries, see https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

func OpenSharedLibrary

func OpenSharedLibrary(name string) (SharedLibrary, error)

OpenSharedLibrary opens a shared library file. Unlike with ld, name must be an exact path. To search for a library in the usual locations, use FindSharedLibrary instead.

func (lib SharedLibrary) CopyAndLink(dir string) error

CopyAndLink copies the shared library to dir and creates the LinkerName and Soname symlinks for it. It creates dir if it doesn't already exist.

func (SharedLibrary) LogValue

func (lib SharedLibrary) LogValue() slog.Value

Jump to

Keyboard shortcuts

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