From 7bac26279fc130cfe0935bd9629352ebb972abe2 Mon Sep 17 00:00:00 2001 From: Saikari Date: Mon, 30 Dec 2024 22:29:08 +0300 Subject: [PATCH] [lief] add new port LIEF-0.16.0 (#42374) Co-authored-by: WangWeiLin-MV <156736127+WangWeiLin-MV@users.noreply.github.com> --- ports/lief/fix-cmakelists.patch | 49 ++++++++++++ ports/lief/fix-liefconfig-cmake-in.patch | 24 ++++++ ports/lief/fix-vcpkg-includes.patch | 52 ++++++++++++ ports/lief/portfile.cmake | 79 +++++++++++++++++++ ports/lief/vcpkg.json | 79 +++++++++++++++++++ .../test_ports/vcpkg-ci-lief/portfile.cmake | 7 ++ .../vcpkg-ci-lief/project/CMakeLists.txt | 9 +++ .../test_ports/vcpkg-ci-lief/project/main.cpp | 10 +++ scripts/test_ports/vcpkg-ci-lief/vcpkg.json | 30 +++++++ versions/baseline.json | 4 + versions/l-/lief.json | 9 +++ 11 files changed, 352 insertions(+) create mode 100644 ports/lief/fix-cmakelists.patch create mode 100644 ports/lief/fix-liefconfig-cmake-in.patch create mode 100644 ports/lief/fix-vcpkg-includes.patch create mode 100644 ports/lief/portfile.cmake create mode 100644 ports/lief/vcpkg.json create mode 100644 scripts/test_ports/vcpkg-ci-lief/portfile.cmake create mode 100644 scripts/test_ports/vcpkg-ci-lief/project/CMakeLists.txt create mode 100644 scripts/test_ports/vcpkg-ci-lief/project/main.cpp create mode 100644 scripts/test_ports/vcpkg-ci-lief/vcpkg.json create mode 100644 versions/l-/lief.json diff --git a/ports/lief/fix-cmakelists.patch b/ports/lief/fix-cmakelists.patch new file mode 100644 index 00000000000000..bb087a6f1538d1 --- /dev/null +++ b/ports/lief/fix-cmakelists.patch @@ -0,0 +1,49 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index fc2b679..4ec92b9 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -113,19 +113,7 @@ message(STATUS "CMAKE_CXX_IMPLICIT_LINK_LIBRARIES: ${CMAKE_CXX_IMPLICIT_LINK_LIB + message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") + message(STATUS "CMAKE_MSVC_RUNTIME_LIBRARY: ${CMAKE_MSVC_RUNTIME_LIBRARY}") + +-if(LIEF_INSTALL) +- if(UNIX) +- include(GNUInstallDirs) +- set(CMAKE_INSTALL_LIBDIR "lib") +- else() +- set(CMAKE_INSTALL_LIBDIR "lib") +- set(CMAKE_INSTALL_DATADIR "share") + set(CMAKE_INSTALL_INCLUDEDIR "include") +- set(CMAKE_INSTALL_BINDIR "bin") +- set(CMAKE_INSTALL_DATAROOTDIR "share") +- message(STATUS "Setting installation destination to: ${CMAKE_INSTALL_PREFIX}") +- endif() +-endif() + + # LIEF Source definition + # ====================== +@@ -318,7 +306,9 @@ else() + ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/third-party/internal/span.hpp) + endif() + +-target_link_libraries(LIB_LIEF PRIVATE lief_spdlog) ++find_package(fmt CONFIG REQUIRED) ++find_package(spdlog CONFIG REQUIRED) ++target_link_libraries(LIB_LIEF PRIVATE fmt::fmt spdlog::spdlog) + + if(ANDROID AND LIEF_LOGGING) + target_link_libraries(LIB_LIEF PUBLIC log) +@@ -507,11 +497,11 @@ if(LIEF_INSTALL) + endif() + + install( +- TARGETS LIB_LIEF lief_spdlog ++ TARGETS LIB_LIEF + EXPORT LIEFExport + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +- RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libraries + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + + install( diff --git a/ports/lief/fix-liefconfig-cmake-in.patch b/ports/lief/fix-liefconfig-cmake-in.patch new file mode 100644 index 00000000000000..637686f1466812 --- /dev/null +++ b/ports/lief/fix-liefconfig-cmake-in.patch @@ -0,0 +1,24 @@ +diff --git a/cmake/LIEFConfig.cmake.in b/cmake/LIEFConfig.cmake.in +index dba7363..7f88f98 100644 +--- a/cmake/LIEFConfig.cmake.in ++++ b/cmake/LIEFConfig.cmake.in +@@ -69,7 +69,7 @@ macro(LIEF_load_targets lib_type) + return() + endif () + +- if("${lib_type}" STREQUAL "static") ++ if(1) + # Need to find all dependencies even if they're private when LIEF is + # compiled statically + include(CMakeFindDependencyMacro) +@@ -93,6 +93,10 @@ macro(LIEF_load_targets lib_type) + if(NOT @LIEF_DISABLE_FROZEN@ AND @LIEF_OPT_FROZEN_EXTERNAL@) + find_dependency(frozen) + endif() ++ ++ find_dependency(tl-expected) ++ find_dependency(fmt) ++ check_required_components(lief) + endif() + + # Include the respective targets file diff --git a/ports/lief/fix-vcpkg-includes.patch b/ports/lief/fix-vcpkg-includes.patch new file mode 100644 index 00000000000000..1bcbdcac4bc6e1 --- /dev/null +++ b/ports/lief/fix-vcpkg-includes.patch @@ -0,0 +1,52 @@ +diff --git a/src/BinaryStream/BinaryStream.cpp b/src/BinaryStream/BinaryStream.cpp +index 83e618c..6447b7b 100644 +--- a/src/BinaryStream/BinaryStream.cpp ++++ b/src/BinaryStream/BinaryStream.cpp +@@ -15,7 +15,7 @@ + */ + #include "LIEF/BinaryStream/BinaryStream.hpp" + #include "LIEF/DWARF/enums.hpp" +-#include "third-party/utfcpp.hpp" ++#include + + #include + #include +diff --git a/src/PE/Builder.cpp b/src/PE/Builder.cpp +index 8cbe7b2..994e9bf 100644 +--- a/src/PE/Builder.cpp ++++ b/src/PE/Builder.cpp +@@ -21,7 +21,7 @@ + + #include "logging.hpp" + +-#include "third-party/utfcpp.hpp" ++#include + + + #include "LIEF/PE/Builder.hpp" +diff --git a/src/logging.cpp b/src/logging.cpp +index 39936fe..f5e1345 100644 +--- a/src/logging.cpp ++++ b/src/logging.cpp +@@ -20,7 +20,7 @@ + #include "logging.hpp" + + #include "spdlog/spdlog.h" +-#include "spdlog/fmt/bundled/args.h" ++#include + #include "spdlog/sinks/stdout_color_sinks.h" + #include "spdlog/sinks/basic_file_sink.h" + #include "spdlog/sinks/android_sink.h" +diff --git a/src/utils.cpp b/src/utils.cpp +index 0acbba1..b624a1d 100644 +--- a/src/utils.cpp ++++ b/src/utils.cpp +@@ -22,7 +22,7 @@ + #include "LIEF/utils.hpp" + #include "LIEF/errors.hpp" + +-#include "third-party/utfcpp.hpp" ++#include + + #include "LIEF/config.h" + #include "logging.hpp" diff --git a/ports/lief/portfile.cmake b/ports/lief/portfile.cmake new file mode 100644 index 00000000000000..fb092865883107 --- /dev/null +++ b/ports/lief/portfile.cmake @@ -0,0 +1,79 @@ +vcpkg_download_distfile( + FIX_FMT_V11_JOIN_LINUX_INCLUDE_MEMORY_PATCH + URLS https://github.com/lief-project/LIEF/commit/41166332a2435fdb7d2bdc5c73f9ff9b442c5459.patch?full_index=1 + FILENAME fix-fmt-v11-join-linux-include-memory-41166332a2435fdb7d2bdc5c73f9ff9b442c5459.patch + SHA512 14d5f7380352bd340c16447905b8185dbd2d977c8ba245e01d982fe7fbbdffb71004b9d4fdd732bc13e71a11aa3f46a4822cdeb2277e2cec6b841492d0de5606 +) + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO lief-project/LIEF + REF ${VERSION} + SHA512 7df75fab6c7023e37a6a4d27fac8dcb4200e0235625fc5952bb23cedb2e582a37fb67ee471c1ae953c0b205fd9cca5538a835f65ef80a771f72dc7ff68000ed9 + HEAD_REF master + PATCHES + fix-cmakelists.patch + fix-liefconfig-cmake-in.patch + fix-vcpkg-includes.patch + "${FIX_FMT_V11_JOIN_LINUX_INCLUDE_MEMORY_PATCH}" +) + +file(REMOVE_RECURSE "${SOURCE_PATH}/third-party") + +vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS + FEATURES + "c-api" LIEF_C_API # C API + "enable-json" LIEF_ENABLE_JSON # Enable JSON-related APIs + "extra-warnings" LIEF_EXTRA_WARNINGS # Enable extra warning from the compiler + "logging" LIEF_LOGGING # Enable logging + "logging-debug" LIEF_LOGGING_DEBUG # Enable debug logging + + "use-ccache" LIEF_USE_CCACHE # Use ccache to speed up compilation + + "elf" LIEF_ELF # Build LIEF with ELF module + "pe" LIEF_PE # Build LIEF with PE module + "macho" LIEF_MACHO # Build LIEF with MachO module + + "oat" LIEF_OAT # Build LIEF with OAT module + "dex" LIEF_DEX # Build LIEF with DEX module + "vdex" LIEF_VDEX # Build LIEF with VDEX module + "art" LIEF_ART # Build LIEF with ART module +) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + ${FEATURE_OPTIONS} + -DLIEF_EXAMPLES=OFF + + # Build with external vcpkg dependencies + -DLIEF_OPT_MBEDTLS_EXTERNAL=ON + -DLIEF_EXTERNAL_SPDLOG=ON + -DLIEF_OPT_NLOHMANN_JSON_EXTERNAL=ON + -DLIEF_OPT_FROZEN_EXTERNAL=ON + -DLIEF_OPT_EXTERNAL_SPAN=ON + -DLIEF_OPT_UTFCPP_EXTERNAL=ON + -DLIEF_OPT_EXTERNAL_EXPECTED=ON + -DLIEF_DISABLE_FROZEN=OFF + -DLIEF_DISABLE_EXCEPTIONS=OFF + + "-DLIEF_EXTERNAL_SPAN_DIR=${_VCPKG_INSTALLED_DIR}/${TARGET_TRIPLET}/include/tcb" +) + +vcpkg_cmake_install() + +vcpkg_cmake_config_fixup(CONFIG_PATH "lib/cmake/LIEF") + +vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/share/lief/LIEFConfig.cmake" + [[include("${LIEF_${lib_type}_export}")]] + [[include("${CMAKE_CURRENT_LIST_DIR}/LIEFExport-${lib_type}.cmake")]] +) + +vcpkg_fixup_pkgconfig() + +file(REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/debug/include" + "${CURRENT_PACKAGES_DIR}/debug/share" +) + +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") diff --git a/ports/lief/vcpkg.json b/ports/lief/vcpkg.json new file mode 100644 index 00000000000000..d0ff1a22288e94 --- /dev/null +++ b/ports/lief/vcpkg.json @@ -0,0 +1,79 @@ +{ + "name": "lief", + "version-semver": "0.16.0", + "description": "LIEF - Library to Instrument Executable Formats", + "homepage": "https://lief.quarkslab.com", + "license": "Apache-2.0", + "dependencies": [ + "fmt", + "frozen", + "mbedtls", + "spdlog", + "tcb-span", + "tl-expected", + "utfcpp", + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ], + "default-features": [ + "art", + "dex", + "elf", + "enable-json", + "logging", + "macho", + "oat", + "pe", + "vdex" + ], + "features": { + "art": { + "description": "Build LIEF with ART module" + }, + "c-api": { + "description": "C API" + }, + "dex": { + "description": "Build LIEF with DEX module" + }, + "elf": { + "description": "Build LIEF with ELF module" + }, + "enable-json": { + "description": "Enable JSON-related APIs", + "dependencies": [ + "nlohmann-json" + ] + }, + "extra-warnings": { + "description": "Enable extra warning from the compiler" + }, + "logging": { + "description": "Enable logging" + }, + "logging-debug": { + "description": "Enable debug logging" + }, + "macho": { + "description": "Build LIEF with MachO module" + }, + "oat": { + "description": "Build LIEF with OAT module" + }, + "pe": { + "description": "Build LIEF with PE module" + }, + "use-ccache": { + "description": "Use ccache to speed up compilation" + }, + "vdex": { + "description": "Build LIEF with VDEX module" + } + } +} diff --git a/scripts/test_ports/vcpkg-ci-lief/portfile.cmake b/scripts/test_ports/vcpkg-ci-lief/portfile.cmake new file mode 100644 index 00000000000000..62422cac0028d9 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-lief/portfile.cmake @@ -0,0 +1,7 @@ +SET(VCPKG_POLICY_EMPTY_PACKAGE enabled) + +vcpkg_cmake_configure( + SOURCE_PATH "${CURRENT_PORT_DIR}/project" +) + +vcpkg_cmake_build() diff --git a/scripts/test_ports/vcpkg-ci-lief/project/CMakeLists.txt b/scripts/test_ports/vcpkg-ci-lief/project/CMakeLists.txt new file mode 100644 index 00000000000000..9c994ed9893fae --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-lief/project/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.24) + +project(vcpkg-ci-lief LANGUAGES C CXX) + +set(CMAKE_CXX_STANDARD 14) + +find_package(LIEF CONFIG REQUIRED) +add_executable(main main.cpp) +target_link_libraries(main PRIVATE LIEF::LIEF) diff --git a/scripts/test_ports/vcpkg-ci-lief/project/main.cpp b/scripts/test_ports/vcpkg-ci-lief/project/main.cpp new file mode 100644 index 00000000000000..881e659baea7c1 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-lief/project/main.cpp @@ -0,0 +1,10 @@ +#include +#include +#include + +int main() +{ + std::cout << "access flags public = " << LIEF::DEX::to_string(LIEF::DEX::access_flags_list[1]) << std::endl; + std::cout << "Version = " << LIEF_VERSION << std::endl; + return 0; +} diff --git a/scripts/test_ports/vcpkg-ci-lief/vcpkg.json b/scripts/test_ports/vcpkg-ci-lief/vcpkg.json new file mode 100644 index 00000000000000..d50d4ab9296364 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-lief/vcpkg.json @@ -0,0 +1,30 @@ +{ + "name": "vcpkg-ci-lief", + "version-string": "ci", + "description": "Testing packages which provide lief", + "license": null, + "dependencies": [ + { + "name": "lief", + "features": [ + "c-api", + "enable-json", + "extra-warnings", + "logging", + "logging-debug", + "use-ccache", + "elf", + "pe", + "macho", + "oat", + "dex", + "vdex", + "art" + ] + }, + { + "name": "vcpkg-cmake", + "host": true + } + ] +} diff --git a/versions/baseline.json b/versions/baseline.json index 22fef4f9628afc..4ec4b5390fc7f0 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -5532,6 +5532,10 @@ "baseline": "2020-11-24", "port-version": 0 }, + "lief": { + "baseline": "0.16.0", + "port-version": 0 + }, "lightgbm": { "baseline": "4.5.0", "port-version": 0 diff --git a/versions/l-/lief.json b/versions/l-/lief.json new file mode 100644 index 00000000000000..2a2893988ae394 --- /dev/null +++ b/versions/l-/lief.json @@ -0,0 +1,9 @@ +{ + "versions": [ + { + "git-tree": "fafe51c4db1abe4b79e44013592db1c89945740d", + "version-semver": "0.16.0", + "port-version": 0 + } + ] +}