Build for OpenHarmony / HarmonyOS¶
NovaPhy has partial support for HarmonyOS. You can build the NovaPhy C++
modules through native compilation with DevBox. However, natively compiled
Python modules cannot be loaded by the Python interpreter because of the
strict permission strategy. Therefore, you must package NovaPhy into
python-installer and install the repackaged python-installer using
debugging tools (hdc).
Native Compile¶
vcpkg is not available on HarmonyOS. You have to download and install NovaPhy's dependencies manually.
Prerequisites¶
Steps¶
# Prepare prerequisites
export CC=clang
export CXX=clang++
python -m pip install pybind11
mkdir sysroot
# Build and install Eigen3
wget https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz
tar -xzf eigen-3.4.0.tar.gz
cd eigen-3.4.0
mkdir build
cmake -S . -B build --install-prefix="$(pwd)/../sysroot"
cmake --install build
cd ..
# Build and install TinyXML
wget https://github.com/leethomason/tinyxml2/archive/refs/tags/11.0.0.tar.gz
tar -xzf 11.0.0.tar.gz
cd tinyxml2-11.0.0
mkdir build
cmake -S . -B build --install-prefix="$(pwd)/../sysroot"
cmake --install build
cd ..
# Build NovaPhy
cd NovaPhy
mkdir build
cmake -S . -B build \
"-DCMAKE_PREFIX_PATH=$(pwd)/../sysroot;$(python -m pybind11 --cmakedir)"
Cross Compile on Linux¶
For cross-compiling and packaging python-installer on Linux,
the script scripts/ohos/build.sh can complete the process automatically.
But before using the script, some configuration is needed.
Signing Certificate¶
You must generate the certificate for python-installer yourself:
- Download python-installer provided by OpenHarmony PC Developer.
- Open the project in DevEco Studio. Note that DevEco Studio only supports Windows and macOS. (If you have another method to obtain the certificate, this step is unnecessary.)
- Generate signature information via DevEco Studio.
After these steps, the build-profile.json of python-installer will
contain a snippet similar to:
{
"name": "default",
"type": "HarmonyOS",
"material": {
"certpath": "path-to-cer",
"keyAlias": "debugKey",
"keyPassword": "<redacted>",
"profile": "path-to-p7b",
"signAlg": "SHA256withECDSA",
"storeFile": "path-to-p12",
"storePassword": "<redacted>"
}
}
Copy the snippet and save it to a JSON file (e.g. sign-config.json).
All three paths in the configuration must share a common parent directory.
Build Script¶
You also need the HarmonyOS command line tools.
export OHOS_CLI=/path/to/ohos-command-tools
./scripts/ohos/build.sh -S . -B build-ohos -s sign-config.json
The script will build python-installer with NovaPhy automatically and
install it on the connected HDC device. If the HDC device is not detected,
open permissions for the USB bus: