From a65aed275239d698f479600ddd47feb898972946 Mon Sep 17 00:00:00 2001 From: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com> Date: Thu, 1 Feb 2024 00:14:48 -0600 Subject: [PATCH] Aquire zstd with fetchcontent for libdwarf 9 (#85) --- .github/workflows/build.yml | 62 ++++++++++++++++++++++--------- .github/workflows/test.yml | 62 ++++++++++++++++++++++--------- CMakeLists.txt | 55 ++++++++++++++++++++++++--- cmake/in/cpptrace-config-cmake.in | 1 + test/speedtest/CMakeLists.txt | 1 + 5 files changed, 142 insertions(+), 39 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 399e889..6805510 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,12 +19,21 @@ jobs: pip3 install colorama - name: libdwarf run: | + cd .. + mkdir zstd + cd zstd + git init + git remote add origin https://github.com/facebook/zstd.git + git fetch --depth 1 origin 63779c798237346c2b245c546c40b72a5a5913fe # 1.5.5 + git checkout FETCH_HEAD + make -j + sudo make install cd .. mkdir libdwarf cd libdwarf git init - git remote add origin https://github.com/flagarde/libdwarf-code.git - git fetch --depth 1 origin d1a559b7af0840194dfa51f7e3013e0f80614032 + git remote add origin https://github.com/jeremy-rifkin/libdwarf-code.git + git fetch --depth 1 origin b8cf3548112fd4cb68e8d4b89c6ce4348bc8745c git checkout FETCH_HEAD mkdir build cd build @@ -48,12 +57,21 @@ jobs: pip3 install colorama - name: libdwarf run: | + cd .. + mkdir zstd + cd zstd + git init + git remote add origin https://github.com/facebook/zstd.git + git fetch --depth 1 origin 63779c798237346c2b245c546c40b72a5a5913fe # 1.5.5 + git checkout FETCH_HEAD + make -j + sudo make install cd .. mkdir libdwarf cd libdwarf git init - git remote add origin https://github.com/flagarde/libdwarf-code.git - git fetch --depth 1 origin d1a559b7af0840194dfa51f7e3013e0f80614032 + git remote add origin https://github.com/jeremy-rifkin/libdwarf-code.git + git fetch --depth 1 origin b8cf3548112fd4cb68e8d4b89c6ce4348bc8745c git checkout FETCH_HEAD mkdir build cd build @@ -79,24 +97,34 @@ jobs: pip3 install colorama - name: libdwarf run: | - cd .. - mkdir libdwarf - cd libdwarf - git init - git remote add origin https://github.com/davea42/libdwarf-code.git - git fetch --depth 1 origin 6216e185863f41d6f19ab850caabfff7326020d7 - git checkout FETCH_HEAD - mkdir build - cd build if("${{matrix.compiler}}" -eq "gcc") { + cd .. + mkdir zstd + cd zstd + git init + git remote add origin https://github.com/facebook/zstd.git + git fetch --depth 1 origin 63779c798237346c2b245c546c40b72a5a5913fe # 1.5.5 + git checkout FETCH_HEAD + cd build/cmake + mkdir build + cd build + cmake .. -DZSTD_BUILD_SHARED=On -DZSTD_BUILD_SHARED=Off -DZSTD_LEGACY_SUPPORT=Off -DZSTD_BUILD_PROGRAMS=Off -DZSTD_BUILD_CONTRIB=Off -DZSTD_BUILD_TESTS=Off -G"Unix Makefiles" + make -j + make install + cd ../../../.. + mkdir libdwarf + cd libdwarf + git init + git remote add origin https://github.com/jeremy-rifkin/libdwarf-code.git + git fetch --depth 1 origin b8cf3548112fd4cb68e8d4b89c6ce4348bc8745c + git checkout FETCH_HEAD + mkdir build + cd build cmake .. -DPIC_ALWAYS=TRUE -DBUILD_DWARFDUMP=FALSE -G"Unix Makefiles" make -j make install - } else { - cmake .. -DPIC_ALWAYS=TRUE -DBUILD_DWARFDUMP=FALSE - msbuild INSTALL.vcxproj + cd ../../cpptrace } - cd ../../cpptrace - name: build run: | python3 ci/build-in-all-configs.py --${{matrix.compiler}} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c7cb37d..afbb080 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,12 +22,21 @@ jobs: pip3 install colorama - name: libdwarf run: | + cd .. + mkdir zstd + cd zstd + git init + git remote add origin https://github.com/facebook/zstd.git + git fetch --depth 1 origin 63779c798237346c2b245c546c40b72a5a5913fe # 1.5.5 + git checkout FETCH_HEAD + make -j + sudo make install cd .. mkdir libdwarf cd libdwarf git init - git remote add origin https://github.com/flagarde/libdwarf-code.git - git fetch --depth 1 origin d1a559b7af0840194dfa51f7e3013e0f80614032 + git remote add origin https://github.com/jeremy-rifkin/libdwarf-code.git + git fetch --depth 1 origin b8cf3548112fd4cb68e8d4b89c6ce4348bc8745c git checkout FETCH_HEAD mkdir build cd build @@ -49,12 +58,21 @@ jobs: - uses: actions/checkout@v4 - name: libdwarf run: | + cd .. + mkdir zstd + cd zstd + git init + git remote add origin https://github.com/facebook/zstd.git + git fetch --depth 1 origin 63779c798237346c2b245c546c40b72a5a5913fe # 1.5.5 + git checkout FETCH_HEAD + make -j + sudo make install cd .. mkdir libdwarf cd libdwarf git init - git remote add origin https://github.com/flagarde/libdwarf-code.git - git fetch --depth 1 origin d1a559b7af0840194dfa51f7e3013e0f80614032 + git remote add origin https://github.com/jeremy-rifkin/libdwarf-code.git + git fetch --depth 1 origin b8cf3548112fd4cb68e8d4b89c6ce4348bc8745c git checkout FETCH_HEAD mkdir build cd build @@ -95,24 +113,34 @@ jobs: pip3 install colorama - name: libdwarf run: | - cd .. - mkdir libdwarf - cd libdwarf - git init - git remote add origin https://github.com/davea42/libdwarf-code.git - git fetch --depth 1 origin 6216e185863f41d6f19ab850caabfff7326020d7 - git checkout FETCH_HEAD - mkdir build - cd build if("${{matrix.compiler}}" -eq "gcc") { + cd .. + mkdir zstd + cd zstd + git init + git remote add origin https://github.com/facebook/zstd.git + git fetch --depth 1 origin 63779c798237346c2b245c546c40b72a5a5913fe # 1.5.5 + git checkout FETCH_HEAD + cd build/cmake + mkdir build + cd build + cmake .. -DZSTD_BUILD_SHARED=On -DZSTD_BUILD_SHARED=Off -DZSTD_LEGACY_SUPPORT=Off -DZSTD_BUILD_PROGRAMS=Off -DZSTD_BUILD_CONTRIB=Off -DZSTD_BUILD_TESTS=Off -G"Unix Makefiles" + make -j + make install + cd ../../../.. + mkdir libdwarf + cd libdwarf + git init + git remote add origin https://github.com/jeremy-rifkin/libdwarf-code.git + git fetch --depth 1 origin b8cf3548112fd4cb68e8d4b89c6ce4348bc8745c + git checkout FETCH_HEAD + mkdir build + cd build cmake .. -DPIC_ALWAYS=TRUE -DBUILD_DWARFDUMP=FALSE -G"Unix Makefiles" make -j make install - } else { - cmake .. -DPIC_ALWAYS=TRUE -DBUILD_DWARFDUMP=FALSE - msbuild INSTALL.vcxproj + cd ../../cpptrace } - cd ../../cpptrace - name: build and test run: | python3 ci/test-all-configs.py --${{matrix.compiler}} diff --git a/CMakeLists.txt b/CMakeLists.txt index a4d9140..0bb00ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -339,11 +339,43 @@ endif() if(CPPTRACE_GET_SYMBOLS_WITH_LIBDWARF) target_compile_definitions(${target_name} PUBLIC CPPTRACE_GET_SYMBOLS_WITH_LIBDWARF) if(CPPTRACE_USE_EXTERNAL_LIBDWARF) + find_package(zstd) + if(TARGET libzstd_static) + add_library(ZSTD::ZSTD ALIAS libzstd_static) + set(ZSTD_FOUND TRUE) + endif() find_package(libdwarf REQUIRED) else() + include(FetchContent) + cmake_policy(SET CMP0074 NEW) + FetchContent_Declare( + zstd + GIT_REPOSITORY https://github.com/facebook/zstd.git + GIT_TAG 63779c798237346c2b245c546c40b72a5a5913fe # v1.5.5 + GIT_SHALLOW 1 + SOURCE_SUBDIR build/cmake + ) + # FetchContent_MakeAvailable(zstd) + FetchContent_GetProperties(zstd) + if(NOT zstd_POPULATED) + FetchContent_Populate(zstd) + set(ZSTD_BUILD_PROGRAMS OFF) + set(ZSTD_BUILD_CONTRIB OFF) + set(ZSTD_BUILD_TESTS OFF) + set(ZSTD_BUILD_STATIC ON) + set(ZSTD_BUILD_SHARED OFF) + set(ZSTD_LEGACY_SUPPORT OFF) + add_subdirectory("${zstd_SOURCE_DIR}/build/cmake" "${zstd_BINARY_DIR}") + endif() + + if(TARGET libzstd_static) + add_library(ZSTD::ZSTD ALIAS libzstd_static) + set(ZSTD_FOUND TRUE) + endif() + set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) - set(PIC_ALWAYS TRUE) - set(BUILD_DWARFDUMP FALSE) + # set(PIC_ALWAYS TRUE) + # set(BUILD_DWARFDUMP FALSE) include(FetchContent) FetchContent_Declare( libdwarf @@ -355,11 +387,24 @@ if(CPPTRACE_GET_SYMBOLS_WITH_LIBDWARF) # GIT_REPOSITORY https://github.com/jeremy-rifkin/libdwarf-lite.git # GIT_TAG c78e984f3abbd20f6e01d6f51819e826b1691f65 # v0.8.0 # GIT_TAG 71090c680b4c943448ba87a0f1f864f174e4edda # v0.9.0 - GIT_REPOSITORY https://github.com/flagarde/libdwarf-code.git - GIT_TAG d1a559b7af0840194dfa51f7e3013e0f80614032 + GIT_REPOSITORY https://github.com/jeremy-rifkin/libdwarf-code.git + GIT_TAG b8cf3548112fd4cb68e8d4b89c6ce4348bc8745c GIT_SHALLOW 1 ) - FetchContent_MakeAvailable(libdwarf) + # FetchContent_MakeAvailable(libdwarf) + FetchContent_GetProperties(libdwarf) + if(NOT libdwarf_POPULATED) + set(PIC_ALWAYS TRUE) + set(BUILD_DWARFDUMP FALSE) + # set(ENABLE_DECOMPRESSION FALSE) + FetchContent_Populate(libdwarf) + add_subdirectory("${libdwarf_SOURCE_DIR}" "${libdwarf_BINARY_DIR}") + target_include_directories( + dwarf + PRIVATE + ${zstd_SOURCE_DIR}/lib + ) + endif() endif() if(CPPTRACE_CONAN) target_link_libraries(${target_name} PRIVATE libdwarf::libdwarf) diff --git a/cmake/in/cpptrace-config-cmake.in b/cmake/in/cpptrace-config-cmake.in index 91483c6..a196307 100644 --- a/cmake/in/cpptrace-config-cmake.in +++ b/cmake/in/cpptrace-config-cmake.in @@ -4,6 +4,7 @@ # Dependencies if(@CPPTRACE_GET_SYMBOLS_WITH_LIBDWARF@) include(CMakeFindDependencyMacro) + find_dependency(zstd REQUIRED) find_dependency(libdwarf REQUIRED) endif() diff --git a/test/speedtest/CMakeLists.txt b/test/speedtest/CMakeLists.txt index 6cfd3ee..a6eb38d 100644 --- a/test/speedtest/CMakeLists.txt +++ b/test/speedtest/CMakeLists.txt @@ -36,6 +36,7 @@ FetchContent_MakeAvailable(googletest) set(cpptrace_DIR "../../build/foo/lib/cmake/cpptrace") set(libdwarf_DIR "../../build/foo/lib/cmake/libdwarf") +set(zstd_DIR "../../build/foo/lib/cmake/zstd") find_package(cpptrace REQUIRED) add_executable(speedtest speedtest.cpp)