Skip to content

Commit 4dcd31d

Browse files
committed
Improve OpenHarmony toolchain detection in CI build
Enhanced the build workflow to dynamically locate the OpenHarmony toolchain file based on available API level directories in the SDK. Updated CMake configuration to use the detected toolchain path, improving compatibility with different SDK structures and simplifying the setup process.
1 parent 2b0177c commit 4dcd31d

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

.github/workflows/build.yml

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -182,37 +182,36 @@ jobs:
182182
- name: Setup build environment
183183
run: |
184184
SDK_DIR=$(pwd)/sdk
185+
186+
# Find the API level directory (usually "20" or similar)
187+
API_LEVEL=$(ls -1 $SDK_DIR | grep -E '^[0-9]+$' | head -1)
188+
if [ -z "$API_LEVEL" ]; then
189+
# Fallback to direct native/ structure
190+
OHOS_NATIVE_TOOLCHAIN="$SDK_DIR/native/build/cmake/ohos.toolchain.cmake"
191+
else
192+
OHOS_NATIVE_TOOLCHAIN="$SDK_DIR/$API_LEVEL/native/build/cmake/ohos.toolchain.cmake"
193+
fi
194+
185195
echo "OHOS_NDK_HOME=$SDK_DIR" >> $GITHUB_ENV
186196
echo "OHOS_SDK_PATH=$SDK_DIR" >> $GITHUB_ENV
187-
ls -la $SDK_DIR/native/ || true
188-
ls -la $SDK_DIR/native/build/ || true
189-
ls -la $SDK_DIR/native/build/cmake/ || true
197+
echo "OHOS_NATIVE_TOOLCHAIN=$OHOS_NATIVE_TOOLCHAIN" >> $GITHUB_ENV
198+
199+
# Debug: Show SDK structure
200+
echo "SDK structure:"
201+
ls -la $SDK_DIR/ || true
202+
echo "Looking for toolchain at: $OHOS_NATIVE_TOOLCHAIN"
203+
ls -la $OHOS_NATIVE_TOOLCHAIN || true
190204
191205
- name: Configure CMake for OpenHarmony
192206
shell: bash
193207
run: |
194208
mkdir build-ohos
195209
cd build-ohos
196210
197-
# Find ninja executable
198-
NINJA=$(which ninja)
199-
echo "Found ninja at: $NINJA"
200-
201-
# Debug: Check SDK structure
202-
echo "SDK structure:"
203-
ls -la $OHOS_SDK_PATH/native/ || true
204-
echo "Toolchain file:"
205-
cat $OHOS_SDK_PATH/native/build/cmake/ohos.toolchain.cmake | head -150 || true
206-
207-
# Configure CMake with OpenHarmony toolchain (ARM64 only)
208-
cmake .. \
209-
-DCMAKE_SYSTEM_NAME=OHOS \
210-
-DCMAKE_TOOLCHAIN_FILE=$OHOS_SDK_PATH/native/build/cmake/ohos.toolchain.cmake \
211-
-DOHOS_ARCH=aarch64 \
212-
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
213-
-DCMAKE_BUILD_TYPE=Release \
214-
-DCMAKE_MAKE_PROGRAM=$NINJA \
215-
-G Ninja
211+
# Configure CMake with OpenHarmony toolchain
212+
cmake -DCMAKE_SYSTEM_NAME=OHOS \
213+
-DCMAKE_TOOLCHAIN_FILE="$OHOS_NATIVE_TOOLCHAIN" \
214+
..
216215
217216
- name: Build Examples
218217
shell: bash

0 commit comments

Comments
 (0)