From 9d7d499a793022ff2dc2a9f136cad474b233427e Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Thu, 25 Apr 2024 19:15:23 +0200 Subject: [PATCH] Detect OpenHarmony Rust target The OpenHarmony SDK contains a CMake toolchain file, which among others sets CMAKE_OHOS_ARCH_ABI. We can use this to automatically infer the correct Rust target. The SDK can be obtained from the release notes on gitee: https://gitee.com/openharmony/docs/tree/master/en/release-notes --- cmake/FindRust.cmake | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmake/FindRust.cmake b/cmake/FindRust.cmake index 97c65dbc..c6479c15 100644 --- a/cmake/FindRust.cmake +++ b/cmake/FindRust.cmake @@ -713,6 +713,19 @@ if (NOT Rust_CARGO_TARGET_CACHED) if (_Rust_ANDROID_TARGET) set(Rust_CARGO_TARGET_CACHED "${_Rust_ANDROID_TARGET}" CACHE STRING "Target triple") endif() + elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "OHOS") + if(CMAKE_OHOS_ARCH_ABI STREQUAL arm64-v8a) + set(_RUST_OHOS_TARGET aarch64-unknown-linux-ohos) + elseif(CMAKE_OHOS_ARCH_ABI STREQUAL armeabi-v7a) + set(_RUST_OHOS_TARGET armv7-unknown-linux-ohos) + elseif(CMAKE_OHOS_ARCH_ABI STREQUAL x86_64) + set(_RUST_OHOS_TARGET x86_64-unknown-linux-ohos) + else() + message(WARNING "unrecognized OHOS architecture: ${OHOS_ARCH}") + endif() + if(_RUST_OHOS_TARGET) + set(Rust_CARGO_TARGET_CACHED "${_RUST_OHOS_TARGET}" CACHE STRING "Target triple") + endif() endif() # Fallback to the default host target if(NOT Rust_CARGO_TARGET_CACHED)