diff --git a/thirdparty/realm-core/HPKBUILD b/thirdparty/realm-core/HPKBUILD new file mode 100644 index 0000000000000000000000000000000000000000..0fdf140fbb7d2a5f98d4f352355564adad29d6e5 --- /dev/null +++ b/thirdparty/realm-core/HPKBUILD @@ -0,0 +1,102 @@ +# Copyright (c) 2023 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. + +# Contributor: 小肉头君 +# Maintainer: 小肉头君 +pkgname=realm-core +pkgver=v14.12.0 +pkgrel=0 +pkgdesc="Core database component for the Realm Mobile Database SDKs." +url="https://github.com/realm/realm-core" +archs=("armeabi-v7a" "arm64-v8a") +license=("Apache-2.0 license") +depends=("zlib" "openssl_1_1_1w" "libuv") +makedepends=() +source="https://github.com/realm/$pkgname.git" + +autounpack=false +downloadpackage=false +buildtools="cmake" +builddir=$pkgname-${pkgver:1} +packagename=$builddir.tar.gz +cloneFlag=true +patchflag=true + +prepare() { + if $cloneFlag + then + git clone -b $pkgver $source $builddir > $publicbuildlog 2>&1 + if [ $? -ne 0 ] + then + echo "$pkgname git clone $source error." + return -1 + fi + cd $builddir + git checkout $pkgver + if [ $? -ne 0 ] + then + echo "$pkgname git checkout $pkgver error." + return -2 + fi + git submodule update --init --recursive >> $publicbuildlog 2>&1 + if [ $? -ne 0 ] + then + echo "$pkgname git submodule update error." + return -3 + fi + cloneFlag=false + cd $OLDPWD + fi + if $patchflag + then + cd $builddir + patch -p1 < `pwd`/../realm-core_oh_pkg.patch + # patch只需要打一次,关闭打patch + patchflag=false + cd $OLDPWD + fi + mkdir -p $builddir/$ARCH-build +} + +build() { + cd $builddir + # cmake 要求3.22.1以上版本,所以需要使用系统的cmake + cmake "$@" -DZLIB_ROOT=$LYCIUM_ROOT/usr/zlib/$ARCH/ \ + -DOPENSSL_ROOT_DIR=$LYCIUM_ROOT/usr/openssl_1_1_1w/$ARCH \ + -DLibUV_INCLUDE_DIR=$LYCIUM_ROOT/usr/libuv/$ARCH/include \ + -DOPENSSL_INCLUDE_DIR=$LYCIUM_ROOT/usr/openssl_1_1_1w/$ARCH/include \ + -DOPENSSL_LIBRARIES="$LYCIUM_ROOT/usr/openssl_1_1_1w/$ARCH/lib/libssl.so;$LYCIUM_ROOT/usr/openssl_1_1_1w/$ARCH/lib/libcrypto.so" \ + -B$ARCH-build -S./ > $buildlog 2>&1 + $MAKE VERBOSE=1 -C $ARCH-build >> $buildlog 2>&1 + ret=$? + cd $OLDPWD + return $ret + +} + +package() { + cd $builddir + $MAKE VERBOSE=1 -C $ARCH-build install >> $buildlog 2>&1 + cd $OLDPWD +} + +check() { + echo "The test must be on an OpenHarmony device!" + # real test cmd + # ctest +} + +# 清理环境 +cleanbuild() { + rm -rf ${PWD}/$builddir +} diff --git a/thirdparty/realm-core/HPKCHECK b/thirdparty/realm-core/HPKCHECK new file mode 100644 index 0000000000000000000000000000000000000000..5524b6d3d8ad107a1f75f75330b686fa68fb696e --- /dev/null +++ b/thirdparty/realm-core/HPKCHECK @@ -0,0 +1,31 @@ +# Copyright (c) 2023 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. + +# Contributor: 小肉头君 +# Maintainer: 小肉头君 + +source HPKBUILD > /dev/null 2>&1 +logfile=${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${pkgname}_${ARCH}_${OHOS_SDK_VER}_test.log + +openharmonycheck() { + res=0 + cd $builddir/$ARCH-build + ctest > $logfile 2>&1 + res=$? + if [ $res -ne 0 ];then + mkdir ${LYCIUM_FAULT_PATH}/${pkgname} + cp Testing/Temporary/LastTest.log ${LYCIUM_FAULT_PATH}/${pkgname}/ + fi + cd $OLDPWD + return $res +} diff --git a/thirdparty/realm-core/OAT.xml b/thirdparty/realm-core/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..5663c536ddecb545bb824af7a320605c8072e4f4 --- /dev/null +++ b/thirdparty/realm-core/OAT.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/thirdparty/realm-core/README.OpenSource b/thirdparty/realm-core/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..8e02c0aa8bcef021cb08f0dfc6b45f4fdf519bac --- /dev/null +++ b/thirdparty/realm-core/README.OpenSource @@ -0,0 +1,38 @@ +[ + { + "Name": "realm-core", + "License": ""Apache-2.0 license", + "License File": "https://github.com/realm/realm-core/blob/master/LICENSE", + "Version Number": "v14.12.1", + "Owner": "xiafeng@huawei.com", + "Upstream URL": "https://github.com/realm/realm-core", + "Description": "Core database component for the Realm Mobile Database SDKs." + }, + { + "Name": "openssl", + "License": "OpenSSL License and Original SSLeay License", + "License File": "https://www.openssl.org/source/license-openssl-ssleay.txt", + "Version Number": "1.1.1w", + "Owner": "xiafeng@huawei.com", + "Upstream URL": "https://gitee.com/mirrors/openssl/repository/archive/OpenSSL_1_1_1w.zip", + "Description": "OpenSSL is a robust, commercial-grade, full-featured Open Source Toolkit for the Transport Layer Security (TLS) protocol formerly known as the Secure Sockets Layer (SSL) protocol." + } + { + "Name": "libuv", + "License": "MIT", + "License File": "https://github.com/libuv/libuv/blob/v1.x/LICENSE", + "Version Number": "v1.44.2", + "Owner": "xiafeng@huawei.com", + "Upstream URL": "https://github.com/libuv/libuv", + "Description": "fmt is an open-source formatting library providing a fast and safe alternative to C stdio and C++ iostreams." + }, + { + "Name": "zlib", + "License": "zlib License", + "License File": "https://github.com/madler/zlib/blob/master/LICENSE", + "Version Number": "v1.2.13", + "Owner": "xiafeng@huawei.com", + "Upstream URL": "https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz", + "Description": "A massively spiffy yet delicately unobtrusive compression library." + } +] diff --git a/thirdparty/realm-core/README_zh.md b/thirdparty/realm-core/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..272817778dd96c4c279463ee7870e7a6dd1f46a5 --- /dev/null +++ b/thirdparty/realm-core/README_zh.md @@ -0,0 +1,12 @@ +# realm-core三方库说明 +## 功能简介 +Realm Core是一个C++编写的底层数据库引擎,它提供了对多种编程语言(如Java、Swift、Objective-C等)的支持。通过封装C++库,开发者可以轻松地在自己的应用中集成和使用Realm Core。 + +## 三方库版本 +- v14.12.0 + +## 使用约束 +- [IDE和SDK版本](../../docs/constraint.md) + +## 集成方式 ++ [应用hap包集成](docs/hap_integrate.md) diff --git a/thirdparty/realm-core/SHA512SUM b/thirdparty/realm-core/SHA512SUM new file mode 100644 index 0000000000000000000000000000000000000000..87cf5bc00408b4d684bf1d3c14159ae060f63879 --- /dev/null +++ b/thirdparty/realm-core/SHA512SUM @@ -0,0 +1 @@ +d22010f45c9161fa4a4c4792c9e3751f0d230aaaab42fc686f4fbf3bbebb44e23c929c220dc03a3e37d92355eef5ce5f63c3900b3a4d4b7aab788b7addc4c75c realm-core-14.12.0.tar.gz diff --git a/thirdparty/realm-core/docs/hap_integrate.md b/thirdparty/realm-core/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..5a4a3aa5917fb588bbe3897a8bf0aea9e579d003 --- /dev/null +++ b/thirdparty/realm-core/docs/hap_integrate.md @@ -0,0 +1,87 @@ +# realm-core集成到应用hap + +本库是在RK3568开发板上基于OpenHarmony3.2 Release版本的镜像验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 + +## 开发环境 + +- [开发环境准备](../../../docs/hap_integrate_environment.md) + +## 编译三方库 + +- 下载本仓库 + + ```shell + git clone https://gitee.com/openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` + +- 三方库目录结构 + + ```shell + tpc_c_cplusplus/thirdparty/realm-core #三方库realm-core的目录结构如下 + ├── docs #三方库相关文档的文件夹 + ├── HPKBUILD #构建脚本 + ├── HPKCHECK #测试脚本 + ├── OAT.xml #OAT扫描相关文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本、license等信息 + ├── README_zh.md #三方库简介 + ├── SHA512SUM #三方库校验文件 + ├── realm-core_oh_pkg.patch #用于realm-core库编译的补丁 + ``` + +- 在lycium目录下编译三方库 + + 编译环境的搭建参考[准备三方库构建环境](../../../lycium/README.md#1编译环境准备) + + ```shell + cd lycium + ./build.sh realm-core + ``` + +- 三方库头文件及生成的库 + + 在lycium目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库 + + ```shell + realm-core/arm64-v8a realm-core/armeabi-v7a + ``` + +- [测试三方库](#测试三方库) + +## 应用中使用三方库 + +- 需要将realm-core生成的待测so文件以及其依赖的so拷贝到entry/libs目录下,如下图所示 + +![thirdparty_install_dir](pic/realm-core_libs_ide.png) + +- 在应用工程的cpp目录新建一个thirdparty目录,将生成的二进制文件以及头文件拷贝到该目录下,如下图所示 + +![thirdparty_install_dir](pic/realm-core_include_ide.png) +![thirdparty_install_dir](pic/realm-core_lib_ide.png) + +- 在最外层(cpp目录下)CMakeLists.txt中添加如下语句 + +```shell + #将三方库加入工程中 + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/realm-core/${OHOS_ARCH}/lib/librealm.a) + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/realm-core/${OHOS_ARCH}/lib/librealm-object-store.a) + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/realm-core/${OHOS_ARCH}/lib/librealm-parser.a) + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/realm-core/${OHOS_ARCH}/lib/librealm-sync.a) + #将三方库的头文件加入工程中 + target_include_directories(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/realm-core/${OHOS_ARCH}/include) +``` +## 测试三方库 + +三方库的测试使用原库自带的测试用例来做测试,[准备三方库测试环境](../../../lycium/README.md#3ci环境准备) + +进入到构建目录运行测试用例(注意arm64-v8a为构建64位的目录,armeabi-v7a为构建32位的目录),执行结果如图所示 +```shell + cd /data/tpc_c_cplusplus/thirdparty/realm-core/realm-core-14.12.0/arm64-v8a-build/ + ./ctest +``` + ![thirdparty_install_dir](pic/ctest.png) + +## 参考资料 + +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) +- [通过DevEco Studio开发一个NAPI工程](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md) diff --git a/thirdparty/realm-core/docs/pic/ctest.png b/thirdparty/realm-core/docs/pic/ctest.png new file mode 100644 index 0000000000000000000000000000000000000000..53e27443fe80eb55409ed6ab512de33f72acfaff Binary files /dev/null and b/thirdparty/realm-core/docs/pic/ctest.png differ diff --git a/thirdparty/realm-core/docs/pic/realm-core_include_ide.png b/thirdparty/realm-core/docs/pic/realm-core_include_ide.png new file mode 100644 index 0000000000000000000000000000000000000000..c245043aaf7bd1c58096e6d39066c7782ee6beed Binary files /dev/null and b/thirdparty/realm-core/docs/pic/realm-core_include_ide.png differ diff --git a/thirdparty/realm-core/docs/pic/realm-core_lib_ide.png b/thirdparty/realm-core/docs/pic/realm-core_lib_ide.png new file mode 100644 index 0000000000000000000000000000000000000000..63f530bac3c5c5e5d5192901b344901415938a63 Binary files /dev/null and b/thirdparty/realm-core/docs/pic/realm-core_lib_ide.png differ diff --git a/thirdparty/realm-core/docs/pic/realm-core_libs_ide.png b/thirdparty/realm-core/docs/pic/realm-core_libs_ide.png new file mode 100644 index 0000000000000000000000000000000000000000..f44ebb08829ddc53bb8a686d26a478048e6846d3 Binary files /dev/null and b/thirdparty/realm-core/docs/pic/realm-core_libs_ide.png differ diff --git a/thirdparty/realm-core/realm-core_oh_pkg.patch b/thirdparty/realm-core/realm-core_oh_pkg.patch new file mode 100644 index 0000000000000000000000000000000000000000..bafdba6ecb00f56f1dfebcf4c02b493a3cc52a69 --- /dev/null +++ b/thirdparty/realm-core/realm-core_oh_pkg.patch @@ -0,0 +1,63 @@ +diff -Nura realm-core-14.12.0/CMakeLists.txt realm-core-14.12.0-other/CMakeLists.txt +--- realm-core-14.12.0/CMakeLists.txt 2024-08-10 06:04:49.000000000 +0800 ++++ realm-core-14.12.0-other/CMakeLists.txt 2024-09-10 11:05:24.693192917 +0800 +@@ -289,13 +289,13 @@ + + if(REALM_ENABLE_SYNC) + option(REALM_FORCE_OPENSSL "Always use OpenSSL for SSL needs, regardless of target platform." OFF) +- if(CMAKE_SYSTEM_NAME MATCHES "^Windows|Linux|Android") ++ if(CMAKE_SYSTEM_NAME MATCHES "^Windows|Linux|Android|OHOS") + set(REALM_NEEDS_OPENSSL TRUE) + endif() + if(REALM_NEEDS_OPENSSL OR REALM_FORCE_OPENSSL) + option(REALM_INCLUDE_CERTS "Include a list of trust certificates in the build for OpenSSL certificate verification" ON) + endif() +-elseif(REALM_ENABLE_ENCRYPTION AND CMAKE_SYSTEM_NAME MATCHES "Linux|Android") ++elseif(REALM_ENABLE_ENCRYPTION AND CMAKE_SYSTEM_NAME MATCHES "Linux|Android|OHOS") + set(REALM_NEEDS_OPENSSL TRUE) + endif() + +diff -Nura realm-core-14.12.0/src/realm/util/features.h realm-core-14.12.0-other/src/realm/util/features.h +--- realm-core-14.12.0/src/realm/util/features.h 2024-08-10 06:04:49.000000000 +0800 ++++ realm-core-14.12.0-other/src/realm/util/features.h 2024-09-10 11:06:07.818574026 +0800 +@@ -212,6 +212,10 @@ + #if defined ANDROID || defined __ANDROID_API__ + #define REALM_ANDROID 1 + #define REALM_LINUX 0 ++#elif defined __OHOS__ ++#define REALM_ANDROID 0 ++#define REALM_LINUX 0 ++#define REALM_OHOS 1 + #elif defined(__linux__) + #define REALM_ANDROID 0 + #define REALM_LINUX 1 +@@ -275,7 +279,7 @@ + #define REALM_APPLE_DEVICE 0 + #endif + +-#if REALM_ANDROID || REALM_IOS || REALM_WATCHOS || REALM_TVOS || REALM_UWP ++#if REALM_ANDROID || REALM_IOS || REALM_WATCHOS || REALM_TVOS || REALM_UWP || REALM_OHOS + #define REALM_MOBILE 1 + #else + #define REALM_MOBILE 0 +diff -Nura realm-core-14.12.0/src/realm/util/thread.cpp realm-core-14.12.0-other/src/realm/util/thread.cpp +--- realm-core-14.12.0/src/realm/util/thread.cpp 2024-08-10 06:04:49.000000000 +0800 ++++ realm-core-14.12.0-other/src/realm/util/thread.cpp 2024-09-10 11:08:00.768780585 +0800 +@@ -45,13 +45,17 @@ + #if _POSIX_THREADS >= 200809L + #ifdef __GNU_LIBRARY__ + #if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 12 && !REALM_ANDROID ++#ifndef REALM_OHOS + #define REALM_HAVE_ROBUST_PTHREAD_MUTEX + #endif ++#endif + #elif !REALM_ANDROID ++#ifndef REALM_OHOS + #define REALM_HAVE_ROBUST_PTHREAD_MUTEX + #endif + #endif + #endif ++#endif + #endif + +