From e22f7cb484fc50cdb2750c2941862fafee51e6f0 Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Tue, 14 Mar 2023 16:54:34 +0300 Subject: [PATCH] Support build with ohos-sdk toolchain Also this commit removes old ohos toolchain file: - cmake/toolchain/cross-ohos-aarch64.cmake Signed-off-by: Vyacheslav Cherkashin --- cmake/Definitions.cmake | 17 +++++-- cmake/toolchain/cross-ohos-aarch64.cmake | 48 ------------------- plugins/ets/runtime/CMakeLists.txt | 9 ++++ plugins/ets/runtime/ets_vm_api.cpp | 5 -- .../ets/runtime/interop_js/ts2ets_common.h | 2 +- .../ets/runtime/interop_js/ts2ets_copy.cpp | 2 +- .../gtest_plugin/ets_interop_js_gtest.cpp | 11 +++++ 7 files changed, 34 insertions(+), 60 deletions(-) delete mode 100644 cmake/toolchain/cross-ohos-aarch64.cmake diff --git a/cmake/Definitions.cmake b/cmake/Definitions.cmake index 4a6709511..5f44aa81e 100644 --- a/cmake/Definitions.cmake +++ b/cmake/Definitions.cmake @@ -26,24 +26,24 @@ function(panda_promote_to_definitions) endforeach() endfunction() -if(CMAKE_SYSTEM_NAME STREQUAL Linux) +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") panda_set_flag(PANDA_TARGET_LINUX) panda_set_flag(PANDA_TARGET_UNIX) if (NOT PANDA_ENABLE_ADDRESS_SANITIZER) panda_set_flag(PANDA_USE_FUTEX) endif() -elseif(CMAKE_SYSTEM_NAME STREQUAL OHOS) +elseif(CMAKE_SYSTEM_NAME STREQUAL "OHOS") panda_set_flag(PANDA_TARGET_OHOS) panda_set_flag(PANDA_TARGET_UNIX) -elseif(CMAKE_SYSTEM_NAME STREQUAL Android) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") panda_set_flag(PANDA_TARGET_MOBILE) panda_set_flag(PANDA_TARGET_UNIX) if (NOT PANDA_ENABLE_ADDRESS_SANITIZER) panda_set_flag(PANDA_USE_FUTEX) endif() -elseif(CMAKE_SYSTEM_NAME STREQUAL Windows) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") panda_set_flag(PANDA_TARGET_WINDOWS) -elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") panda_set_flag(PANDA_TARGET_MACOS) panda_set_flag(PANDA_TARGET_UNIX) else() @@ -231,6 +231,13 @@ endif() if(PANDA_TARGET_OHOS) set(PANDA_WITH_BENCHMARKS false) add_definitions(-D__MUSL__) + + if(PANDA_TARGET_ARM64) + # WORKAROUND: + # Disable '-Wunused-command-line-argument' error to avoid compilation error: + # clang++: error: argument unused during compilation: '--gcc-toolchain=/llvm' [-Werror,-Wunused-command-line-argument] + add_compile_options(-Wno-unused-command-line-argument) + endif() endif() if(CMAKE_BUILD_TYPE STREQUAL Debug) diff --git a/cmake/toolchain/cross-ohos-aarch64.cmake b/cmake/toolchain/cross-ohos-aarch64.cmake deleted file mode 100644 index 8baf7c1bd..000000000 --- a/cmake/toolchain/cross-ohos-aarch64.cmake +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set(TOOLCHAIN_CLANG_ROOT "" CACHE STRING "Path to clang- directory") -set(TOOLCHAIN_SYSROOT "" CACHE STRING "Path to sysroot") - -set(PANDA_TRIPLET aarch64-linux-ohos) -set(PANDA_SYSROOT ${TOOLCHAIN_SYSROOT}) - -set(CMAKE_SYSTEM_NAME OHOS) -set(CMAKE_SYSTEM_PROCESSOR aarch64) -set(CMAKE_PREFIX_PATH ${TOOLCHAIN_SYSROOT}) -set(CMAKE_C_COMPILER_TARGET ${PANDA_TRIPLET}) -set(CMAKE_CXX_COMPILER_TARGET ${PANDA_TRIPLET}) -set(CMAKE_ASM_COMPILER_TARGET ${PANDA_TRIPLET}) - -link_libraries(unwind) - -if(NOT PANDA_TOOLCHAIN_INITIALIZED) - # Toolchain file can be sourced multiple times with different sets of variables. - # Prevent failures if TOOLCHAIN_CLANG_ROOT is not set this time but still fail - # if TOOLCHAIN_CLANG_ROOT is not specified at all. - if(NOT TOOLCHAIN_CLANG_ROOT) - set(CMAKE_AR "/bin/false" CACHE FILEPATH "") - set(CMAKE_RANLIB "/bin/false" CACHE FILEPATH "") - set(CMAKE_C_COMPILER "/bin/false" CACHE FILEPATH "") - set(CMAKE_CXX_COMPILER "/bin/false" CACHE FILEPATH "") - else() - set(CMAKE_AR "${TOOLCHAIN_CLANG_ROOT}/bin/llvm-ar" CACHE FILEPATH "" FORCE) - set(CMAKE_RANLIB "${TOOLCHAIN_CLANG_ROOT}/bin/llvm-ranlib" CACHE FILEPATH "" FORCE) - set(CMAKE_C_COMPILER "${TOOLCHAIN_CLANG_ROOT}/bin/clang" CACHE FILEPATH "" FORCE) - set(CMAKE_CXX_COMPILER "${TOOLCHAIN_CLANG_ROOT}/bin/clang++" CACHE FILEPATH "" FORCE) - endif() - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --rtlib=compiler-rt -fuse-ld=lld" CACHE STRING "" FORCE) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --rtlib=compiler-rt -fuse-ld=lld" CACHE STRING "" FORCE) - # Do not add linker flags multiple times when variables persist across toolchain file invocation. - set(PANDA_TOOLCHAIN_INITIALIZED ON CACHE STRING "" FORCE) -endif() diff --git a/plugins/ets/runtime/CMakeLists.txt b/plugins/ets/runtime/CMakeLists.txt index 88bebce46..a9c048a52 100644 --- a/plugins/ets/runtime/CMakeLists.txt +++ b/plugins/ets/runtime/CMakeLists.txt @@ -72,6 +72,15 @@ target_include_directories(arkruntime_static PUBLIC target_compile_definitions(arkruntime_static PRIVATE ${CURRENT_DEFS}) add_dependencies(arkruntime_static cross_values) +if(PANDA_TARGET_OHOS) + if(POLICY CMP0079) + # Set CMP0079=NEW policy to allow add link library "hilog_ndk.z" + # to target "arkruntime_static" which is not built in this directory. + cmake_policy(SET CMP0079 NEW) + endif() + target_link_libraries(arkruntime_static hilog_ndk.z) +endif() + if (PANDA_ETS_INTEROP_JS) add_subdirectory(interop_js) endif() diff --git a/plugins/ets/runtime/ets_vm_api.cpp b/plugins/ets/runtime/ets_vm_api.cpp index aa28eda61..e956c0008 100644 --- a/plugins/ets/runtime/ets_vm_api.cpp +++ b/plugins/ets/runtime/ets_vm_api.cpp @@ -17,11 +17,6 @@ #include "ets_vm.h" #include "generated/base_options.h" -// WORKAROUND: -// We delete PANDA_TARGET_OHOS macros because CI doesn't have header. -// We should remove this workaround when CI will be fixed. -#undef PANDA_TARGET_OHOS - #ifdef PANDA_TARGET_OHOS #include diff --git a/plugins/ets/runtime/interop_js/ts2ets_common.h b/plugins/ets/runtime/interop_js/ts2ets_common.h index a08aab4b3..f47054b8f 100644 --- a/plugins/ets/runtime/interop_js/ts2ets_common.h +++ b/plugins/ets/runtime/interop_js/ts2ets_common.h @@ -24,7 +24,7 @@ #ifdef PANDA_TARGET_OHOS #include -#define OH_TS2ETS_LOG_INFO(msg) OH_LOG_Print(LOG_APP, LOG_INFO, 0xFF00, "ts2ets", msg) +#define OH_TS2ETS_LOG_INFO(msg) OH_LOG_Print(LOG_APP, LOG_INFO, 0xFF00, "ts2ets", "%s", msg) #define OH_TS2ETS_LOG_INFO_A(msg, ...) OH_LOG_Print(LOG_APP, LOG_INFO, 0xFF00, "ts2ets", msg, __VA_ARGS__) #define OH_TS2ETS_LOG_ERROR(msg) OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, "ts2ets", msg) #define OH_TS2ETS_LOG_ERROR_A(msg, ...) OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, "ts2ets", msg, __VA_ARGS__) diff --git a/plugins/ets/runtime/interop_js/ts2ets_copy.cpp b/plugins/ets/runtime/interop_js/ts2ets_copy.cpp index 128ee913a..5d80a1769 100644 --- a/plugins/ets/runtime/interop_js/ts2ets_copy.cpp +++ b/plugins/ets/runtime/interop_js/ts2ets_copy.cpp @@ -687,7 +687,7 @@ napi_value InvokeEtsMethodImpl(napi_env env, napi_value *jsargv, uint32_t jsargc js_res = ets2js.GetResult(); auto end = std::chrono::steady_clock::now(); long long int t = std::chrono::duration_cast(end - begin).count(); - OH_TS2ETS_LOG_INFO_A("InvokeEtsMethod: ets2js elapsed time %ldd us", t); + OH_TS2ETS_LOG_INFO_A("InvokeEtsMethod: ets2js elapsed time %lld us", t); js_handle_scope.Escape(js_res); } diff --git a/plugins/ets/tests/interop_js/gtest_plugin/ets_interop_js_gtest.cpp b/plugins/ets/tests/interop_js/gtest_plugin/ets_interop_js_gtest.cpp index a706b1146..4dea1264c 100644 --- a/plugins/ets/tests/interop_js/gtest_plugin/ets_interop_js_gtest.cpp +++ b/plugins/ets/tests/interop_js/gtest_plugin/ets_interop_js_gtest.cpp @@ -23,6 +23,17 @@ std::abort(); \ } while (0) +#ifdef PANDA_TARGET_OHOS +// NOTE: +// napi_fatal_exception() is not implemented it libace_napi.z.so, +// so let's implement it ourselves +extern "C" napi_status napi_fatal_exception([[maybe_unused]] napi_env env, [[maybe_unused]] napi_value err) +{ + ETS_PLUGIN_FATAL(__func__ << " is not implemented"); + return napi_ok; +} +#endif // PANDA_TARGET_OHOS + namespace panda::ets::interop::js::testing { napi_env EtsInteropTest::js_env_ = {}; -- Gitee