lzham_codec: add package (#2488)

* lzham_codec: add package

* Added another test and moved WIN32 defines

* Add #include <cstdint>, add more define to ios, change .+64 to x64, Add "x86" to is_arch

* Added patches from lzham_codec pull requests

* Add arm64 support and moved mingw out of elseif

* Add define __GNUC__, remove package_end

* Update fix_arm64.patch

* Add string.h patch, update fix_arm64.patch

* Using __yield() for windows ARM64, Fix checksum of fix_mingw.patch

* Fix fix_arm64.patch

* fix_mingw.patch file to utf-8

* Add mimalloc for mingw

* Add config defines mimalloc

* Add configs dictonary with mimalloc to install

* Update xmake.lua

* Move add_packages and add_defines into target

---------

Co-authored-by: ruki <waruqi@gmail.com>
pull/2519/head
Chi Huu Huynh 1 year ago committed by GitHub
parent b1dd666c56
commit f98312a8a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      packages/l/lzham_codec/patches/2023.01.03/add_mimalloc.patch
  2. 28
      packages/l/lzham_codec/patches/2023.01.03/fix_arm64.patch
  3. 24
      packages/l/lzham_codec/patches/2023.01.03/fix_linux.patch
  4. 26
      packages/l/lzham_codec/patches/2023.01.03/fix_macosx.patch
  5. 12
      packages/l/lzham_codec/patches/2023.01.03/fix_mingw.patch
  6. 142
      packages/l/lzham_codec/patches/2023.01.03/use_lzham_prefixed_max_int_values.patch
  7. 114
      packages/l/lzham_codec/port/xmake.lua
  8. 42
      packages/l/lzham_codec/xmake.lua

@ -0,0 +1,30 @@
diff --git a/lzhamdecomp/lzham_core.h b/lzhamdecomp/lzham_core.h
index 2e55362..abb8f71 100644
--- a/lzhamdecomp/lzham_core.h
+++ b/lzhamdecomp/lzham_core.h
@@ -241,7 +241,9 @@ const bool c_lzham_big_endian_platform = !c_lzham_little_endian_platform;
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
-#if !defined(__APPLE__) && !defined(__FreeBSD__)
+#ifdef ASSERT_USE_MIMALLOC
+ #include "mimalloc-override.h"
+#elif !defined(__APPLE__) && !defined(__FreeBSD__)
#include <malloc.h>
#endif
#include <stdarg.h>
diff --git a/lzhamdecomp/lzham_mem.cpp b/lzhamdecomp/lzham_mem.cpp
index e8163fa..e82a5d2 100644
--- a/lzhamdecomp/lzham_mem.cpp
+++ b/lzhamdecomp/lzham_mem.cpp
@@ -2,7 +2,9 @@
// LZHAM is in the Public Domain. Please see the Public Domain declaration at the end of include/lzham.h
#include "lzham_core.h"
-#ifdef __APPLE__
+#ifdef ASSERT_USE_MIMALLOC
+ #include "mimalloc-override.h"
+#elif defined(__APPLE__)
#include <malloc/malloc.h>
#elif defined(__FreeBSD__) || defined(__NetBSD__)
#include <malloc_np.h>

@ -0,0 +1,28 @@
diff --git a/lzhamdecomp/lzham_platform.h b/lzhamdecomp/lzham_platform.h
index 01704be..04b29fb 100644
--- a/lzhamdecomp/lzham_platform.h
+++ b/lzhamdecomp/lzham_platform.h
@@ -24,7 +24,11 @@ void lzham_fail(const char* pExp, const char* pFile, unsigned line);
#if defined(__GNUC__) && LZHAM_PLATFORM_PC
extern __inline__ __attribute__((__always_inline__,__gnu_inline__)) void lzham_yield_processor()
{
- __asm__ __volatile__("pause");
+ #if defined(__AARCH64__)
+ __asm__ __volatile__("yield");
+ #else
+ __asm__ __volatile__("pause");
+ #endif
}
#elif LZHAM_PLATFORM_X360
#define lzham_yield_processor() \
@@ -48,7 +52,9 @@ extern __inline__ __attribute__((__always_inline__,__gnu_inline__)) void lzham_y
LZHAM_FORCE_INLINE void lzham_yield_processor()
{
#if LZHAM_USE_MSVC_INTRINSICS
- #if LZHAM_PLATFORM_PC_X64
+ #if defined(__AARCH64__)
+ __yield();
+ #elif LZHAM_PLATFORM_PC_X64
_mm_pause();
#else
YieldProcessor();

@ -0,0 +1,24 @@
diff --git a/lzhamdecomp/lzham_huffman_codes.cpp b/lzhamdecomp/lzham_huffman_codes.cpp
index 11bdbd4..75884cc 100644
--- a/lzhamdecomp/lzham_huffman_codes.cpp
+++ b/lzhamdecomp/lzham_huffman_codes.cpp
@@ -2,6 +2,7 @@
// LZHAM is in the Public Domain. Please see the Public Domain declaration at the end of include/lzham.h
#include "lzham_core.h"
#include "lzham_huffman_codes.h"
+#include <cstdint>
namespace lzham
{
diff --git a/lzhamdecomp/lzham_symbol_codec.h b/lzhamdecomp/lzham_symbol_codec.h
index 306d59b..af773d5 100644
--- a/lzhamdecomp/lzham_symbol_codec.h
+++ b/lzhamdecomp/lzham_symbol_codec.h
@@ -2,6 +2,7 @@
// LZHAM is in the Public Domain. Please see the Public Domain declaration at the end of include/lzham.h
#pragma once
#include "lzham_prefix_coding.h"
+#include <cstdint>
namespace lzham
{

@ -0,0 +1,26 @@
diff --git a/lzhamdecomp/lzham_platform.cpp b/lzhamdecomp/lzham_platform.cpp
index cfc85c1..2cf493c 100644
--- a/lzhamdecomp/lzham_platform.cpp
+++ b/lzhamdecomp/lzham_platform.cpp
@@ -62,7 +62,7 @@ void lzham_debug_break(void)
#if LZHAM_USE_WIN32_API
DebugBreak();
#elif (TARGET_OS_MAC == 1) && (TARGET_IPHONE_SIMULATOR == 0) && (TARGET_OS_IPHONE == 0)
- __asm {int 3}
+ __asm__("int $3");
#else
assert(0);
#endif
diff --git a/lzhamdecomp/lzham_traits.h b/lzhamdecomp/lzham_traits.h
index ea7214f..1ec89ae 100644
--- a/lzhamdecomp/lzham_traits.h
+++ b/lzhamdecomp/lzham_traits.h
@@ -68,7 +68,7 @@ namespace lzham
#define LZHAM_DEFINE_BITWISE_COPYABLE(Q) template<> struct bitwise_copyable<Q> { enum { cFlag = true }; };
#if defined(__APPLE__) || defined(__NetBSD__)
- #define LZHAM_IS_POD(T) std::__is_pod<T>::__value
+ #define LZHAM_IS_POD(T) std::is_pod<T>::value
#else
#define LZHAM_IS_POD(T) __is_pod(T)
#endif

@ -0,0 +1,12 @@
diff --git a/lzhamdecomp/lzham_vector.h b/lzhamdecomp/lzham_vector.h
index badc540..1c5331e 100644
--- a/lzhamdecomp/lzham_vector.h
+++ b/lzhamdecomp/lzham_vector.h
@@ -1,6 +1,7 @@
// File: lzham_vector.h
// LZHAM is in the Public Domain. Please see the Public Domain declaration at the end of include/lzham.h
#pragma once
+#include <string.h>
namespace lzham
{

@ -0,0 +1,142 @@
diff --git a/lzhamcomp/lzham_win32_threading.h b/lzhamcomp/lzham_win32_threading.h
index 0e1d16b..4aaff8c 100644
--- a/lzhamcomp/lzham_win32_threading.h
+++ b/lzhamcomp/lzham_win32_threading.h
@@ -43,9 +43,9 @@ namespace lzham
}
}
- bool wait(uint32 milliseconds = UINT32_MAX)
+ bool wait(uint32 milliseconds = LZHAM_UINT32_MAX)
{
- LZHAM_ASSUME(INFINITE == UINT32_MAX);
+ LZHAM_ASSUME(INFINITE == LZHAM_UINT32_MAX);
DWORD result = WaitForSingleObject(m_handle, milliseconds);
diff --git a/lzhamdecomp/lzham_huffman_codes.cpp b/lzhamdecomp/lzham_huffman_codes.cpp
index 11bdbd4..788414a 100644
--- a/lzhamdecomp/lzham_huffman_codes.cpp
+++ b/lzhamdecomp/lzham_huffman_codes.cpp
@@ -224,7 +224,7 @@ namespace lzham
sym_freq& sf = state.syms0[num_used_syms];
sf.m_left = (uint16)i;
- sf.m_right = UINT16_MAX;
+ sf.m_right = LZHAM_UINT16_MAX;
sf.m_freq = freq;
num_used_syms++;
}
diff --git a/lzhamdecomp/lzham_prefix_coding.cpp b/lzhamdecomp/lzham_prefix_coding.cpp
index e9ada15..52377c9 100644
--- a/lzhamdecomp/lzham_prefix_coding.cpp
+++ b/lzhamdecomp/lzham_prefix_coding.cpp
@@ -149,7 +149,7 @@ namespace lzham
{
uint c = pCodesizes[i];
- LZHAM_ASSERT(!c || (next_code[c] <= UINT16_MAX));
+ LZHAM_ASSERT(!c || (next_code[c] <= LZHAM_UINT16_MAX));
pCodes[i] = static_cast<uint16>(next_code[c]++);
@@ -296,7 +296,7 @@ namespace lzham
LZHAM_ASSERT(t < (1U << table_bits));
- LZHAM_ASSERT(pTables->m_lookup[t] == UINT32_MAX);
+ LZHAM_ASSERT(pTables->m_lookup[t] == LZHAM_UINT32_MAX);
pTables->m_lookup[t] = sym_index | (codesize << 16U);
}
diff --git a/lzhamdecomp/lzham_symbol_codec.cpp b/lzhamdecomp/lzham_symbol_codec.cpp
index 5623584..b2ea7ee 100644
--- a/lzhamdecomp/lzham_symbol_codec.cpp
+++ b/lzhamdecomp/lzham_symbol_codec.cpp
@@ -581,7 +581,7 @@ namespace lzham
freq++;
m_sym_freq[sym] = static_cast<uint16>(freq);
- LZHAM_ASSERT(freq <= UINT16_MAX);
+ LZHAM_ASSERT(freq <= LZHAM_UINT16_MAX);
if (--m_symbols_until_update == 0)
{
@@ -828,7 +828,7 @@ namespace lzham
freq++;
model.m_sym_freq[sym] = static_cast<uint16>(freq);
- LZHAM_ASSERT(freq <= UINT16_MAX);
+ LZHAM_ASSERT(freq <= LZHAM_UINT16_MAX);
if (--model.m_symbols_until_update == 0)
{
@@ -1265,8 +1265,8 @@ namespace lzham
{
uint32 t = pTables->m_lookup[m_bit_buf >> (cBitBufSize - pTables->m_table_bits)];
- LZHAM_ASSERT(t != UINT32_MAX);
- sym = t & UINT16_MAX;
+ LZHAM_ASSERT(t != LZHAM_UINT32_MAX);
+ sym = t & LZHAM_UINT16_MAX;
len = t >> 16;
LZHAM_ASSERT(model.m_code_sizes[sym] == len);
@@ -1301,7 +1301,7 @@ namespace lzham
freq++;
model.m_sym_freq[sym] = static_cast<uint16>(freq);
- LZHAM_ASSERT(freq <= UINT16_MAX);
+ LZHAM_ASSERT(freq <= LZHAM_UINT16_MAX);
if (--model.m_symbols_until_update == 0)
{
diff --git a/lzhamdecomp/lzham_symbol_codec.h b/lzhamdecomp/lzham_symbol_codec.h
index 306d59b..b231530 100644
--- a/lzhamdecomp/lzham_symbol_codec.h
+++ b/lzhamdecomp/lzham_symbol_codec.h
@@ -19,7 +19,7 @@ namespace lzham
typedef uint64 bit_cost_t;
const uint32 cBitCostScaleShift = 24;
const uint32 cBitCostScale = (1U << cBitCostScaleShift);
- const bit_cost_t cBitCostMax = UINT64_MAX;
+ const bit_cost_t cBitCostMax = LZHAM_UINT64_MAX;
inline bit_cost_t convert_to_scaled_bitcost(uint bits) { LZHAM_ASSERT(bits <= 255); uint32 scaled_bits = bits << cBitCostScaleShift; return static_cast<bit_cost_t>(scaled_bits); }
@@ -444,7 +444,7 @@ namespace lzham
if (LZHAM_BUILTIN_EXPECT(k <= pTables->m_table_max_code, 1)) \
{ \
uint32 t = pTables->m_lookup[bit_buf >> (symbol_codec::cBitBufSize - pTables->m_table_bits)]; \
- result = t & UINT16_MAX; \
+ result = t & LZHAM_UINT16_MAX; \
len = t >> 16; \
} \
else \
@@ -465,7 +465,7 @@ namespace lzham
uint freq = pModel->m_sym_freq[result]; \
freq++; \
pModel->m_sym_freq[result] = static_cast<uint16>(freq); \
- LZHAM_ASSERT(freq <= UINT16_MAX); \
+ LZHAM_ASSERT(freq <= LZHAM_UINT16_MAX); \
if (LZHAM_BUILTIN_EXPECT(--pModel->m_symbols_until_update == 0, 0)) \
{ \
pModel->update_tables(); \
@@ -501,7 +501,7 @@ namespace lzham
if (LZHAM_BUILTIN_EXPECT(k <= pTables->m_table_max_code, 1)) \
{ \
uint32 t = pTables->m_lookup[bit_buf >> (symbol_codec::cBitBufSize - pTables->m_table_bits)]; \
- result = t & UINT16_MAX; \
+ result = t & LZHAM_UINT16_MAX; \
len = t >> 16; \
} \
else \
@@ -522,7 +522,7 @@ namespace lzham
uint freq = pModel->m_sym_freq[result]; \
freq++; \
pModel->m_sym_freq[result] = static_cast<uint16>(freq); \
- LZHAM_ASSERT(freq <= UINT16_MAX); \
+ LZHAM_ASSERT(freq <= LZHAM_UINT16_MAX); \
if (LZHAM_BUILTIN_EXPECT(--pModel->m_symbols_until_update == 0, 0)) \
{ \
pModel->update_tables(); \

@ -0,0 +1,114 @@
add_rules("mode.debug", "mode.release")
option("mimalloc", {default = false, showmenu = true, description = "Use mimalloc"})
if has_config("mimalloc") then
add_requires("mimalloc")
end
target("lzham_codec")
set_kind("$(kind)")
set_languages("cxx14")
add_options("mimalloc")
add_files(
"lzhamlib/lzham_lib.cpp",
"lzhamcomp/lzham_lzbase.cpp",
"lzhamcomp/lzham_lzcomp_internal.cpp",
"lzhamcomp/lzham_lzcomp_state.cpp",
"lzhamcomp/lzham_lzcomp.cpp",
"lzhamcomp/lzham_match_accel.cpp",
"lzhamdecomp/lzham_assert.cpp",
"lzhamdecomp/lzham_checksum.cpp",
"lzhamdecomp/lzham_huffman_codes.cpp",
"lzhamdecomp/lzham_lzdecomp.cpp",
"lzhamdecomp/lzham_lzdecompbase.cpp",
"lzhamdecomp/lzham_mem.cpp",
"lzhamdecomp/lzham_platform.cpp",
"lzhamdecomp/lzham_prefix_coding.cpp",
"lzhamdecomp/lzham_symbol_codec.cpp",
"lzhamdecomp/lzham_timer.cpp",
"lzhamdecomp/lzham_vector.cpp"
)
add_headerfiles(
"include/lzham_dynamic_lib.h",
"include/lzham_static_lib.h",
"include/lzham.h",
"include/zlib.h",
"lzhamcomp/lzham_comp.h",
"lzhamcomp/lzham_lzbase.h",
"lzhamcomp/lzham_lzcomp_internal.h",
"lzhamcomp/lzham_match_accel.h",
"lzhamcomp/lzham_null_threading.h",
"lzhamcomp/lzham_threading.h",
"lzhamdecomp/lzham_assert.h",
"lzhamdecomp/lzham_checksum.h",
"lzhamdecomp/lzham_config.h",
"lzhamdecomp/lzham_core.h",
"lzhamdecomp/lzham_decomp.h",
"lzhamdecomp/lzham_helpers.h",
"lzhamdecomp/lzham_huffman_codes.h",
"lzhamdecomp/lzham_lzdecompbase.h",
"lzhamdecomp/lzham_math.h",
"lzhamdecomp/lzham_mem.h",
"lzhamdecomp/lzham_platform.h",
"lzhamdecomp/lzham_prefix_coding.h",
"lzhamdecomp/lzham_symbol_codec.h",
"lzhamdecomp/lzham_timer.h",
"lzhamdecomp/lzham_traits.h",
"lzhamdecomp/lzham_types.h",
"lzhamdecomp/lzham_utils.h",
"lzhamdecomp/lzham_vector.h"
)
add_includedirs("include", {public = true})
add_includedirs("lzhamcomp", "lzhamdecomp")
if has_config("mimalloc") then
add_packages("mimalloc")
add_defines("ASSERT_USE_MIMALLOC")
end
if is_arch("x86_64") then
add_defines("__x86_64__")
elseif is_arch("i386") then
add_defines("__i386__")
end
if is_plat("mingw") then
add_defines("__GNUC__")
if is_arch("i386", "x86") then
add_defines("__MINGW32__")
else
add_defines("__MINGW64__")
end
end
if is_plat("windows") then
add_defines("WIN32", "__WIN32__")
if is_arch("arm64") then
add_defines("__AARCH64__")
elseif is_arch("x64") then
add_defines("_WIN64")
end
add_files("lzhamcomp/lzham_win32_threading.cpp")
add_headerfiles("lzhamcomp/lzham_win32_threading.h")
else
add_syslinks("pthread")
if is_plat("linux") then
add_defines("__linux__")
elseif is_plat("freebsd") then
add_defines("__FreeBSD__")
end
if is_plat("macosx", "iphoneos") then
add_defines("__APPLE__")
add_defines("__MACH__")
if is_plat("macosx") then
add_defines("TARGET_OS_MAC")
else
add_defines("TARGET_OS_IPHONE")
end
end
add_files("lzhamcomp/lzham_pthreads_threading.cpp")
add_headerfiles("lzhamcomp/lzham_pthreads_threading.h")
end

@ -0,0 +1,42 @@
package("lzham_codec")
set_homepage("https://github.com/richgel999/lzham_codec")
set_description("Lossless data compression codec with LZMA-like ratios but 1.5x-8x faster decompression speed, C/C++")
set_urls("https://github.com/richgel999/lzham_codec.git")
add_versions("2023.01.03", "d379b1f9121e2197881c61cfc4713c78848bdfe7")
add_patches("2023.01.03", path.join(os.scriptdir(), "patches", "2023.01.03", "fix_linux.patch"), "f43db780903b98567d5039bcc99c08d3ed871a979333b3387e8416536b3ba925")
add_patches("2023.01.03", path.join(os.scriptdir(), "patches", "2023.01.03", "use_lzham_prefixed_max_int_values.patch"), "bf8dd1bf584fb0e8a7dcdb846e009ef52c1fcc0fbee7158635322b69883874a6")
add_patches("2023.01.03", path.join(os.scriptdir(), "patches", "2023.01.03", "fix_macosx.patch"), "8c5ec78e9381215f0283dde82059775c3f8406c444013c04bb55b578415ff7ef")
add_patches("2023.01.03", path.join(os.scriptdir(), "patches", "2023.01.03", "fix_arm64.patch"), "c1493e4e0b097e3cf0657a90d836952b1dd47c15d3977b8923805004336945d2")
add_patches("2023.01.03", path.join(os.scriptdir(), "patches", "2023.01.03", "fix_mingw.patch"), "b35bb937a0fc2ba7a61c7e3253ede9d3e8c0f952a8f312e6fa2fe577987fa9c6")
add_patches("2023.01.03", path.join(os.scriptdir(), "patches", "2023.01.03", "add_mimalloc.patch"), "7d42ce1d7f1d5d8874f99714ddfff97f35247506d423b488e0de8c74ded92a2f")
add_configs("mimalloc", {description = "Use mimalloc instead of default malloc headers", default = is_plat("mingw"), type = "boolean", readonly = is_plat("mingw")})
on_load(function (package)
if package:config("mimalloc") then
package:add("deps", "mimalloc")
end
end)
on_install(function (package)
os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
local configs = {}
if package:config("mimalloc") then
package:add("defines", "ASSERT_USE_MIMALLOC")
configs.mimalloc = true
end
import("package.tools.xmake").install(package, configs)
end)
on_test(function (package)
assert(package:has_cfuncs("lzham_compress_init", {includes = "lzham_static_lib.h"}))
assert(package:check_cxxsnippets({test = [[
#include <lzham_static_lib.h>
void test() {
lzham_static_lib lzham_lib;
lzham_lib.load();
}
]]}))
end)
Loading…
Cancel
Save