chore: allow builing static binaries on alpine

This commit is contained in:
Marcus Holland-Moritz 2025-04-22 16:34:13 +02:00
parent d73994231d
commit 8c02bb6a14
3 changed files with 59 additions and 30 deletions

View File

@ -41,6 +41,25 @@ set(DWARFS_VERSION
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
set(CMAKE_FIND_LIBRARY_SUFFIXES
".a"
CACHE STRING "please look for static libs")
set(Boost_USE_STATIC_LIBS
ON
CACHE BOOL "only static boost libs")
set(BOOST_LINK_STATIC
"ON"
CACHE STRING "yes, really")
set(USE_STATIC_DEPS_ON_UNIX
ON
CACHE BOOL "yes")
set(GFLAGS_SHARED
OFF
CACHE BOOL "static")
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
list(APPEND PKG_CONFIG_EXECUTABLE "--static")
find_package(Boost 1.67 REQUIRED COMPONENTS date_time filesystem find_package(Boost 1.67 REQUIRED COMPONENTS date_time filesystem
program_options system) program_options system)
@ -56,37 +75,39 @@ set(compiler_only
ON ON
CACHE BOOL "only build thrift compiler") CACHE BOOL "only build thrift compiler")
set(FOLLY_HAVE_ELF OFF CACHE BOOL "" FORCE)
add_subdirectory(folly EXCLUDE_FROM_ALL) add_subdirectory(folly EXCLUDE_FROM_ALL)
add_subdirectory(fbthrift EXCLUDE_FROM_ALL) add_subdirectory(fbthrift EXCLUDE_FROM_ALL)
if(WITH_TESTS) if(WITH_TESTS)
# Download and unpack googletest at configure time # # Download and unpack googletest at configure time
configure_file(CMakeLists.txt.gtest googletest-download/CMakeLists.txt) # configure_file(CMakeLists.txt.gtest googletest-download/CMakeLists.txt)
execute_process( # execute_process(
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . # COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result # RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download) # WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download)
if(result) # if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}") # message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif() # endif()
execute_process( # execute_process(
COMMAND ${CMAKE_COMMAND} --build . # COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result # RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download) # WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download)
if(result) # if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}") # message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif() # endif()
# Prevent overriding the parent project's compiler/linker settings on Windows # # Prevent overriding the parent project's compiler/linker settings on Windows
set(gtest_force_shared_crt # set(gtest_force_shared_crt
ON # ON
CACHE BOOL "" FORCE) # CACHE BOOL "" FORCE)
# Add googletest directly to our build. This defines the gtest and gtest_main # # Add googletest directly to our build. This defines the gtest and gtest_main
# targets. # # targets.
add_subdirectory( # add_subdirectory(
${CMAKE_CURRENT_BINARY_DIR}/googletest-src # ${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL) # ${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL)
enable_testing() enable_testing()
include(GoogleTest) include(GoogleTest)
@ -129,6 +150,10 @@ add_executable(dwarfs-bin src/dwarfs.cpp)
add_executable(dwarfsck src/dwarfsck.cpp) add_executable(dwarfsck src/dwarfsck.cpp)
add_executable(dwarfsbench src/dwarfsbench.cpp) add_executable(dwarfsbench src/dwarfsbench.cpp)
foreach(tgt mkdwarfs dwarfs-bin dwarfsck dwarfsbench)
target_link_options(${tgt} PRIVATE -static -static-libgcc)
endforeach()
list(APPEND BINARY_TARGETS mkdwarfs dwarfs-bin dwarfsck dwarfsbench) list(APPEND BINARY_TARGETS mkdwarfs dwarfs-bin dwarfsck dwarfsbench)
if(WITH_TESTS) if(WITH_TESTS)
@ -309,6 +334,7 @@ install(FILES ${MAN_PAGES} DESTINATION share/man/man1)
install(DIRECTORY include/dwarfs DESTINATION include) install(DIRECTORY include/dwarfs DESTINATION include)
set(CPACK_SOURCE_GENERATOR "TBZ2") set(CPACK_SOURCE_GENERATOR "TBZ2")
set(CPACK_GENERATOR "TXZ")
set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")

View File

@ -27,7 +27,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <bits/types/struct_iovec.h> #include <sys/uio.h>
#include <folly/small_vector.h> #include <folly/small_vector.h>

View File

@ -25,7 +25,7 @@
#include <stdexcept> #include <stdexcept>
#include <cxxabi.h> #include <cxxabi.h>
#include <execinfo.h> // #include <execinfo.h>
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
@ -37,6 +37,7 @@ namespace dwarfs {
namespace { namespace {
#if 0
void backtrace(std::ostream& os) { void backtrace(std::ostream& os) {
const int stack_size = 5; const int stack_size = 5;
const int stack_offset = 2; const int stack_offset = 2;
@ -69,6 +70,8 @@ void backtrace(std::ostream& os) {
::free(strings); ::free(strings);
} }
#endif
} // namespace } // namespace
logger::level_type logger::parse_level(std::string_view level) { logger::level_type logger::parse_level(std::string_view level) {
@ -104,9 +107,9 @@ void stream_logger::write(level_type level, const std::string& output) {
std::lock_guard<std::mutex> lock(mx_); std::lock_guard<std::mutex> lock(mx_);
os_ << t << " " << output << "\n"; os_ << t << " " << output << "\n";
if (threshold_ == TRACE) { // if (threshold_ == TRACE) {
backtrace(os_); // backtrace(os_);
} // }
} }
} }