From 0d895f00a21364a52f19d993bbe6095c7f276ad4 Mon Sep 17 00:00:00 2001 From: Wang Fenjin Date: Sun, 15 Feb 2026 17:36:28 +0800 Subject: [PATCH 1/5] Add OHOS build and release workflow with build script improvements --- .github/workflows/main.yml | 72 ++++++++++++++++++++++++++++++++++++++ build-ohos.sh | 38 +++++++++++++------- 2 files changed, 98 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9b53754..0e61bd1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -438,3 +438,75 @@ jobs: files: "${{ github.workspace }}/libsimple-android-${{ matrix.abi }}.zip" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + OHOS: + runs-on: ubuntu-latest + needs: Linux + env: + OHOS_SDK_URL: ${{ secrets.OHOS_SDK_URL }} + OHOS_SDK_VERSION: v6.0.0.1 + steps: + - uses: actions/checkout@v6 + with: + submodules: true + + - name: Download and extract OHOS SDK + shell: bash + run: | + set -euxo pipefail + sdk_root="${RUNNER_TEMP}/ohos-sdk" + sdk_archive="${RUNNER_TEMP}/ohos-sdk.tar.gz" + mkdir -p "${sdk_root}" + + if [ -n "${OHOS_SDK_URL:-}" ]; then + curl -L --retry 3 --retry-all-errors --max-time 3600 "${OHOS_SDK_URL}" -o "${sdk_archive}" + else + sdk_base_url="https://github.com/openharmony-rs/ohos-sdk/releases/download/${OHOS_SDK_VERSION}" + curl -L --retry 3 --retry-all-errors --max-time 3600 "${sdk_base_url}/ohos-sdk-windows_linux-public.tar.gz.aa" -o "${sdk_archive}.aa" + curl -L --retry 3 --retry-all-errors --max-time 3600 "${sdk_base_url}/ohos-sdk-windows_linux-public.tar.gz.ab" -o "${sdk_archive}.ab" + cat "${sdk_archive}.aa" "${sdk_archive}.ab" > "${sdk_archive}" + fi + + tar -xzf "${sdk_archive}" -C "${sdk_root}" + + linux_dir="$(find "${sdk_root}" -type d -name Linux | head -n 1)" + if [ -z "${linux_dir}" ]; then + echo "Failed to locate Linux directory in OHOS SDK archive." >&2 + exit 1 + fi + + cd "${linux_dir}" + shopt -s nullglob + zips=( *.zip ) + if [ "${#zips[@]}" -eq 0 ]; then + echo "No SDK zip files found under ${linux_dir}." >&2 + exit 1 + fi + for f in "${zips[@]}"; do unzip -q -o "${f}"; done + + echo "OHOS_SDK=${linux_dir}" >> "${GITHUB_ENV}" + + - name: Build OHOS + run: ./build-ohos.sh + + - name: Verify OHOS outputs + run: | + test -f "output/bin/libsimple.so" + test -f "output/bin/dict/jieba.dict.utf8" + + - name: Package OHOS + if: startsWith(github.ref, 'refs/tags/') + run: | + mkdir libsimple-ohos-arm64-v8a + cp -r output/bin/libsimple.so output/bin/dict libsimple-ohos-arm64-v8a/ + zip -r libsimple-ohos-arm64-v8a.zip libsimple-ohos-arm64-v8a + working-directory: "${{ github.workspace }}" + + - name: Release OHOS + if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v2 + with: + draft: true + files: "${{ github.workspace }}/libsimple-ohos-arm64-v8a.zip" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/build-ohos.sh b/build-ohos.sh index f5fc2a0..77f96aa 100644 --- a/build-ohos.sh +++ b/build-ohos.sh @@ -1,21 +1,35 @@ #!/bin/sh -current_dir=$(pwd)/$(dirname "$0") +set -eu + +current_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) build_dir="${current_dir}/build-ohos" -lib_prefix="${current_dir}/output" +lib_prefix="${current_dir}/output" +: "${OHOS_SDK:?OHOS_SDK is required}" CMAKE="${OHOS_SDK}/native/build-tools/cmake/bin/cmake" TOOLCHAIN_FILE="${OHOS_SDK}/native/build/cmake/ohos.toolchain.cmake" -OHOS_ARCH="arm64-v8a" +OHOS_ARCH="${OHOS_ARCH:-arm64-v8a}" + +if [ ! -x "${CMAKE}" ]; then + echo "CMake not found at ${CMAKE}" >&2 + exit 1 +fi + +if [ ! -f "${TOOLCHAIN_FILE}" ]; then + echo "OHOS toolchain file not found at ${TOOLCHAIN_FILE}" >&2 + exit 1 +fi -mkdir -p "$build_dir" && cd "$build_dir" || exit +mkdir -p "${build_dir}" -"$CMAKE" \ - -DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN_FILE" \ - -DCMAKE_INSTALL_PREFIX="$lib_prefix" \ - -DOHOS_ARCH="$OHOS_ARCH" \ +"${CMAKE}" \ + -S "${current_dir}" \ + -B "${build_dir}" \ + -DCMAKE_TOOLCHAIN_FILE="${TOOLCHAIN_FILE}" \ + -DCMAKE_INSTALL_PREFIX="${lib_prefix}" \ + -DOHOS_ARCH="${OHOS_ARCH}" \ -DCMAKE_CXX_FLAGS="-Wno-unused-command-line-argument" \ - -DCMAKE_C_FLAGS="-Wno-unused-command-line-argument" \ - "$current_dir" + -DCMAKE_C_FLAGS="-Wno-unused-command-line-argument" -make -make install +"${CMAKE}" --build "${build_dir}" --parallel +"${CMAKE}" --install "${build_dir}" From 754f8ce5719eae47bfa3705786e453bfb7bcb11a Mon Sep 17 00:00:00 2001 From: Wang Fenjin Date: Sun, 15 Feb 2026 17:41:51 +0800 Subject: [PATCH 2/5] Add separate macOS x64 and arm64 build/test workflows --- .github/workflows/main.yml | 67 +++++++++++++++++++++++++++++--------- CMakePresets.json | 54 ++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 15 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0e61bd1..76f11f6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -277,11 +277,48 @@ jobs: echo "- OS: ${{ runner.os }}" >> $GITHUB_STEP_SUMMARY MacOS: - runs-on: macos-latest + runs-on: ${{ matrix.os }} needs: Linux + strategy: + fail-fast: true + matrix: + include: + - os: macos-13 + arch: x64 + - os: macos-14 + arch: arm64 env: BUILD_TYPE: ${{ startsWith(github.ref, 'refs/tags/') && 'Release' || 'Debug' }} steps: + - name: "Set macOS Build Presets" + id: mac_build + shell: bash + run: | + case "${{ matrix.arch }}" in + x64) + configure_preset="macos-ninja-x64" + build_dir="${GITHUB_WORKSPACE}/../../_temp/macos-x64" + ;; + arm64) + configure_preset="macos-ninja-arm64" + build_dir="${GITHUB_WORKSPACE}/../../_temp/macos-arm64" + ;; + *) + echo "Unsupported matrix.arch: ${{ matrix.arch }}" >&2 + exit 1 + ;; + esac + + if [[ "${{ github.ref }}" == refs/tags/* ]]; then + build_preset="${configure_preset}-release" + else + build_preset="${configure_preset}" + fi + + echo "CONFIGURE_PRESET=${configure_preset}" >> "$GITHUB_OUTPUT" + echo "BUILD_PRESET=${build_preset}" >> "$GITHUB_OUTPUT" + echo "BUILD_DIR=${build_dir}" >> "$GITHUB_OUTPUT" + - uses: actions/checkout@v6 with: submodules: true @@ -305,18 +342,18 @@ jobs: - name: 'Run CMake' uses: lukka/run-cmake@v10 with: - configurePreset: 'macos-ninja' - buildPreset: ${{ startsWith(github.ref, 'refs/tags/') && 'macos-ninja-release' || 'macos-ninja' }} + configurePreset: ${{ steps.mac_build.outputs.CONFIGURE_PRESET }} + buildPreset: ${{ steps.mac_build.outputs.BUILD_PRESET }} - name: 'Run CTest' run: ctest -C ${{ env.BUILD_TYPE }} - working-directory: "${{ github.workspace }}/../../_temp/macos" + working-directory: "${{ steps.mac_build.outputs.BUILD_DIR }}" - name: "Check file existence" uses: andstor/file-existence-action@v3 with: allow_failure: true - files: "${{ github.workspace }}/../../_temp/macos/src/libsimple.dylib, ${{ github.workspace }}/../../_temp/macos/test/dict/jieba.dict.utf8" + files: "${{ steps.mac_build.outputs.BUILD_DIR }}/src/libsimple.dylib, ${{ steps.mac_build.outputs.BUILD_DIR }}/test/dict/jieba.dict.utf8" - uses: actions/setup-node@v6 with: @@ -331,9 +368,9 @@ jobs: run: | brew install python-setuptools npm install - npm run p -- --ext_path="${{ github.workspace }}/../../_temp/macos/src/" --dict_path="${{ github.workspace }}/../../_temp/macos/test/dict/" + npm run p -- --ext_path="${{ steps.mac_build.outputs.BUILD_DIR }}/src/" --dict_path="${{ steps.mac_build.outputs.BUILD_DIR }}/test/dict/" # don't run this as it's toooo slow - # npm run b -- --ext_path="${{ github.workspace }}/../../_temp/macos/src/" --dict_path="${{ github.workspace }}/../../_temp/macos/test/dict/" + # npm run b -- --ext_path="${{ steps.mac_build.outputs.BUILD_DIR }}/src/" --dict_path="${{ steps.mac_build.outputs.BUILD_DIR }}/test/dict/" # python run # - name: run python example @@ -344,27 +381,27 @@ jobs: - name: Package if: startsWith(github.ref, 'refs/tags/') run: | - mkdir libsimple-osx-x64 + mkdir libsimple-osx-${{ matrix.arch }} sudo xattr -r -d com.apple.quarantine src/libsimple.dylib - cp -r src/libsimple.dylib test/dict libsimple-osx-x64/ - zip -r libsimple-osx-x64.zip libsimple-osx-x64 - working-directory: "${{ github.workspace }}/../../_temp/macos" + cp -r src/libsimple.dylib test/dict libsimple-osx-${{ matrix.arch }}/ + zip -r libsimple-osx-${{ matrix.arch }}.zip libsimple-osx-${{ matrix.arch }} + working-directory: "${{ steps.mac_build.outputs.BUILD_DIR }}" - name: Release if: startsWith(github.ref, 'refs/tags/') uses: softprops/action-gh-release@v2 with: draft: true - files: "${{ github.workspace }}/../../_temp/macos/libsimple-osx-x64.zip" + files: "${{ steps.mac_build.outputs.BUILD_DIR }}/libsimple-osx-${{ matrix.arch }}.zip" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: build-iOS - if: success() + if: ${{ success() && matrix.arch == 'arm64' }} run: ./build-ios.sh - name: Package iOS - if: startsWith(github.ref, 'refs/tags/') + if: ${{ startsWith(github.ref, 'refs/tags/') && matrix.arch == 'arm64' }} run: | mkdir libsimple-ios-xcframework cp -r output/libsimple.xcframework output/dict libsimple-ios-xcframework/ @@ -372,7 +409,7 @@ jobs: working-directory: "${{ github.workspace }}" - name: Release iOS - if: startsWith(github.ref, 'refs/tags/') + if: ${{ startsWith(github.ref, 'refs/tags/') && matrix.arch == 'arm64' }} uses: softprops/action-gh-release@v2 with: draft: true diff --git a/CMakePresets.json b/CMakePresets.json index a6195ff..785d612 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -72,6 +72,34 @@ } } }, + { + "name": "macos-ninja-x64", + "displayName": "macOS Ninja (x64)", + "description": "Configure for macOS x64 build", + "inherits": "macos-ninja", + "binaryDir": "${sourceDir}/../../_temp/macos-x64", + "cacheVariables": { + "CMAKE_OSX_ARCHITECTURES": "x86_64", + "CMAKE_INSTALL_PREFIX": { + "type": "PATH", + "value": "${sourceDir}/../../_temp/macos-x64/install" + } + } + }, + { + "name": "macos-ninja-arm64", + "displayName": "macOS Ninja (arm64)", + "description": "Configure for macOS arm64 build", + "inherits": "macos-ninja", + "binaryDir": "${sourceDir}/../../_temp/macos-arm64", + "cacheVariables": { + "CMAKE_OSX_ARCHITECTURES": "arm64", + "CMAKE_INSTALL_PREFIX": { + "type": "PATH", + "value": "${sourceDir}/../../_temp/macos-arm64/install" + } + } + }, { "name": "windows-msvc-vs17-base", "hidden": true, @@ -166,6 +194,32 @@ "description": "Build for macOS (Release)", "configuration": "Release" }, + { + "name": "macos-ninja-x64", + "configurePreset": "macos-ninja-x64", + "displayName": "Build macOS x64", + "description": "Build for macOS x64" + }, + { + "name": "macos-ninja-x64-release", + "configurePreset": "macos-ninja-x64", + "displayName": "Build macOS x64 (Release)", + "description": "Build for macOS x64 (Release)", + "configuration": "Release" + }, + { + "name": "macos-ninja-arm64", + "configurePreset": "macos-ninja-arm64", + "displayName": "Build macOS arm64", + "description": "Build for macOS arm64" + }, + { + "name": "macos-ninja-arm64-release", + "configurePreset": "macos-ninja-arm64", + "displayName": "Build macOS arm64 (Release)", + "description": "Build for macOS arm64 (Release)", + "configuration": "Release" + }, { "name": "windows-msvc-vs17", "configurePreset": "windows-msvc-vs17", From 0c0bfdeba8b66acd98ec0969ba09cc798cb191e2 Mon Sep 17 00:00:00 2001 From: Wang Fenjin Date: Sun, 15 Feb 2026 17:45:33 +0800 Subject: [PATCH 3/5] Update macOS CI matrix to use macos-15 runners --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 76f11f6..b6c858d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -283,9 +283,9 @@ jobs: fail-fast: true matrix: include: - - os: macos-13 + - os: macos-15-intel arch: x64 - - os: macos-14 + - os: macos-15 arch: arm64 env: BUILD_TYPE: ${{ startsWith(github.ref, 'refs/tags/') && 'Release' || 'Debug' }} From bee5cc1c930d388c3a21c7381696407c831e0655 Mon Sep 17 00:00:00 2001 From: Wang Fenjin Date: Sun, 15 Feb 2026 17:52:28 +0800 Subject: [PATCH 4/5] Improve OHOS SDK extraction and toolchain detection --- .github/workflows/main.yml | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b6c858d..1613bf5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -506,22 +506,26 @@ jobs: tar -xzf "${sdk_archive}" -C "${sdk_root}" - linux_dir="$(find "${sdk_root}" -type d -name Linux | head -n 1)" - if [ -z "${linux_dir}" ]; then - echo "Failed to locate Linux directory in OHOS SDK archive." >&2 - exit 1 + toolchain_file="$(find "${sdk_root}" -type f -path '*/native/build/cmake/ohos.toolchain.cmake' | head -n 1 || true)" + if [ -z "${toolchain_file}" ]; then + mapfile -t zips < <(find "${sdk_root}" -type f -name '*.zip') + if [ "${#zips[@]}" -eq 0 ]; then + echo "No SDK zip files found under ${sdk_root}." >&2 + find "${sdk_root}" -maxdepth 4 -print + exit 1 + fi + for f in "${zips[@]}"; do unzip -q -o "${f}" -d "$(dirname "${f}")"; done + toolchain_file="$(find "${sdk_root}" -type f -path '*/native/build/cmake/ohos.toolchain.cmake' | head -n 1 || true)" fi - cd "${linux_dir}" - shopt -s nullglob - zips=( *.zip ) - if [ "${#zips[@]}" -eq 0 ]; then - echo "No SDK zip files found under ${linux_dir}." >&2 + if [ -z "${toolchain_file}" ]; then + echo "Failed to locate OHOS toolchain after extraction." >&2 + find "${sdk_root}" -maxdepth 5 -print exit 1 fi - for f in "${zips[@]}"; do unzip -q -o "${f}"; done - echo "OHOS_SDK=${linux_dir}" >> "${GITHUB_ENV}" + ohos_sdk="${toolchain_file%/native/build/cmake/ohos.toolchain.cmake}" + echo "OHOS_SDK=${ohos_sdk}" >> "${GITHUB_ENV}" - name: Build OHOS run: ./build-ohos.sh From f59bbfdc00a7035c1eb65762d018784c1ce4c80b Mon Sep 17 00:00:00 2001 From: Wang Fenjin Date: Sun, 15 Feb 2026 18:00:08 +0800 Subject: [PATCH 5/5] Optimize SDK unzip to extract only needed Linux packages --- .github/workflows/main.yml | 14 +++++++++++++- build-ohos.sh | 0 2 files changed, 13 insertions(+), 1 deletion(-) mode change 100644 => 100755 build-ohos.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1613bf5..f97c03b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -514,8 +514,20 @@ jobs: find "${sdk_root}" -maxdepth 4 -print exit 1 fi - for f in "${zips[@]}"; do unzip -q -o "${f}" -d "$(dirname "${f}")"; done + + # Fast path: native build only needs Linux native/toolchains SDK packages. + mapfile -t preferred_zips < <(printf '%s\n' "${zips[@]}" | grep -E '/linux/(native|toolchains)-linux-x64-.*\.zip$' || true) + if [ "${#preferred_zips[@]}" -gt 0 ]; then + for f in "${preferred_zips[@]}"; do unzip -q -o "${f}" -d "$(dirname "${f}")"; done + else + for f in "${zips[@]}"; do unzip -q -o "${f}" -d "$(dirname "${f}")"; done + fi + toolchain_file="$(find "${sdk_root}" -type f -path '*/native/build/cmake/ohos.toolchain.cmake' | head -n 1 || true)" + if [ -z "${toolchain_file}" ]; then + for f in "${zips[@]}"; do unzip -q -o "${f}" -d "$(dirname "${f}")"; done + toolchain_file="$(find "${sdk_root}" -type f -path '*/native/build/cmake/ohos.toolchain.cmake' | head -n 1 || true)" + fi fi if [ -z "${toolchain_file}" ]; then diff --git a/build-ohos.sh b/build-ohos.sh old mode 100644 new mode 100755