Internals of rattler-build#
Making Packages Relocatable with Rattler-Build#
Often, the most challenging aspect of building a package using rattler-build
is making it relocatable. A relocatable package can be installed into any
prefix, allowing it to be used outside the environment in which it was built.
This is in contrast to a non-relocatable package, which can only be utilized
within its original build environment.
rattler-build
automatically performs the following actions to make packages
relocatable:
- Binary object file conversion: Binary object files are converted to use
relative paths using
install_name_tool
on macOS andpatchelf
on Linux. This uses$ORIGIN
for elf files on Linux and@loader_path
for Mach-O files on macOS to make the rpath relative to the executable / shared library. - Text file prefix registration: Any text file without NULL bytes containing the placeholder prefix have the registered prefix replaced with the install prefix.
- Binary file prefix detection and registration: Binary files containing
the build prefix can be automatically registered. The registered files will
have their build prefix replaced with the install prefix at install time.
This works by padding the install prefix with null terminators, such that the
length of the binary file remains the same. The build prefix must be long
enough to accommodate any reasonable installation prefix. On macOS and Linux,
rattler-build
pads the build prefix to 255 characters by appending_placehold
to the end of the build directory name.