Files
scylladb/dist/CMakeLists.txt
Avi Kivity 07c5edcc30 tools: add patchelf utility
We use patchelf to rewrite the dynamic loader (known as the interpreter)
of the binaries we ship, so we can point to our shipped dynamic loader,
which is compatible with our binaries, rather than rely on the distribution's
dynamic loader, which is likely to be incompatible.

Upstream patchelf losing compatibity [1] with Linux 5.17 and below.
This change was also picked up by Fedora 42, so we cannot update the
toolchain to that distribution until we have an alternative.

Here we add a minimal patchelf alternative. It was mostly written by
Claude. It is minimal in that it only supports --set-interpreter and
--print-interpreter, and works well enough for our needs. We still use
the original patchelf for --remove-rpath; this reduces our maintenance
needs.

[1] 43b75fbc9f
[2] 4b015255d1

Closes scylladb/scylladb#24695
2025-06-30 07:24:05 +03:00

145 lines
4.7 KiB
CMake

set(unstripped_dist_pkg
${CMAKE_BINARY_DIR}/$<CONFIG>/dist/tar/${Scylla_PRODUCT}-unstripped-${Scylla_VERSION}-${Scylla_RELEASE}.${CMAKE_SYSTEM_PROCESSOR}.tar.gz)
add_custom_command(
OUTPUT ${unstripped_dist_pkg}
COMMAND
scripts/create-relocatable-package.py
--build-dir ${CMAKE_BINARY_DIR}/$<CONFIG>
--node-exporter-dir ${CMAKE_BINARY_DIR}/node_exporter
--debian-dir ${CMAKE_BINARY_DIR}/debian
${unstripped_dist_pkg}
DEPENDS
${CMAKE_BINARY_DIR}/$<CONFIG>/scylla
${CMAKE_BINARY_DIR}/$<CONFIG>/iotune
${CMAKE_BINARY_DIR}/$<CONFIG>/patchelf
${CMAKE_BINARY_DIR}/node_exporter/node_exporter
${CMAKE_BINARY_DIR}/debian
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_custom_target(dist-server-deb ALL
# the --builddir should match the paths specified by
# "packages" in dist/docker/debian/build_docker.sh
COMMAND reloc/build_deb.sh
--reloc-pkg ${unstripped_dist_pkg}
--builddir ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/debian
DEPENDS ${unstripped_dist_pkg}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_custom_target(dist-server-rpm ALL
COMMAND reloc/build_rpm.sh
--reloc-pkg ${unstripped_dist_pkg}
--builddir ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/redhat
DEPENDS ${unstripped_dist_pkg}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_custom_target(dist-server
DEPENDS dist-server-deb dist-server-rpm)
function(add_stripped name)
# ${name} must be an absolute path
add_custom_command(
OUTPUT
${name}.debug
${name}.stripped
COMMAND ${CMAKE_SOURCE_DIR}/scripts/strip.sh ${name}
DEPENDS ${name})
endfunction()
add_stripped("${CMAKE_BINARY_DIR}/$<CONFIG>/scylla")
# app_iotune is located in seastar/apps/iotune
if(TARGET Seastar::iotune)
set(iotune_src "$<TARGET_FILE:Seastar::iotune>")
else()
set(iotune_src "$<TARGET_FILE:app_iotune>")
endif()
set(iotune_dst "${CMAKE_BINARY_DIR}/$<CONFIG>/iotune")
add_custom_command(
OUTPUT "${iotune_dst}"
COMMAND ${CMAKE_COMMAND} -E copy "${iotune_src}" "${iotune_dst}"
DEPENDS $<OUTPUT_CONFIG:${iotune_src}>)
add_stripped("${iotune_dst}")
add_stripped("${CMAKE_BINARY_DIR}/$<CONFIG>/patchelf")
find_program(TAR_COMMAND tar
REQUIRED)
execute_process(
COMMAND
${CMAKE_SOURCE_DIR}/install-dependencies.sh --print-node-exporter-filename
OUTPUT_VARIABLE
node_exporter_filename
OUTPUT_STRIP_TRAILING_WHITESPACE)
add_custom_command(
OUTPUT
${CMAKE_BINARY_DIR}/node_exporter/node_exporter
COMMAND
${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/node_exporter
COMMAND
${TAR_COMMAND}
-C ${CMAKE_BINARY_DIR}/node_exporter
-xpf ${node_exporter_filename}
--no-same-owner
--strip-components=1)
add_stripped(${CMAKE_BINARY_DIR}/node_exporter/node_exporter)
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/debian
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/debian/debian_files_gen.py
--build-dir ${CMAKE_BINARY_DIR}
--output-dir ${CMAKE_BINARY_DIR}/debian
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
set(stripped_dist_pkg
"${CMAKE_BINARY_DIR}/$<CONFIG>/dist/tar/${Scylla_PRODUCT}-${Scylla_VERSION}-${Scylla_RELEASE}.${CMAKE_SYSTEM_PROCESSOR}.tar.gz")
add_custom_command(
OUTPUT
${stripped_dist_pkg}
COMMAND
${CMAKE_SOURCE_DIR}/scripts/create-relocatable-package.py
--stripped
--build-dir ${CMAKE_BINARY_DIR}/$<CONFIG>
--node-exporter-dir ${CMAKE_BINARY_DIR}/node_exporter
--debian-dir ${CMAKE_BINARY_DIR}/debian
${stripped_dist_pkg}
DEPENDS
${CMAKE_BINARY_DIR}/$<CONFIG>/scylla.stripped
${CMAKE_BINARY_DIR}/$<CONFIG>/patchelf.stripped
${CMAKE_BINARY_DIR}/$<CONFIG>/iotune.stripped
${CMAKE_BINARY_DIR}/node_exporter/node_exporter.stripped
${CMAKE_BINARY_DIR}/debian
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_custom_target(dist-server-tar
DEPENDS ${stripped_dist_pkg})
add_custom_target(package
${CMAKE_COMMAND} -E copy ${stripped_dist_pkg} ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${Scylla_PRODUCT}-package.tar.gz
DEPENDS ${stripped_dist_pkg})
set(dist_pkgs
"${stripped_dist_pkg}")
dist_submodule(cqlsh cqlsh dist_pkgs)
dist_submodule(python3 python3 dist_pkgs)
set(unified_dist_pkg
"${CMAKE_BINARY_DIR}/$<CONFIG>/dist/tar/${Scylla_PRODUCT}-unified-${Scylla_VERSION}-${Scylla_RELEASE}.${CMAKE_SYSTEM_PROCESSOR}.tar.gz")
add_custom_command(
OUTPUT
"${unified_dist_pkg}"
COMMAND
${CMAKE_SOURCE_DIR}/unified/build_unified.sh
--build-dir ${CMAKE_BINARY_DIR}/$<CONFIG>
--pkgs "${dist_pkgs}"
--unified-pkg ${unified_dist_pkg}
DEPENDS
${dist_pkgs}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
VERBATIM)
add_custom_target(dist-unified ALL
DEPENDS ${unified_dist_pkg})
add_custom_target(dist)
add_dependencies(dist
dist-cqlsh
dist-python3
dist-server)
add_subdirectory(debuginfo)