1# Copyright (c) 2021-2022 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14# To build parts of the platform written in Panda Assembly, 15# we need to have the assembler binary. If we are not 16# cross-compiling, we are good to go. Otherwise a subset 17# of source tree is exposed as a separate project for 18# "host tools", which is built solely for host. 19 20function(panda_configure_host_tools) 21 if(NOT CMAKE_CROSSCOMPILING) 22 return() 23 endif() 24 25 include(ExternalProject) 26 27 set(host_tools_build_dir "${CMAKE_CURRENT_BINARY_DIR}/host-tools-build") 28 29 30 if ($ENV{NPROC_PER_JOB}) 31 set(PANDA_HOST_TOOLS_JOBS_NUMBER $ENV{NPROC_PER_JOB}) 32 else() 33 set(PANDA_HOST_TOOLS_JOBS_NUMBER 16) 34 endif() 35 if (PANDA_TARGET_AMD64) 36 set(ARCH_NAME X86_64) 37 set(IRTOC_TARGET x86_64) 38 elseif(PANDA_TARGET_ARM64) 39 set(ARCH_NAME AARCH64) 40 set(IRTOC_TARGET arm64) 41 elseif(PANDA_TARGET_ARM32) 42 set(ARCH_NAME AARCH32) 43 set(IRTOC_TARGET arm32) 44 else() 45 message(FATAL_ERROR "Unsupported target") 46 endif() 47 48 add_custom_target(host_tools_depends) 49 50 if (PANDA_TARGET_ARM64) 51 set(TARGET_ARCH "AARCH64") 52 elseif (PANDA_TARGET_ARM32) 53 set(TARGET_ARCH "AARCH32") 54 else() 55 set(TARGET_ARCH "UNKNOWN") 56 endif() 57 58 set(HOST_TOOLS_CMAKE_ARGS 59 -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} 60 -DPANDA_ROOT=${PANDA_ROOT} 61 -DPANDA_BINARY_ROOT=${PANDA_BINARY_ROOT} 62 -DPANDA_ROOT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR} 63 -DPANDA_THIRD_PARTY_SOURCES_DIR=${PANDA_THIRD_PARTY_SOURCES_DIR} 64 -DPANDA_THIRD_PARTY_CONFIG_DIR=${PANDA_THIRD_PARTY_CONFIG_DIR} 65 -DPANDA_PRODUCT_BUILD=true 66 -DPANDA_WITH_JAVA=${PANDA_WITH_JAVA} 67 -DPANDA_TARGET_MOBILE_WITH_MANAGED_LIBS=${PANDA_TARGET_MOBILE_WITH_MANAGED_LIBS} 68 -DPANDA_WITH_ECMASCRIPT=${PANDA_WITH_ECMASCRIPT} 69 -DPANDA_WITH_ACCORD=${PANDA_WITH_ACCORD} 70 -DPANDA_WITH_CANGJIE=${PANDA_WITH_CANGJIE} 71 -DIRTOC_TARGET=${IRTOC_TARGET} 72 -DPANDA_ENABLE_ADDRESS_SANITIZER=${PANDA_ENABLE_ADDRESS_SANITIZER} 73 -DPANDA_ENABLE_THREAD_SANITIZER=${PANDA_ENABLE_THREAD_SANITIZER} 74 -DPANDA_ENABLE_CLANG_TIDY=false 75 -DPANDA_WITH_BYTECODE_OPTIMIZER=false 76 -DPANDA_WITH_TESTS=false 77 -DHOST_TOOLS=true 78 -DPANDA_HOST_TOOLS_TARGET_TOOLCHAIN=${CMAKE_TOOLCHAIN_FILE} 79 -DPANDA_HOST_TOOLS_TARGET_ARCH=${TARGET_ARCH} 80 -DTOOLCHAIN_CLANG_ROOT=${TOOLCHAIN_CLANG_ROOT} 81 -DTOOLCHAIN_SYSROOT=${TOOLCHAIN_SYSROOT} 82 -DMOBILE_NATIVE_LIBS_SOURCE_PATH=${MOBILE_NATIVE_LIBS_SOURCE_PATH} 83 -DPANDA_TARGET_ARM32_ABI_HARD=${PANDA_TARGET_ARM32_ABI_HARD} 84 -DPANDA_RELEASE_BUILD=${PANDA_RELEASE_BUILD} 85 --no-warn-unused-cli 86 ) 87 88 set(HOST_TOOLS_TARGETS 89 cross_values 90 irtoc_fastpath 91 irtoc_interpreter 92 irtoc_tests 93 ark_asm 94 c_secshared 95 zlib 96 ) 97 98 add_custom_target(irtoc_fastpath) 99 add_custom_target(irtoc_interpreter) 100 add_custom_target(irtoc_tests) 101 102 if(PANDA_WITH_JAVA) 103 list(APPEND HOST_TOOLS_TARGETS c2p irtoc_java_fastpath) 104 if(DEFINED PANDA_JAVA_LIBCORE_VERSION) 105 list(APPEND HOST_TOOLS_CMAKE_ARGS -DPANDA_JAVA_LIBCORE_VERSION=${PANDA_JAVA_LIBCORE_VERSION}) 106 endif() 107 endif() 108 109 if (PANDA_WITH_ECMASCRIPT) 110 list(APPEND HOST_TOOLS_TARGETS es2panda) 111 endif() 112 113 set(BUILD_COMMAND) 114 115 # After CMake 3.15 all targets can be specified in a single `--target` option. But we use CMake 3.10 at the moment. 116 foreach(target ${HOST_TOOLS_TARGETS}) 117 string(APPEND BUILD_COMMAND "${CMAKE_COMMAND} --build ${host_tools_build_dir} --target ${target} -- -j${PANDA_HOST_TOOLS_JOBS_NUMBER} && ") 118 endforeach() 119 string(APPEND BUILD_COMMAND " true") 120 separate_arguments(BUILD_COMMAND UNIX_COMMAND ${BUILD_COMMAND}) 121 122 # Ensuring that cross-values from host-tools and from the main project are the same: 123 set(TARGET_CROSS_VALUES ${PANDA_BINARY_ROOT}/cross_values/generated_values/${ARCH_NAME}_values_gen.h) 124 set(HOST_CROSS_VALUES ${host_tools_build_dir}/cross_values/generated_values/${ARCH_NAME}_values_gen.h) 125 set(CHECK_COMMAND "${PANDA_ROOT}/cross_values/diff_check_values.sh ${TARGET_CROSS_VALUES} ${HOST_CROSS_VALUES}") 126 separate_arguments(CHECK_COMMAND UNIX_COMMAND ${CHECK_COMMAND}) 127 128 ExternalProject_Add(panda_host_tools 129 DEPENDS host_tools_depends 130 SOURCE_DIR "${PANDA_ROOT}" 131 BINARY_DIR "${host_tools_build_dir}" 132 BUILD_IN_SOURCE FALSE 133 CONFIGURE_COMMAND ${CMAKE_COMMAND} <SOURCE_DIR> -G "${CMAKE_GENERATOR}" 134 ${HOST_TOOLS_CMAKE_ARGS} 135 BUILD_COMMAND ${BUILD_COMMAND} 136 INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping install step" 137 TEST_COMMAND ${CHECK_COMMAND} 138 ) 139 140 add_custom_target(build_host_tools 141 COMMAND ${BUILD_COMMAND} 142 COMMAND ${CHECK_COMMAND} 143 WORKING_DIRECTORY ${host_tools_build_dir} 144 DEPENDS panda_host_tools 145 ) 146endfunction() 147 148panda_configure_host_tools() 149