diff --git a/minizip-ng/BUILD.gn b/minizip-ng/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..71b8ebb1c90fd2416155436e9fc358e1b0e9cb24 --- /dev/null +++ b/minizip-ng/BUILD.gn @@ -0,0 +1,195 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") + +declare_args() { + enable_minizip_test = false +} + +config("libminizip_config") { + include_dirs = [ + "//third_party/openssl/include", + "//third_party/openssl/include/openssl/", + "//third_party/minizip-ng/minizip-ng", + "//third_party/bzip2", + "//third_party/zlib", + "//third_party/iconv/", + "//third_party/iconv/libiconv", + "//third_party/xz/xz/", + "//third_party/xz/xz/src/liblzma/api/", + "//third_party/zstd/zstd", + "//third_party/zstd/zstd/lib/" + ] + + cflags = [ + "-fPIC", + "-Wall", + "-Wextra", + "-frtti", + "-fexceptions", + "-std=gnu99", + "-Wno-error=missing-braces", + "-Wno-error=visibility", + "-Wno-error=unused-function", + "-Wno-error=unused-variable", + "-Wno-error=undef", + "-Wno-error=deprecated-declarations", + "-Wno-error=sign-compare", + "-Wno-error=parentheses-equality", + "-Wno-incompatible-pointer-types", + "-Wno-error=unused-parameter", + "-Wno-error=header-hygiene", + "-Wno-error=implicit-function-declaration", + "-DHAVE_BZIP2", + "-DHAVE_INTTYPES_H", + "-DHAVE_PKCRYPT", + "-DHAVE_STDINT_H", + "-DHAVE_WZAES", + "-DHAVE_ZLIB", + "-DHAVE_ZSTD", + "-DHAVE_LZMA", + "-DMZ_ZIP_SIGNING", + "-DHAVE_ICONV", + "-DLZMA_API_STATIC", + "-D_POSIX_C_SOURCE=200112L", + ] +} + +ohos_shared_library("minizip_shared") { + sources = [ + "//third_party/minizip-ng/minizip-ng/mz_compat.c", + "//third_party/minizip-ng/minizip-ng/mz_crypt.c", + "//third_party/minizip-ng/minizip-ng/mz_crypt_openssl.c", + "//third_party/minizip-ng/minizip-ng/mz_os.c", + "//third_party/minizip-ng/minizip-ng/mz_os_posix.c", + "//third_party/minizip-ng/minizip-ng/mz_strm.c", + "//third_party/minizip-ng/minizip-ng/mz_strm_buf.c", + "//third_party/minizip-ng/minizip-ng/mz_strm_bzip.c", + "//third_party/minizip-ng/minizip-ng/mz_strm_mem.c", + "//third_party/minizip-ng/minizip-ng/mz_strm_os_posix.c", + "//third_party/minizip-ng/minizip-ng/mz_strm_pkcrypt.c", + "//third_party/minizip-ng/minizip-ng/mz_strm_split.c", + "//third_party/minizip-ng/minizip-ng/mz_strm_wzaes.c", + "//third_party/minizip-ng/minizip-ng/mz_strm_zlib.c", + "//third_party/minizip-ng/minizip-ng/mz_zip.c", + "//third_party/minizip-ng/minizip-ng/mz_zip_rw.c", + "//third_party/minizip-ng/minizip-ng/mz_strm_lzma.c", + "//third_party/minizip-ng/minizip-ng/mz_strm_zstd.c", + ] + + configs = [ + ":libminizip_config" + ] + + deps = [ + "//third_party/openssl:libcrypto_shared", + "//third_party/zlib:libz_shared", + "//third_party/bzip2:libbz2", + "//third_party/iconv:iconv", + "//third_party/zstd:zstd_shared", + "//third_party/xz:libxz", + ] + + part_name = "minizip" +} + +ohos_executable("minizip") { + sources = [ + "./minizip-ng/minizip.c", + ] + + cflags = [ + "-DHAVE_BZIP2", + "-DHAVE_ICONV", + "-DHAVE_INTTYPES_H", + "-DHAVE_LZMA", + "-DHAVE_PKCRYPT", + "-DHAVE_STDINT_H", + "-DHAVE_WZAES", + "-DHAVE_ZLIB", + "-DHAVE_ZSTD", + "-DLZMA_API_STATIC", + "-DMZ_ZIP_SIGNING", + "-D_POSIX_C_SOURCE=200112L", + ] + + deps = [ + "//third_party/minizip-ng:minizip_shared", + ] + + part_name = "minizip" +} + +ohos_executable("minigzip") { + sources = [ + "./minizip-ng/minigzip.c", + ] + + public_configs = [ ":libminizip_config" ] + + deps = [ + "//third_party/minizip-ng:minizip_shared", + ] + + part_name = "minizip" +} + +config ("minizip_config") { + include_dirs = [ + "//third_party/minizip-ng/minizip-ng", + "//third_party/minizip-ng/minizip-ng/test", + ] + + cflags = [ + "-DHAVE_COMPAT", + "-DHAVE_BZIP2", + "-DHAVE_INTTYPES_H", + "-DHAVE_PKCRYPT", + "-DHAVE_STDINT_H", + "-DHAVE_WZAES", + "-DHAVE_ZLIB", + "-DHAVE_LZMA", + "-DHAVE_ZSTD", + "-DMZ_ZIP_SIGNING", + "-DZLIB_COMPAT", + "-D_POSIX_C_SOURCE=200112L" + ] +} + +ohos_executable("minizip_test") { + sources = [ + "./minizip-ng/test/test.c" + ] + + public_configs = [ ":minizip_config" ] + + deps = [ + "//third_party/minizip-ng:minizip_shared", + ] + + part_name = "minizip" +} + + +group ("samples") { + if(enable_minizip_test) { + deps = [ + ":minizip", + ":minigzip", + ":minizip_test", + ] + } else { + deps = [] + } +} diff --git a/minizip-ng/README.OpenSource b/minizip-ng/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..c96ef5a5000de7df17f59a81fd5d5e89ab50d1e7 --- /dev/null +++ b/minizip-ng/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "minizip-ng", + "License": "zlib", + "License File": "COPYRIGHT", + "Version Number": "3.0.4", + "Owner": "caiqi14@huawei.com", + "Upstream URL": "https://github.com/zlib-ng/minizip-ng", + "Description": "minizip-ng is a zip manipulation library written in C that is supported on Windows, macOS, and Linux." + } +] \ No newline at end of file diff --git a/minizip-ng/README_zh.md b/minizip-ng/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..14ffe46ec138fb85def2628e7b1c442d96ad30fb --- /dev/null +++ b/minizip-ng/README_zh.md @@ -0,0 +1,17 @@ +# minizip-ng 三方库说明 +## 功能简介 +minizip是一个用C编写的zip文件操作库。 +## 使用约束 + +- IDE版本:DevEco Studio 3.0 Beta4 +- ROM版本:OpenHarmony3.2 Beta1 +- API版本:9 +- 三方库版本:3.0.4 +- 当前适配的功能:完成了创建和解压BZIP2、LZMA、XZ和ZSTD格式的zip文件 +- [License : zlib](https://github.com/zlib-ng/minizip-ng/tree/3.0.4/LICENSE) + +## 集成方式 + ++ [系统Rom包集成](docs/rom_integrate.md) + + diff --git a/minizip-ng/bundle.json b/minizip-ng/bundle.json new file mode 100644 index 0000000000000000000000000000000000000000..c86c812eb9286b4d84ae17e8f537e1898c0e82d5 --- /dev/null +++ b/minizip-ng/bundle.json @@ -0,0 +1,33 @@ +{ + "name": "@ohos/minizip", + "description": "minizip-ng is a zip manipulation library written in C that is supported on Windows, macOS, and Linux.", + "version": "3.1", + "license": "zip", + "publishAs": "code-segment", + "segment": { + "destPath": "third_party/minizip-ng" + }, + "dirs": {}, + "scripts": {}, + "readmePath": { + "en": "README" + }, + "component": { + "name": "minizip", + "subsystem": "thirdparty", + "syscap": [], + "features": [], + "adapted_system_type": [], + "rom": "", + "ram": "", + "deps": { + "components": [], + "third_party": [] + }, + "build": { + "sub_component": ["//third_party/minizip-ng:minizip_shared","//third_party/minizip-ng:samples"], + "inner_kits": [], + "test": [] + } + } +} \ No newline at end of file diff --git a/minizip-ng/docs/pic/results.png b/minizip-ng/docs/pic/results.png new file mode 100644 index 0000000000000000000000000000000000000000..4ee6b6d75392e0effb99cfa512ed60873649f94a Binary files /dev/null and b/minizip-ng/docs/pic/results.png differ diff --git a/minizip-ng/docs/rom_integrate.md b/minizip-ng/docs/rom_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..9a95619a2e2b0190b65a2756b7e7448a49d02f1e --- /dev/null +++ b/minizip-ng/docs/rom_integrate.md @@ -0,0 +1,108 @@ +# minizip-ng如何集成到系统Rom +## 准备源码工程 +本库是基于OpenHarmony-v3.2-Beta1版本,在润和RK3568开发板上验证的。如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 +## 准备系统Rom源码 +源码获取方法请参照:[OpenHarmony源码下载](https://gitee.com/openharmony/docs/blob/OpenHarmony-v3.2-Beta1/zh-cn/release-notes/OpenHarmony-v3.2-beta1.md#%E6%BA%90%E7%A0%81%E8%8E%B7%E5%8F%96) +## 增加构建脚本及配置文件 +- 下载本仓库代码 + ``` + cd ~/ + git clone git@gitee.com:openharmony-sig/tpc_c_cplusplus.git --depth=1 # 将本仓库下载到本地 + ``` +- 仓库代码目录结构说明 + ``` + tpc_c_cplusplus/minizip-ng + |-- docs # 存放三方库相关文档的文件夹 + |-- BUILD.gn # 构建脚本,支持rom包集成 + |-- bundle.json # 三方库组件定义文件 + ├── README.OpenSource # 说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md + ``` +- 将本仓库文件夹拷贝到third_party下 + ``` + cp ~/tpc_c_cplusplus/minizipi-ng ~/openharmony/third_party/ -rf + ``` +## 准备三方库源码 +- 将源码下载到minizip-ng目录并将其解压出来。 +``` +cd ~/OpenHarmony/third_party/minizip-ng # 进入到minizip目录 +git clone -b 3.0.4 https://github.com/zlib-ng/minizip-ng.git # 下载三方库 +``` +## 系统Rom中引入三方库测试程序 +准备完三方库代码后,我们需要将三方库加入到编译构建体系中。标准系统编译构建可以参考文档[标准系统编译构建指导](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/device-dev/subsystems/subsys-build-standard-large.md)。 +我们默认三方库是属于OpenHarmony的thirdparty子系统,如果需要自己定义子系统参考文档[如何为三方库组件中添加一个三方库](https://gitee.com/openharmony-sig/knowledge/blob/master/docs/openharmony_getstarted/port_thirdparty/README.md) +在OpenHarmony源码的vendor/hihope/rk356/config.json文件,新增需要编译的组件,如下: +``` +{ + "subsystem": "thirdparty", + "components": [ + { + "component": "musl", + "features": [] + }, + { + "component": "minizip", + "features": [] + } + ] +} +``` +## 系统Rom中引入三方库测试程序 +在OpenHarmony源码的vendor/hihope/rk356/config.json文件,对应组件的features中打开编译选项,如下: +``` +{ + "subsystem": "thirdparty", + "components": [ + { + "component": "musl", + "features": [] + }, + { + "component": "minizip", + "features": ["enable_minizip_test=true"] + } + ] +} +``` +## 编译工程 +在OpenHarmony源码根目录下 +``` +cd ~/openharmony +``` +- 选择产品 +``` +hb set # 该命令会列出所有可选平台,这里我们选择rk3568 +``` +- 运行编译 +``` +hb build --target-cpu arm64 # 编译64位系统使用:arm64, 编译32位系统使用:arm +``` +- 生成文件的路径,可执行文件和库文件都在out/rk3568/thirdparty/minizip目录下,同时也打包到了镜像中 +## 运行效果 +将编译生成的库和测试文件放到板子上运行,为避免每次将文件推入设备都烧录整个镜像,我们使用hdc_std工具将文件推到开发板上 +- 首先将hdc_std工具编译出来 + ``` + hb set # 首先,源码根目录下使用hb set 选择产品ohos-sdk + hb build # 然后,编译。最后,工具编译出来在out/sdk/ohos-sdk/windows/toolchains/hdc_std.exe + ``` +- 将工具拷贝到Windows,可以为工具目录配置环境变量,也可以在工具所在目录打开windows命令行 +- 将原生库测试需要的所有文件打包成minizip.tar,并拷贝到windows下 +- 将文件推送到开发板,在windows命令行进行如下操作 + ``` + hdc_std shell mount -o remount,rw / # 修改系统权限为可读写 + hdc_std file send minizip.tar / # 将文件包推入开发板 + hdc_std shell # 进入开发板 + tar xvf minizip.tar # 解压 + cd minizip # 进入minizip目录 + mv libminizip_shared.z.so /system/lib64/ # 64位系统需要将库文件拷贝到系统lib64目录, 32位系统则是lib目录 + ``` +- 运行测试程序 + 程序安装完后,由于测试用例较多,我们准备了1个测试文件 test.c,测试了该库常用的zip文件压缩和解压缩功能,并和期望结果做对比,内容一致,如图: + ![results](pic/results.png) +## 参考资料 +- [润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) +- [OpenHarmony源码下载](https://gitee.com/openharmony/docs/blob/OpenHarmony-v3.2-Beta1/zh-cn/release-notes/OpenHarmony-v3.2-beta1.md#%E6%BA%90%E7%A0%81%E8%8E%B7%E5%8F%96) +- [标准系统编译构建指导](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/device-dev/subsystems/subsys-build-standard-large.md) +- [如何为三方库组件中添加一个三方库](https://gitee.com/openharmony-sig/knowledge/blob/master/docs/openharmony_getstarted/port_thirdparty/README.md) \ No newline at end of file