From b0001567aa8a1db3d94c12a7c219d84fe2ab073c Mon Sep 17 00:00:00 2001 From: star9029 Date: Thu, 19 Sep 2024 14:57:08 +0800 Subject: [PATCH] lief: improve deps (#5279) * lief: improve deps * patch algorithm * add check * fix exceptions config --- packages/f/frozen/xmake.lua | 7 +- .../l/lief/patches/0.15.1/algorithm.patch | 25 +++++++ packages/l/lief/xmake.lua | 69 +++++++++++++++---- packages/s/spdlog/xmake.lua | 1 + packages/t/tl_expected/xmake.lua | 7 +- 5 files changed, 93 insertions(+), 16 deletions(-) create mode 100644 packages/l/lief/patches/0.15.1/algorithm.patch diff --git a/packages/f/frozen/xmake.lua b/packages/f/frozen/xmake.lua index 937b13c47..7adeabbf4 100644 --- a/packages/f/frozen/xmake.lua +++ b/packages/f/frozen/xmake.lua @@ -1,5 +1,4 @@ package("frozen") - set_kind("library", {headeronly = true}) set_homepage("https://github.com/serge-sans-paille/frozen") set_description("A header-only, constexpr alternative to gperf for C++14 users") @@ -11,8 +10,12 @@ package("frozen") add_versions("1.2.0", "ed8339c017d7c5fe019ac2c642477f435278f0dc643c1d69d3f3b1e95915e823") add_versions("1.1.1", "f7c7075750e8fceeac081e9ef01944f221b36d9725beac8681cbd2838d26be45") + add_deps("cmake") + on_install(function (package) - os.cp("include/frozen", package:installdir("include")) + local configs = {"-DBUILD_TESTING=OFF"} + table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release")) + import("package.tools.cmake").install(package, configs) end) on_test(function (package) diff --git a/packages/l/lief/patches/0.15.1/algorithm.patch b/packages/l/lief/patches/0.15.1/algorithm.patch new file mode 100644 index 000000000..c8366f0e5 --- /dev/null +++ b/packages/l/lief/patches/0.15.1/algorithm.patch @@ -0,0 +1,25 @@ +diff --git a/src/ELF/DynamicEntryArray.cpp b/src/ELF/DynamicEntryArray.cpp +index c6fa7130ed..4e1bec392f 100644 +--- a/src/ELF/DynamicEntryArray.cpp ++++ b/src/ELF/DynamicEntryArray.cpp +@@ -18,6 +18,8 @@ + + #include "logging.hpp" + ++#include ++ + namespace LIEF { + namespace ELF { + +diff --git a/src/ELF/DynamicEntryRunPath.cpp b/src/ELF/DynamicEntryRunPath.cpp +index e0838401bc..c6758fbd21 100644 +--- a/src/ELF/DynamicEntryRunPath.cpp ++++ b/src/ELF/DynamicEntryRunPath.cpp +@@ -17,6 +17,7 @@ + #include "LIEF/Visitor.hpp" + #include "logging.hpp" + ++#include + #include + #include + diff --git a/packages/l/lief/xmake.lua b/packages/l/lief/xmake.lua index 1dddacfbf..cccca3bc6 100644 --- a/packages/l/lief/xmake.lua +++ b/packages/l/lief/xmake.lua @@ -1,17 +1,18 @@ package("lief") - set_homepage("https://lief.quarkslab.com") set_description("Library to Instrument Executable Formats.") set_license("Apache-2.0") - set_urls("https://github.com/lief-project/LIEF/archive/$(version).tar.gz", + set_urls("https://github.com/lief-project/LIEF/archive/refs/tags/$(version).tar.gz", "https://github.com/lief-project/LIEF.git") + + add_versions("0.15.1", "28653b59afc8b8b255251f21a0f3cbfbdec05dd988fb3f473e22dde28f427ad8") add_versions("0.10.1", "6f30c98a559f137e08b25bcbb376c0259914b33c307b8b901e01ca952241d00a") add_versions("0.11.5", "6d6d57304a56850958e4ce54f3da2ea2b9eb856ccbab61c6cde9cba15d7c9da5") add_versions("0.14.0", "400804e38cb5ce8d15fb52a4db6345f02da7b2e5cb773665712283001482b808") add_versions("0.14.1", "92916dcb3178353d863aef4f409186889983c56e025b774741d5316a72ec3a7d") - add_deps("cmake") + add_patches("<=0.15.1", "patches/0.15.1/algorithm.patch", "3e110539c3db037b2b24cd32f97ad8cc6241b1f69d4a65dab9fd6c84e482bbd9") add_configs("elf", {description = "Enable ELF module.", default = true, type = "boolean"}) add_configs("pe", {description = "Enable PE module.", default = true, type = "boolean"}) @@ -22,14 +23,63 @@ package("lief") add_configs("oat", {description = "Enable Oat module.", default = false, type = "boolean"}) add_configs("art", {description = "Enable Art module.", default = false, type = "boolean"}) + add_configs("exceptions", {description = "Build with exception support.", default = true, type = "boolean"}) + if is_plat("windows") then add_syslinks("advapi32") end - on_install("macosx", "linux", "windows", function (package) - local configs = {"-DLIEF_PYTHON_API=OFF", "-DLIEF_DOC=OFF", "-DLIEF_TESTS=OFF", "-DLIEF_EXAMPLES=OFF", "-DLIEF_INSTALL_PYTHON=OFF"} - table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release")) + add_deps("cmake") + add_deps("spdlog", {configs = {header_only = false, noexcept = true}}) + add_deps("nlohmann_json", {configs = {cmake = true}}) + add_deps("tl_expected", "utfcpp", "mbedtls <3.6.0", "tcb-span", "frozen") + + if on_check then + on_check(function (package) + if package:is_plat("windows") then + local vs_toolset = package:toolchain("msvc"):config("vs_toolset") + if vs_toolset then + local vs_toolset_ver = import("core.base.semver").new(vs_toolset) + local minor = vs_toolset_ver:minor() + assert(minor and minor >= 30, "package(lief) require vs_toolset >= 14.3") + end + end + if package:is_arch("arm.*") then + raise("package(lief) dep(mbedtls <3.6.0) unsupported arm arch") + end + end) + end + + on_install(function (package) + if package:config("shared") then + package:add("defines", "LIEF_IMPORT") + end + + io.replace("CMakeLists.txt", "target_link_libraries(LIB_LIEF PRIVATE utf8cpp)", "target_link_libraries(LIB_LIEF PRIVATE utf8cpp::utf8cpp)", {plain = true}) + + local configs = { + "-DLIEF_C_API=ON", + "-DLIEF_PYTHON_API=OFF", + "-DLIEF_DOC=OFF", + "-DLIEF_TESTS=OFF", + "-DLIEF_EXAMPLES=OFF", + "-DLIEF_INSTALL_PYTHON=OFF", + "-DLIEF_EXTERNAL_SPDLOG=ON", + "-DLIEF_OPT_EXTERNAL_EXPECTED=ON", + "-DLIEF_OPT_UTFCPP_EXTERNAL=ON", + "-DLIEF_OPT_MBEDTLS_EXTERNAL=ON", + "-DLIEF_OPT_EXTERNAL_SPAN=ON", + "-DLIEF_ENABLE_JSON=ON", + "-DLIEF_OPT_NLOHMANN_JSON_EXTERNAL=ON", + "-DLIEF_OPT_FROZEN_EXTERNAL=ON", + "-DLIEF_DISABLE_FROZEN=OFF", + } + table.insert(configs, "-DLIEF_EXTERNAL_SPAN_DIR=" .. package:dep("tcb-span"):installdir("include")) + table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release")) table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) + table.insert(configs, "-DLIEF_ASAN=" .. (package:config("asan") and "ON" or "OFF")) + table.insert(configs, "-DLIEF_DISABLE_EXCEPTIONS=" .. (package:config("exceptions") and "OFF" or "ON")) + for name, enabled in pairs(package:configs()) do if not package:extraconf("configs", name, "builtin") then table.insert(configs, "-DLIEF_" .. name:upper() .. "=" .. (enabled and "ON" or "OFF")) @@ -48,11 +98,6 @@ package("lief") parse_entry = "macho_parse" end if parse_entry then - assert(package:check_cxxsnippets({test = [[ - #include - void test() { - ]] .. parse_entry .. [[(""); - } - ]]}, {configs = {languages = "c"}})) + assert(package:has_cfuncs(parse_entry, {includes = "LIEF/LIEF.h"})) end end) diff --git a/packages/s/spdlog/xmake.lua b/packages/s/spdlog/xmake.lua index 4cd2c536c..e7ff47914 100644 --- a/packages/s/spdlog/xmake.lua +++ b/packages/s/spdlog/xmake.lua @@ -69,6 +69,7 @@ package("spdlog") end local configs = {"-DSPDLOG_BUILD_TESTS=OFF", "-DSPDLOG_BUILD_EXAMPLE=OFF"} + table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release")) table.insert(configs, "-DSPDLOG_BUILD_SHARED=" .. (package:config("shared") and "ON" or "OFF")) table.insert(configs, "-DSPDLOG_USE_STD_FORMAT=" .. (package:config("std_format") and "ON" or "OFF")) table.insert(configs, "-DSPDLOG_FMT_EXTERNAL=" .. (package:config("fmt_external") and "ON" or "OFF")) diff --git a/packages/t/tl_expected/xmake.lua b/packages/t/tl_expected/xmake.lua index d777f79dc..69a551c8e 100644 --- a/packages/t/tl_expected/xmake.lua +++ b/packages/t/tl_expected/xmake.lua @@ -1,5 +1,4 @@ package("tl_expected") - set_kind("library", {headeronly = true}) set_homepage("https://github.com/TartanLlama/expected") set_description("C++11/14/17 std::expected with functional-style extensions") @@ -11,8 +10,12 @@ package("tl_expected") add_versions("v1.0.0", "c1733556cbd3b532a02b68e2fbc2091b5bc2cccc279e4f6c6bd83877aabd4b02") add_versions("v1.1.0", "4b2a347cf5450e99f7624247f7d78f86f3adb5e6acd33ce307094e9507615b78") + add_deps("cmake") + on_install(function (package) - os.cp("include/tl", package:installdir("include")) + local configs = {"-DBUILD_TESTING=OFF"} + table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release")) + import("package.tools.cmake").install(package, configs) end) on_test(function (package)