From 13462643d235fbced7e96c15442d125718a50d53 Mon Sep 17 00:00:00 2001 From: star9029 Date: Thu, 19 Sep 2024 10:07:35 +0800 Subject: [PATCH] fast-lzma2: add package (#5274) * fast-lzma2: add package * improve asm build * workaround asm build * disable asm on macosx * improve xmake.lua * improve macosx build --- packages/f/fast-lzma2/port/xmake.lua | 56 ++++++++++++++++++++++++++++ packages/f/fast-lzma2/xmake.lua | 30 +++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 packages/f/fast-lzma2/port/xmake.lua create mode 100644 packages/f/fast-lzma2/xmake.lua diff --git a/packages/f/fast-lzma2/port/xmake.lua b/packages/f/fast-lzma2/port/xmake.lua new file mode 100644 index 000000000..edf66d062 --- /dev/null +++ b/packages/f/fast-lzma2/port/xmake.lua @@ -0,0 +1,56 @@ +set_version("v1.0.1", {soname = "1"}) + +add_rules("mode.debug", "mode.release") + +add_requires("xxhash") + +target("fast-lzma2") + set_kind("$(kind)") + add_files("*.c") + add_headerfiles("fast-lzma2.h", "fl2_errors.h") + add_packages("xxhash") + + if is_kind("shared") and is_plat("windows") then + add_defines("FL2_DLL_EXPORT") + add_defines("FL2_DLL_IMPORT", {interface = true}) + end + + if is_plat("linux", "bsd") then + add_syslinks("pthread") + end + + on_config(function (target) + if not target:is_arch("x64", "x86_64") or is_host("bsd", "macosx") then + return + end + + target:add("defines", "LZMA2_DEC_OPT") + if target:has_tool("cxx", "clang") then + target:add("deps", "asm") + else + if target:is_plat("windows") then + target:add("files", "*.asm") + target:add("asflags", "-DMS_x64_CALL=1") + else + target:add("files", "*.S") + target:add("asflags", "-DMS_x64_CALL=0") + end + end + end) +target_end() + +if is_arch("x64", "x86_64") and not is_host("bsd", "macosx") then + -- workaround for clang toolchain + target("asm") + set_kind("object") + + if is_plat("windows") then + add_files("*.asm") + add_asflags("-DMS_x64_CALL=1") + set_toolchains("msvc") + else + add_asflags("-DMS_x64_CALL=0") + add_files("*.S") + set_toolchains("gcc") + end +end diff --git a/packages/f/fast-lzma2/xmake.lua b/packages/f/fast-lzma2/xmake.lua new file mode 100644 index 000000000..a1570137f --- /dev/null +++ b/packages/f/fast-lzma2/xmake.lua @@ -0,0 +1,30 @@ +package("fast-lzma2") + set_homepage("https://github.com/conor42/fast-lzma2") + set_description("Fast LZMA2 Library") + set_license("BSD-3-Clause") + + add_urls("https://github.com/conor42/fast-lzma2/archive/refs/tags/$(version).tar.gz", + "https://github.com/conor42/fast-lzma2.git") + + add_versions("v1.0.1", "60fd0a031fb0a153ba4f00799aed443ce9f149b203c59e17e558afbfafe8bf64") + + if is_plat("linux", "bsd") then + add_syslinks("pthread") + end + + add_deps("xxhash") + + on_install(function (package) + if package:is_plat("windows") and package:config("shared") then + package:add("defines", "FL2_DLL_IMPORT") + end + + os.rm("xxhash.c") + os.rm("xxhash.h") + os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua") + import("package.tools.xmake").install(package) + end) + + on_test(function (package) + assert(package:has_cfuncs("FL2_compress", {includes = "fast-lzma2.h"})) + end)