chore: allow builing static binaries on alpine

This commit is contained in:
Marcus Holland-Moritz 2025-04-22 16:34:13 +02:00
parent 21caae54b3
commit 08eee0656a
3 changed files with 60 additions and 31 deletions

View File

@ -41,6 +41,25 @@ set(DWARFS_VERSION
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
program_options system)
@ -53,37 +72,39 @@ set(compiler_only
ON
CACHE BOOL "only build thrift compiler")
set(FOLLY_HAVE_ELF OFF CACHE BOOL "" FORCE)
add_subdirectory(folly EXCLUDE_FROM_ALL)
add_subdirectory(fbthrift EXCLUDE_FROM_ALL)
if(WITH_TESTS)
# Download and unpack googletest at configure time
configure_file(CMakeLists.txt.gtest googletest-download/CMakeLists.txt)
execute_process(
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download)
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(
COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download)
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
# # Download and unpack googletest at configure time
# configure_file(CMakeLists.txt.gtest googletest-download/CMakeLists.txt)
# execute_process(
# COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
# RESULT_VARIABLE result
# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download)
# if(result)
# message(FATAL_ERROR "CMake step for googletest failed: ${result}")
# endif()
# execute_process(
# COMMAND ${CMAKE_COMMAND} --build .
# RESULT_VARIABLE result
# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download)
# if(result)
# message(FATAL_ERROR "Build step for googletest failed: ${result}")
# endif()
# Prevent overriding the parent project's compiler/linker settings on Windows
set(gtest_force_shared_crt
ON
CACHE BOOL "" FORCE)
# # Prevent overriding the parent project's compiler/linker settings on Windows
# set(gtest_force_shared_crt
# ON
# CACHE BOOL "" FORCE)
# Add googletest directly to our build. This defines the gtest and gtest_main
# targets.
add_subdirectory(
${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL)
# # Add googletest directly to our build. This defines the gtest and gtest_main
# # targets.
# add_subdirectory(
# ${CMAKE_CURRENT_BINARY_DIR}/googletest-src
# ${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL)
enable_testing()
include(GoogleTest)
@ -126,6 +147,10 @@ add_executable(dwarfs-bin src/dwarfs.cpp)
add_executable(dwarfsck src/dwarfsck.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)
if(WITH_TESTS)
@ -273,10 +298,11 @@ install(
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(FILES man/dwarfs.1 man/mkdwarfs.1 DESTINATION share/man/man1)
# install(FILES man/dwarfs.1 man/mkdwarfs.1 DESTINATION share/man/man1)
install(DIRECTORY include/dwarfs DESTINATION include)
set(CPACK_SOURCE_GENERATOR "TBZ2")
set(CPACK_GENERATOR "TXZ")
set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")

View File

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

View File

@ -25,7 +25,7 @@
#include <stdexcept>
#include <cxxabi.h>
#include <execinfo.h>
// #include <execinfo.h>
#include <boost/date_time/posix_time/posix_time.hpp>
@ -37,6 +37,7 @@ namespace dwarfs {
namespace {
#if 0
void backtrace(std::ostream& os) {
const int stack_size = 5;
const int stack_offset = 2;
@ -69,6 +70,8 @@ void backtrace(std::ostream& os) {
::free(strings);
}
#endif
} // namespace
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_);
os_ << t << " " << output << "\n";
if (threshold_ == TRACE) {
backtrace(os_);
}
// if (threshold_ == TRACE) {
// backtrace(os_);
// }
}
}