diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8608156..8389212 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,6 +44,22 @@ jobs: xcodebuild -workspace builds/xcode/HPatchLite.xcworkspace -scheme hpatchi -configuration Release OBJROOT=$PWD/bin SYMROOT=$PWD/bin xcodebuild -workspace builds/xcode/HPatchLite.xcworkspace -scheme hdiffi -configuration Release OBJROOT=$PWD/bin SYMROOT=$PWD/bin + ndk-build: + strategy: + matrix: + platform: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.platform }} + steps: + - uses: actions/checkout@v2 + - uses: nttld/setup-ndk@v1.0.6 + with: + ndk-version: r16b + - name: buildByAndroidNDK + run: | + git submodule update --init --recursive + cd ./builds/android_ndk_jni_mk + ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk NDK_APPLICATION_MK=./Application.mk + vc-build: runs-on: windows-latest steps: diff --git a/HDiffPatch b/HDiffPatch index e8d1df5..379fa82 160000 --- a/HDiffPatch +++ b/HDiffPatch @@ -1 +1 @@ -Subproject commit e8d1df50a9374d1c3a46257a3106a092c46a1946 +Subproject commit 379fa8251d483be2587230233130247c03663636 diff --git a/README.md b/README.md index f6a91fd..28d82e0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # [HPatchLite](https://github.com/sisong/HPatchLite) -[![release](https://img.shields.io/badge/release-v0.4.1-blue.svg)](https://github.com/sisong/HPatchLite/releases) +[![release](https://img.shields.io/badge/release-v0.4.2-blue.svg)](https://github.com/sisong/HPatchLite/releases) [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/sisong/HPatchLite/blob/main/LICENSE) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/sisong/HPatchLite/pulls) [![+issue Welcome](https://img.shields.io/github/issues-raw/sisong/HPatchLite?color=green&label=%2Bissue%20welcome)](https://github.com/sisong/HPatchLite/issues) @@ -10,9 +10,9 @@ HPatchLite is a lite version of [HDiffPatch](https://github.com/sisong/HDiffPatch), tiny code & ram requirements when patch on MCU,NB-IoT,... -The patch code(ROM occupancy) very small, compiled by Mbed Studio is 664 bytes. -Tip: if define _IS_RUN_MEM_SAFE_CHECK=0 can reduce 74 bytes; -if used tinyuz & define _IS_USED_SHARE_hpatch_lite_types=1, can reduce 52 bytes. +The patch code(ROM occupancy) very small, compiled by Mbed Studio is 670 bytes. +Tip: if used tinyuz & define _IS_USED_SHARE_hpatch_lite_types=1, can reduce 52 bytes; +if define _IS_RUN_MEM_SAFE_CHECK=0, can reduce 74 bytes. At the same time, the patch memory(RAM occupancy) can also be very small, RAM size = one decompress memory size + input cache size(>=3Byte) when patch. diff --git a/README_cn.md b/README_cn.md index 04b30fd..351c3d9 100644 --- a/README_cn.md +++ b/README_cn.md @@ -1,5 +1,5 @@ # [HPatchLite](https://github.com/sisong/HPatchLite) -[![release](https://img.shields.io/badge/release-v0.4.1-blue.svg)](https://github.com/sisong/HPatchLite/releases) +[![release](https://img.shields.io/badge/release-v0.4.2-blue.svg)](https://github.com/sisong/HPatchLite/releases) [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/sisong/HPatchLite/blob/main/LICENSE) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/sisong/HPatchLite/pulls) [![+issue Welcome](https://img.shields.io/github/issues-raw/sisong/HPatchLite?color=green&label=%2Bissue%20welcome)](https://github.com/sisong/HPatchLite/issues) @@ -10,9 +10,9 @@ HPatchLite 是 [HDiffPatch](https://github.com/sisong/HDiffPatch) 的一个精简(Lite)版,为在MCU、NB-IoT等小型设备上执行打补丁(patch)功能而优化。 -编译后的patch代码(ROM 占用)非常的小,用 Mbed Studio 编译后为 664 字节。 -提示:设置宏_IS_RUN_MEM_SAFE_CHECK=0可以节省74字节; -如果使用了tinyuz并且设置宏_IS_USED_SHARE_hpatch_lite_types=1,可以节省52字节。 +编译后的patch代码(ROM 占用)非常的小,用 Mbed Studio 编译后为 670 字节。 +提示:如果使用了tinyuz并且设置宏_IS_USED_SHARE_hpatch_lite_types=1,可以节省52字节; +设置宏_IS_RUN_MEM_SAFE_CHECK=0,可以节省74字节。 同时,patch时内存(RAM 占用)也可以非常的小, 大小为 一个解压缩流需要的内存大小 + patch时输入的缓存区大小(>=3Byte)。 diff --git a/builds/android_ndk_jni_mk/Android.mk b/builds/android_ndk_jni_mk/Android.mk new file mode 100644 index 0000000..ccfaf65 --- /dev/null +++ b/builds/android_ndk_jni_mk/Android.mk @@ -0,0 +1,67 @@ +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE := hpatchi + +# args +LZMA := 0 +TUZ := 1 +ZLIB := 1 # -lz dynamic link unsafe for inflate_state + +ifeq ($(LZMA),0) + Lzma_Files := +else + # https://github.com/sisong/lzma + LZMA_PATH := $(LOCAL_PATH)/../../lzma/C/ + Lzma_Files := $(LZMA_PATH)/LzmaDec.c \ + $(LZMA_PATH)/Lzma2Dec.c + ifeq ($(TARGET_ARCH_ABI),arm64-v8a) + Lzma_Files += $(LZMA_PATH)/../Asm/arm64/LzmaDecOpt.S + endif +endif +ifeq ($(TUZ),0) + Tuz_Files := +else + # https://github.com/sisong/tinyuz + TUZ_PATH := $(LOCAL_PATH)/../../tinyuz/decompress/ + Tuz_Files := $(TUZ_PATH)/tuz_dec.c +endif +ifeq ($(ZLIB),0) +else + # http://zlib.net/ https://github.com/madler/zlib + ZLIB_PATH := $(LOCAL_PATH)/../../zlib/ +endif + +HDP_PATH := $(LOCAL_PATH)/../../HDiffPatch +Hdp_Files := $(HDP_PATH)/file_for_patch.c \ + $(HDP_PATH)/libHDiffPatch/HPatchLite/hpatch_lite.c + +Src_Files := $(LOCAL_PATH)/hpatchi_jni.c \ + $(LOCAL_PATH)/hpatchi.c + +DEF_FLAGS := -Os -D_IS_NEED_DEFAULT_CompressPlugin=0 +ifeq ($(LZMA),0) +else + DEF_FLAGS += -D_CompressPlugin_lzma -D_CompressPlugin_lzma2 -D_7ZIP_ST -I$(LZMA_PATH) + ifeq ($(TARGET_ARCH_ABI),arm64-v8a) + DEF_FLAGS += -D_LZMA_DEC_OPT + endif +endif +ifeq ($(TUZ),0) +else + DEF_FLAGS += -D_CompressPlugin_tuz -I$(TUZ_PATH) +endif +ifeq ($(ZLIB),0) +else + DEF_FLAGS += -D_CompressPlugin_zlib -I$(ZLIB_PATH) +endif + +LOCAL_SRC_FILES := $(Src_Files) $(Lzma_Files) $(Tuz_Files) $(Hdp_Files) +LOCAL_LDLIBS := -llog +ifeq ($(ZLIB),0) +else + LOCAL_LDLIBS += -lz +endif +LOCAL_CFLAGS := -DANDROID_NDK -DNDEBUG $(DEF_FLAGS) +include $(BUILD_SHARED_LIBRARY) + diff --git a/builds/android_ndk_jni_mk/Application.mk b/builds/android_ndk_jni_mk/Application.mk new file mode 100644 index 0000000..611e5d5 --- /dev/null +++ b/builds/android_ndk_jni_mk/Application.mk @@ -0,0 +1,7 @@ +APP_PLATFORM := android-14 +APP_CFLAGS += -Wno-error=format-security +APP_CFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden +APP_CFLAGS += -ffunction-sections -fdata-sections +APP_LDFLAGS += -Wl,--gc-sections +APP_BUILD_SCRIPT := Android.mk +APP_ABI := armeabi armeabi-v7a arm64-v8a x86 x86_64 diff --git a/builds/android_ndk_jni_mk/build_libs.bat b/builds/android_ndk_jni_mk/build_libs.bat new file mode 100644 index 0000000..6f9ef7a --- /dev/null +++ b/builds/android_ndk_jni_mk/build_libs.bat @@ -0,0 +1 @@ +ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk NDK_APPLICATION_MK=Application.mk \ No newline at end of file diff --git a/builds/android_ndk_jni_mk/build_libs.sh b/builds/android_ndk_jni_mk/build_libs.sh new file mode 100644 index 0000000..6f9ef7a --- /dev/null +++ b/builds/android_ndk_jni_mk/build_libs.sh @@ -0,0 +1 @@ +ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk NDK_APPLICATION_MK=Application.mk \ No newline at end of file diff --git a/builds/android_ndk_jni_mk/hpatchi.c b/builds/android_ndk_jni_mk/hpatchi.c new file mode 100644 index 0000000..2bb1a0a --- /dev/null +++ b/builds/android_ndk_jni_mk/hpatchi.c @@ -0,0 +1,10 @@ +// hpatchi.c +// Created by sisong on 2022-08-19. +#include "hpatchi.h" + +#ifndef _IS_USED_MULTITHREAD +#define _IS_USED_MULTITHREAD 0 +#endif +#define _IS_NEED_MAIN 0 +#define _IS_NEED_ALL_CompressPlugin 0 +#include "../../hpatchi.c" diff --git a/builds/android_ndk_jni_mk/hpatchi.h b/builds/android_ndk_jni_mk/hpatchi.h new file mode 100644 index 0000000..8ade08e --- /dev/null +++ b/builds/android_ndk_jni_mk/hpatchi.h @@ -0,0 +1,20 @@ +// hpatchi.h +// Created by sisong on 2022-08-19. +#ifndef hpatchi_h +#define hpatchi_h +#include +#include +#ifdef __cplusplus +extern "C" { +#endif + #define H_PATCH_EXPORT __attribute__((visibility("default"))) + + // return THPatchiResult, 0 is ok + // 'diffFileName' file is create by hdiffi app,or by create_lite_diff() + int hpatchi(const char *oldFileName,const char *diffFileName, + const char *outNewFileName, size_t cacheMemory) H_PATCH_EXPORT; + +#ifdef __cplusplus +} +#endif +#endif // hpatchi_h diff --git a/builds/android_ndk_jni_mk/hpatchi_jni.c b/builds/android_ndk_jni_mk/hpatchi_jni.c new file mode 100644 index 0000000..ee84333 --- /dev/null +++ b/builds/android_ndk_jni_mk/hpatchi_jni.c @@ -0,0 +1,28 @@ +// hpatch_jni.c +// Created by sisong on 2022-08-19. +#include +#include "hpatchi.h" +#ifdef __cplusplus +extern "C" { +#endif + + JNIEXPORT int + Java_com_github_sisong_hpatchi_patch(JNIEnv* jenv,jobject jobj, + jstring oldFileName,jstring diffFileName, + jstring outNewFileName,jlong cacheMemory){ + const char* cOldFileName = (*jenv)->GetStringUTFChars(jenv,oldFileName, NULL); + const char* cDiffFileName = (*jenv)->GetStringUTFChars(jenv,diffFileName, NULL); + const char* cOutNewFileName = (*jenv)->GetStringUTFChars(jenv,outNewFileName, NULL); + size_t cCacheMemory=(size_t)cacheMemory; + assert((jlong)cCacheMemory==cacheMemory); + int result=hpatchi(cOldFileName,cDiffFileName,cOutNewFileName,cCacheMemory); + (*jenv)->ReleaseStringUTFChars(jenv,outNewFileName,cOutNewFileName); + (*jenv)->ReleaseStringUTFChars(jenv,diffFileName,cDiffFileName); + (*jenv)->ReleaseStringUTFChars(jenv,oldFileName,cOldFileName); + return result; + } + +#ifdef __cplusplus +} +#endif + diff --git a/builds/android_ndk_jni_mk/java/com/github/sisong/hpatchi.java b/builds/android_ndk_jni_mk/java/com/github/sisong/hpatchi.java new file mode 100644 index 0000000..1c9b93f --- /dev/null +++ b/builds/android_ndk_jni_mk/java/com/github/sisong/hpatchi.java @@ -0,0 +1,9 @@ +package com.github.sisong; + +public class hpatchi{ + // return THPatchiResult, 0 is ok + // 'diffFileName' file is create by hdiffi app,or by create_lite_diff() + // cacheMemory recommended 32*2024 256*1024 ... + public static native int patch(String oldFileName,String diffFileName, + String outNewFileName,long cacheMemory); +} diff --git a/decompresser_demo.h b/decompresser_demo.h index 2b57532..2ac8f2e 100644 --- a/decompresser_demo.h +++ b/decompresser_demo.h @@ -34,9 +34,9 @@ # include "zlib.h" // http://zlib.net/ https://github.com/madler/zlib #undef Byte #define ZLIB_INTERNAL -# include "inftrees.h" //for code +# include "inftrees.h" //for inflate_state::code #undef ZLIB_INTERNAL -# include "inflate.h" //for inflate_state +# include "inflate.h" //for inflate_state #endif typedef struct zlib_TStream{ hpi_TInputStreamHandle codeStream; diff --git a/hdiffi_import_patch.h b/hdiffi_import_patch.h index 0e81e77..8d100b6 100644 --- a/hdiffi_import_patch.h +++ b/hdiffi_import_patch.h @@ -13,7 +13,7 @@ extern "C" { #endif #define HPATCHLITE_VERSION_MAJOR 0 #define HPATCHLITE_VERSION_MINOR 4 -#define HPATCHLITE_VERSION_RELEASE 1 +#define HPATCHLITE_VERSION_RELEASE 2 #define _HPATCHLITE_VERSION HPATCHLITE_VERSION_MAJOR.HPATCHLITE_VERSION_MINOR.HPATCHLITE_VERSION_RELEASE #define _HDIFFPATCH_QUOTE(str) #str diff --git a/tinyuz b/tinyuz index c8f0252..e687fd6 160000 --- a/tinyuz +++ b/tinyuz @@ -1 +1 @@ -Subproject commit c8f025290d817581a6d533b093ec488baef98f35 +Subproject commit e687fd643371013d71840eb8a2662d1ec60f9980