Skip to content

Commit

Permalink
Detect OpenHarmony Rust target
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jschwe committed Apr 25, 2024
1 parent d60944e commit 9d7d499
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cmake/FindRust.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9d7d499

Please sign in to comment.