How to contribute to a C/C++ third-party library on OpenHarmony

Getting your Trinity Audio player ready...

Brief introduction

Third-party libraries refer to the services or modules provided by other companies or organizations that can continue to prosper the ecosystem of OpenAtom OpenHarmony (“OpenHarmony”). This topic describes how to port a C/C++ library on the OpenHarmony standard system and submit the library to the community.

Living In Harmony is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.

Subscribed

Third-party library migration problems and solutions

As can be seen from the figure above, there are two main problems with third-party library porting: runtime dependencies are incompatible with the compilation structure.

Runtime dependencies

Runtime dependencies mainly include system APIs, runtime C libraries, and hardware-related. General libraries do not involve hardware-related dependencies, unless there are some libraries specifically for hardware processing (such as GPU acceleration), this article will not explain such libraries in detail, we only need to scan the library through the API scanning tool to analyze whether there are such dependencies. Instructions for using the dependent scanning tool and download address: C/C++ third-party library E2E scanning tool

The compilation structure is incompatible

Nowadays, there are many kinds of compilation structures, and how to add them to the OpenHarmony compilation and build system is a common and unavoidable problem in the porting process. OpenHarmony builds support the following forms:

  • Pure GN compilation
  • GN plus action/exec_script

Nowadays, most third-party libraries are compiled through cmake, and we can add them to OpenHarmony’s build system in the second way above. However, in the standard system, the generated library files cannot be automatically copied to the system firmware by using the action method, so this article will focus on the pass Analyze the cmake process, manually build GN rules for porting, and compile a third-party library.

Migration process of the third-party database

The migration of the third-party library can be roughly divided into four parts, as shown in the following figure:

Next, we will take the manual construction of gn to migrate OpenJPEG to OpenHamony 3.2 Beta1 as an example to describe the entire migration process. To verify the development board of this library, we use RK3568. For more information about OpenHamony 3.2 Beta code, please refer to the official document: OpenHarmony 3.2 Beta 1. Environment construction reference: Runhe RK3568 development board standard equipment to get started quickly(This third party library process applies to OpenHarmony latest versions, 4.0 API 10 and 4.1 API 11+ up)

Native library preparation

Download the code

In the OpenHarmony/third_party directory, enter the following command to download the source code of openjpeg (it is recommended to download the latest branch code):

cd OpenHarmony/third_party/
git clone git@github.com:uclouvain/openjpeg.git -b v2.5.0

Generate a Makefile

From the source code directory structure, it can be analyzed that openjpeg is compiled by Cmake, so we need to perform the following steps to generate the Makefile:

cd OpenHarmony/third_party/openjpeg
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release

Analyze compilation dependencies

External library dependency analysis

Analyze the log information in the process of generating a makefile to find the dependencies of the database on other databases, and generally have the following situations during the log analysis:

  • The library name cannot be found in the log, and some third-party libraries will not print it in the log when they can find the corresponding library under the system when generating the Makefile file.
  • Libraries that were found or not found can be found in the logs
Other third-party libraries depend
  • We assume that none of these libraries exist on OpenHarmony, so they need to be analyzed
    1. OS-developed libraries, which can be found in OpenHarmony’s third_party directory.
    2. Undeveloped libraries, and those that are planned, can be prioritized for porting, escalating, and re-evaluating the effort.
    3. Undeveloped libraries that are not in the plan, analyze these libraries, generally these libraries are divided into two categories, (1) there is an impact on the function of the library, (2) there is no impact on the function of the library; This part needs to find the relevant place of the library to analyze the code, if it does not affect the function, you can consider ignoring it, otherwise it will be reported and the workload problem will be re-evaluated.

In the process of porting third-party libraries, if there are more library dependencies, you need to pay attention to the switch of these macro definitions.

Dependency analysis of the original file

Run the make command to compile, and the source files required by the corresponding library and executable can be analyzed through the compilation process:

water@ubuntu:~/openjpeg/openjpeg/build$ make
[  1%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/thread.c.o
[  2%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/bio.c.o
[  4%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/cio.c.o
[  5%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/dwt.c.o
[  7%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/event.c.o
[  8%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/ht_dec.c.o
[ 10%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/image.c.o
[ 11%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/invert.c.o
[ 13%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/j2k.c.o
[ 14%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/jp2.c.o
[ 16%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/mct.c.o
[ 17%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/mqc.c.o
[ 19%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/openjpeg.c.o
[ 20%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/opj_clock.c.o
[ 22%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/pi.c.o
[ 23%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/t1.c.o
[ 25%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/t2.c.o
[ 26%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/tcd.c.o
[ 28%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/tgt.c.o
[ 29%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/function_list.c.o
[ 31%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/opj_malloc.c.o
[ 32%] Building C object src/lib/openjp2/CMakeFiles/openjp2_static.dir/sparse_array.c.o
[ 34%] Linking C static library ../../../bin/libopenjp2.a
[ 34%] Built target openjp2_static
[ 35%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/thread.c.o
[ 37%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/bio.c.o
[ 38%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/cio.c.o
[ 40%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/dwt.c.o
[ 41%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/event.c.o
[ 43%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/ht_dec.c.o
[ 44%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/image.c.o
[ 46%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/invert.c.o
[ 47%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/j2k.c.o
[ 49%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/jp2.c.o
[ 50%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/mct.c.o
[ 52%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/mqc.c.o
[ 53%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/openjpeg.c.o
[ 55%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/opj_clock.c.o
[ 56%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/pi.c.o
[ 58%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/t1.c.o
[ 59%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/t2.c.o
[ 61%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/tcd.c.o
[ 62%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/tgt.c.o
[ 64%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/function_list.c.o
[ 65%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/opj_malloc.c.o
[ 67%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/sparse_array.c.o
[ 68%] Linking C shared library ../../../bin/libopenjp2.so
[ 68%] Built target openjp2
[ 70%] Building C object src/bin/jp2/CMakeFiles/opj_dump.dir/opj_dump.c.o
[ 71%] Building C object src/bin/jp2/CMakeFiles/opj_dump.dir/convert.c.o
[ 73%] Building C object src/bin/jp2/CMakeFiles/opj_dump.dir/convertbmp.c.o
[ 74%] Building C object src/bin/jp2/CMakeFiles/opj_dump.dir/index.c.o
[ 76%] Building C object src/bin/jp2/CMakeFiles/opj_dump.dir/__/common/color.c.o
[ 77%] Building C object src/bin/jp2/CMakeFiles/opj_dump.dir/__/common/opj_getopt.c.o
[ 79%] Linking C executable ../../../bin/opj_dump
[ 79%] Built target opj_dump
[ 80%] Building C object src/bin/jp2/CMakeFiles/opj_compress.dir/opj_compress.c.o
[ 82%] Building C object src/bin/jp2/CMakeFiles/opj_compress.dir/convert.c.o
[ 83%] Building C object src/bin/jp2/CMakeFiles/opj_compress.dir/convertbmp.c.o
[ 85%] Building C object src/bin/jp2/CMakeFiles/opj_compress.dir/index.c.o
[ 86%] Building C object src/bin/jp2/CMakeFiles/opj_compress.dir/__/common/color.c.o
[ 88%] Building C object src/bin/jp2/CMakeFiles/opj_compress.dir/__/common/opj_getopt.c.o
[ 89%] Linking C executable ../../../bin/opj_compress
[ 89%] Built target opj_compress
[ 91%] Building C object src/bin/jp2/CMakeFiles/opj_decompress.dir/opj_decompress.c.o
[ 92%] Building C object src/bin/jp2/CMakeFiles/opj_decompress.dir/convert.c.o
[ 94%] Building C object src/bin/jp2/CMakeFiles/opj_decompress.dir/convertbmp.c.o
[ 95%] Building C object src/bin/jp2/CMakeFiles/opj_decompress.dir/index.c.o
[ 97%] Building C object src/bin/jp2/CMakeFiles/opj_decompress.dir/__/common/color.c.o
[ 98%] Building C object src/bin/jp2/CMakeFiles/opj_decompress.dir/__/common/opj_getopt.c.o
[100%] Linking C executable ../../../bin/opj_decompress
[100%] Built target opj_decompress

As can be seen from the above process, the files on which each built target depends are composed of files after the previous target (if the previous target is generated by it) and before the target is generated. Such as generating libopenjp2.so (Built target openjp) Files are files after Built target openjp2_static and before Built target openjp:

[ 35%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/thread.c.o
[ 37%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/bio.c.o
[ 38%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/cio.c.o
[ 40%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/dwt.c.o
[ 41%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/event.c.o
[ 43%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/ht_dec.c.o
[ 44%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/image.c.o
[ 46%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/invert.c.o
[ 47%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/j2k.c.o
[ 49%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/jp2.c.o
[ 50%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/mct.c.o
[ 52%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/mqc.c.o
[ 53%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/openjpeg.c.o
[ 55%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/opj_clock.c.o
[ 56%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/pi.c.o
[ 58%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/t1.c.o
[ 59%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/t2.c.o
[ 61%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/tcd.c.o
[ 62%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/tgt.c.o
[ 64%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/function_list.c.o
[ 65%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/opj_malloc.c.o
[ 67%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/sparse_array.c.o
Dependency library and cflag flag analysis

After the make compilation is completed, a directory corresponding to the source code directory structure will be generated in the build directory, and there will be build.make, depend.make, flags.make, and link.txt in the CMakeFiles/xxx.dir directory. By analyzing these four files, we can find the corresponding dependencies and the cflag flag.

build.makeGenerate the source file for the targetdepend.makeOther C source files that need to be depended uponflags.makecflagslink.txtInformation about linked libraries

For example, if the source code directory of libopenjp2 generated in openjpeg is src/lib/openjp2, the corresponding folder src/lib/CMakeFiles/openjp2 .dir will be generated in the build, and you can view four files in this folder: build.mak, depend.make, flags.make, link.txt, and the relevant contents are as follows:

depend.make:

# Empty dependencies file for openjp2.
# This may be replaced when dependencies are built.

flags.make:

# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.16

# compile C with /usr/bin/cc
C_FLAGS = -fPIC   -Wall -Wextra -Wconversion -Wunused-parameter -Wdeclaration-after-statement -Werror=declaration-after-statement

C_DEFINES = -DMUTEX_pthread -Dopenjp2_EXPORTS

C_INCLUDES = -I/home/water/openjpeg/openjpeg/build/src/lib/openjp2

link.txt:

/usr/bin/cc -fPIC -O3 -DNDEBUG  -shared -Wl,-soname,libopenjp2.so.7 -o ../../../bin/libopenjp2.so.2.5.0 CMakeFiles/openjp2.dir/thread.c.o CMakeFiles/openjp2.dir/bio.c.o CMakeFiles/openjp2.dir/cio.c.o CMakeFiles/openjp2.dir/dwt.c.o CMakeFiles/openjp2.dir/event.c.o CMakeFiles/openjp2.dir/ht_dec.c.o CMakeFiles/openjp2.dir/image.c.o CMakeFiles/openjp2.dir/invert.c.o CMakeFiles/openjp2.dir/j2k.c.o CMakeFiles/openjp2.dir/jp2.c.o CMakeFiles/openjp2.dir/mct.c.o CMakeFiles/openjp2.dir/mqc.c.o CMakeFiles/openjp2.dir/openjpeg.c.o CMakeFiles/openjp2.dir/opj_clock.c.o CMakeFiles/openjp2.dir/pi.c.o CMakeFiles/openjp2.dir/t1.c.o CMakeFiles/openjp2.dir/t2.c.o CMakeFiles/openjp2.dir/tcd.c.o CMakeFiles/openjp2.dir/tgt.c.o CMakeFiles/openjp2.dir/function_list.c.o CMakeFiles/openjp2.dir/opj_malloc.c.o CMakeFiles/openjp2.dir/sparse_array.c.o  -lm -lpthread 

From the above file, we can analyze the libopenjp2.so dependency library and C_FLAGS information

Libraries that need to be linked:
 -lm -lpthread 
The C_FLAGS tag that the compiler needs to add:
 C_FLAGS = -O3 -DNDEBUG -fPIC   -ffast-math -Wall -Wextra -Wconversion -Wunused-parameter -Wdeclaration-after-statement -Werror=declaration-after-statement

Test cases and their corresponding static libraries are also analyzed in this way.

Build gn

Based on the information obtained from the above analysis, we can build a BUILD.gn file based on the libopenjp2.so of the OpenHarmony compilation system. Create a BUILD.gn in the openjpeg directory.

cd OpenHarmony/third_party/openjpeg
touch BUILD.gn

Add the source files analyzed above, as well as the dependent libraries and FLAGs, to the BUILD.gn

import("//build/ohos.gni")

#Compile CFLAG tags and libraries that need to be linked
config("openjpeg_cflag_config") {
  cflags = [ 
      "-O3" ,
      "-DNDEBUG",
      "-fPIC",
      "-ffast-math",
      "-Wall",
      "-Wextra",
      "-Wconversion",
      "-Wunused-parameter",
      "-Wdeclaration-after-statement",
      "-Werror=declaration-after-statement",
      ]
    ldflags = [
        "-lm",
        "-lpthread",
    ]
}

#Header files that need to be included
config("openjpeg_config") {
    include_dirs = [
        "//third_party/openjpeg/src/lib/openjp2"
    ]
}

#Source files that need to be included
ohos_source_set("libopenjpeg_source") {
    sources = [
        "//third_party/openjpeg/src/lib/openjp2/thread.c",
        "//third_party/openjpeg/src/lib/openjp2/bio.c",
        "//third_party/openjpeg/src/lib/openjp2/cio.c",
        "//third_party/openjpeg/src/lib/openjp2/dwt.c",
        "//third_party/openjpeg/src/lib/openjp2/event.c",
        "//third_party/openjpeg/src/lib/openjp2/ht_dec.c",
        "//third_party/openjpeg/src/lib/openjp2/image.c",
        "//third_party/openjpeg/src/lib/openjp2/invert.c",
        "//third_party/openjpeg/src/lib/openjp2/j2k.c",
        "//third_party/openjpeg/src/lib/openjp2/jp2.c",
        "//third_party/openjpeg/src/lib/openjp2/mct.c",
        "//third_party/openjpeg/src/lib/openjp2/mqc.c",
        "//third_party/openjpeg/src/lib/openjp2/openjpeg.c",
        "//third_party/openjpeg/src/lib/openjp2/opj_clock.c",
        "//third_party/openjpeg/src/lib/openjp2/pi.c",
        "//third_party/openjpeg/src/lib/openjp2/t1.c",
        "//third_party/openjpeg/src/lib/openjp2/t2.c",
        "//third_party/openjpeg/src/lib/openjp2/tcd.c",
        "//third_party/openjpeg/src/lib/openjp2/tgt.c",
        "//third_party/openjpeg/src/lib/openjp2/function_list.c",
        "//third_party/linu/src/lib/openjp2/opj_malloc.c",
        "//third_party/openjpeg/src/lib/openjp2/sparse_array.c",
    ]
}

##Generate dynamic library
ohos_shared_library("openjpeg") {
  deps = [ ":libopenjpeg_source" ]            #Dependent source file
    public_configs = [ ":openjpeg_config" ]  #Dependent header file configuration information
    configs = [ ":openjpeg_cflag_config" ]   #Dependent CFLAGS configuration information
    part_name = "openjpeg_lib"
}

Referring to the above methods, you can build GN files for all OpenJPG2 test cases, taking test_title_decoder as an example:

cd OpenHarmony/third_party/openjpeg/tests/
touch BUILD.gn

Add the following code to the BUILD.gn based on the dependency analysis of the test case:

import("//build/ohos.gni")

#Header files that need to be included
config("openjpeg_config") {
    include_dirs = [
        "//third_party/openjpeg/src/lib/openjp2",
        "//third_party/openjpeg/src/bin/common",
        "//third_party/openjpeg/src/lib/jp2",
        "//third_party/openjpeg/src/bin/jp2",
    ]
}

##Generate executable file
ohos_executable("test_title_decoder") {
  sources = [
    "test_title_decoder.c",
    "../src/bin/common/opj_getopt.c"
  ]
  deps = [ "//third_party/openjpeg:openjpeg" ]         #Dependent openjp2 library
    configs = [ ":openjpeg_config" ]                   #Dependent header file configuration information
    part_name = "openjpeg_lib"
}

Note: Other test cases can also be written to the GN file with different ohos_executable names, such as:

build.gn

Join the compilation and build system

Standard system compilation and construction can refer to the document standard system compilation and construction guidance.

Define components

The tripartite library is added to the thirdparty subsystem by default,The ported tripartite library is used as a component of the thirdparty subsystem. We need to create a new bundle in the third_party/openjpeg directory.json (For the option description of this file, refer to the bundle in the document compilation and construction.json part):

{
  "name": "@ohos/openjpeg",
  "description": "",
  "version": "2.1",
  "license": "BSD",
  "publishAs": "code-segment",
  "segment": {
      "destPath": "third_party/openjpeg"
  },
  "dirs": {},
  "scripts": {},
  "readmePath": {
      "en": "README"
  },
  "component": {
      "name": "iconv",
      "subsystem": "thirdparty",
      "syscap": [],
      "features": [],
      "adapted_system_type": [],
      "rom": "",
      "ram": "",
      "deps": {
          "components": [],
          "third_party": []
      },
      "build": {
          "sub_component": ["//third_party/openjpeg:openjpeg"],
          "inner_kits": [],
          "test": []
      }
  }
}

Reference component

When building gn, the dynamic libraries and executable programs we define are all our target modules. In order for the target module to be automatically packaged into the firmware by the system after compilation, we need to reference the corresponding components:

part_name = "openjpeg"

Product reference

After defining the components, we also need to add the components to the product definition. Taking rk3568 as an example, the product definition file exists in vendor/hihope/rk3568/config.json, we need to add the following to config.In json:

{
  "subsystem": "thirdparty",
  "components": [
   {
    "component": "musl",
    "features": []
   },
## The following new component informationProduct reference
   {
    "component": "openjpeg",
    "features": []
   }
  ]
}

compile

After all the content is added, execute the following command to compile:

hb set      ## Select the product type, here we choose rk3568
hb build -f ## Compile in full, if you compile a 64-bit system, execute hb build --target-cpu arm64

After the compilation is complete, you can /out/rk3568/packages/phone/system/lib See the compiled and generated in the directory libopenjpeg.z.so file.

ls -l out/rk3568/packages/phone/system/lib/libopenjpeg.z.so
-rwxr-xr-x 1 root root 286148 Mar 23 18:59 libopenjpeg.z.so

In the out/rk3568/packages/phone/system/bin directory, see the test files we compiled test_tile_encoder etc

ls -l out/rk3568/packages/phone/system/bin/test_*
-rwxr-xr-x 1 root root 286148 Mar 23 18:59 test_decode_area
-rwxr-xr-x 1 root root 286148 Mar 23 18:59 test_tile_decoder
-rwxr-xr-x 1 root root 286148 Mar 23 18:59 test_tile_encoder

Test

There are many test cases in the tests directory of the open source library, and the CMakeLists.txt file in the test directory will generate some test files for verification, which will give some test methods, as follows:

test2

Package the library files, test applications, and test files generated by OpenHarmony, push the compressed package to the rk3568 development board with the hdc_std command, and perform the corresponding test operations.

  1. Reload the system so that you can push the package to the board
hdc_std shell          ## Enter the development board system
mount -o remount,rw /  ## Reload the system to read and write
mkdir openjpeg         ## Create an openjpeg folder to store test cases
exit                   ## Exit the development board system
  1. Push the package to the development board
hdc_std file send openjpej.tar /openjpeg
  1. Decompress the package and copy the library file to the corresponding directory
hdc_std shell
cd openjpeg
tar -xvf openjpej.tar
cp libopenjp2.z.so /system/lib/  ## If the system is 64-bit: cp libopenjp2.z.so /system/lib64
  1. Execute the test procedure
./test_tile_encoder 3 2000 2000 1000 1000 8 1 tte1.j2k 64 64 4 1 1 1 256 256
  1. Test result output
test_result

At this point, the migration of the entire library is complete.

Third-party library submission

After porting a third-party library, we need to submit the library to the community, the OpenHarmony C/C++ third-party library SIG repository. At present, the repository stores the relevant adaptation script files of the third-party library after the migration.

Submissions

  • README. OpenSource, a document that records the open source information of third-party libraries, the basic content is as follows:
[
    {
      "Name": "",             ## Library name
      "License": "",          ## Open source protocol
      "License File": "",     ## Open source file, generally open source projects will come with this file
      "Version Number": "",   ## Version of the library
      "Owner": "",            ## author
      "Upstream URL": "",     ## Address of the open source library
      "Description": ""       ## Description of the library
    }
]
  • Adapt to compilation scriptsThere are two types of adaptation scripts
    1. gn script: a third-party library that is suitable for applications compiled on the OpenHarmony source code, and the so compiled by the third-party library will eventually be packaged into the system ROM together with the system firmware.
    2. cmake script: This is suitable for calling when developing NAPI interfaces on the IDE, and the so compiled by the third-party library will be packaged into the hap package together with the application.
  • Adaptation files
    1. The native library uses some configuration files generated when make or cmake is used according to the current configuration. For example, the config.h configuration file is more common.
    2. If the ported third-party library involves APIs or drivers that are not supported by OpenHarmony, re-adapt the relevant code files.
  • Adaptation to the instruction documentThe documentation needs to specify the following:
    1. The version selected by the third-party library.
    2. Compatible OpenHarmony version and/or API version
    3. For the third-party libraries used on the IDE, you also need to specify the version of the IDE and the configuration of the model in the corresponding project
    4. When it comes to toolchains, you need to provide a toolchain version
    5. If there is a modification to the file, you need to explain the modification point and the reason for the modification
    6. Use of adapted files
  • If you are involved in the source code submission, you also need to provide the OAT.xml, OAT open source review configuration, for more information, please refer to OAT open source review.

Submission Steps

For detailed steps, please refer to the guidance document on how to submit a PR.

FAQ

  • What should I do if I don’t print the corresponding target and its dependent files when I compile make?The build.make file is mentioned when analyzing compilation dependencies, which contains the definition of the target and the source file of the dependencies.As mentioned above openjp2.so src/lib/openjp2/CMakeFiles/openjp2.dir/build.make will be generated under build, where you can find the following content:
build.make
  • What if my ported library doesn’t have cmake?This article focuses on porting third-party libraries by building gns by cmake, and for other methods, you can build gns by analyzing Makefile files.
  • What should I do if the XXX interface is not defined when compiled?This issue occurs due to the following points to be confirmed:
    1. Confirm that the source file is fully added
    2. Check whether to add a header file and the header file path