From a788af52f7f68198ff9a3783853d6ffa9fd454d3 Mon Sep 17 00:00:00 2001 From: twfx1996 Date: Sat, 2 Apr 2022 14:24:57 +0800 Subject: [PATCH] support android ndk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 支持使用Android NDK工具链编译modelbox。编译所得到的so文件,可被安卓/鸿蒙平台上的APP调用。 --- CMake/FindMINDSPORE.cmake | 2 +- CMakeLists.txt | 71 ++++++--- src/CMakeLists.txt | 8 + .../cpu/flowunit/python/CMakeLists.txt | 1 - .../cpu/flowunit/python/python_flowunit.cc | 5 +- .../video_encoder/ffmpeg_video_muxer.cc | 9 ++ .../inference/virtualdriver_inference.cc | 9 +- .../virtual/python/virtualdriver_python.cc | 8 +- src/libmodelbox/base/device/device_manager.cc | 3 +- .../base/graph_manager/graph_manager.cc | 3 +- .../base/include/modelbox/base/any.h | 9 ++ .../base/include/modelbox/base/driver.h | 4 + .../base/include/modelbox/base/memory_stub.h | 55 +++++++ src/libmodelbox/base/utils/backtrace.cc | 139 ++++++++++++++++++ src/libmodelbox/base/utils/utils.cc | 7 + src/libmodelbox/engine/flowunit_manager.cc | 3 +- src/libmodelbox/include/modelbox/node.h | 2 +- src/modelbox/manager/src/log.c | 5 +- src/modelbox/manager/src/manager.c | 5 + .../server/include/modelbox/server/utils.h | 2 + src/python/CMakeLists.txt | 2 +- thirdparty/CMake/APIGW_CPP_CMakeList.in | 2 + thirdparty/CMake/cpp_httplib_cmakelist.in | 2 + thirdparty/CMakeLists.txt | 59 ++++++-- 24 files changed, 368 insertions(+), 47 deletions(-) create mode 100644 src/libmodelbox/base/include/modelbox/base/memory_stub.h create mode 100644 src/libmodelbox/base/utils/backtrace.cc diff --git a/CMake/FindMINDSPORE.cmake b/CMake/FindMINDSPORE.cmake index 675984f52..b229d27a1 100644 --- a/CMake/FindMINDSPORE.cmake +++ b/CMake/FindMINDSPORE.cmake @@ -4,7 +4,7 @@ mark_as_advanced(MINDSPORE_INCLUDE) # Look for the library (sorted from most current/relevant entry to least). find_library(MINDSPORE_LIBRARY NAMES - mindspore + NAMES mindspore mindspore-lite HINTS ${CMAKE_INSTALL_FULL_LIBDIR} ${HITS_MINDSPORE_PATH}/lib ) mark_as_advanced(MINDSPORE_LIBRARY) diff --git a/CMakeLists.txt b/CMakeLists.txt index c90aa73dc..dec056d09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,25 +64,58 @@ set(RELEASE_PACKAGE_DIR ${CMAKE_BINARY_DIR}/release) set(CUSTOM_LIBRARY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/libs) set(MODELBOX_TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -find_package(CPPREST) -find_package(OpenSSL REQUIRED) -find_package(Boost COMPONENTS system) -find_package(CUDA 10.0) -find_package(TENSORRT) -find_package(TENSORFLOW) -find_package(OBS) -find_package(DIS) -find_package(VCN) -find_package(NVCUVID) -find_package(FFMPEG) -find_package(ACL) -find_package(DSMI) -find_package(OpenCV) -find_package(DUKTAPE) -find_package(MINDSPORE) -find_package(FUSE) -find_package(JNI) -find_package(Java) +if (DEFINED ENV{USER_ROOT} AND ANDROID_ABI) + # For Android, CMAKE_FIND_ROOT_xxx is set to 'ONLY' by its cmake file. + # Thus find_package/find_library/find_path only searches files in sysroot path of NDK. + # But we provide thirdparty files in path USER_ROOT, we force cmake to search it now. + set(CMAKE_INCLUDE_PATH $ENV{USER_ROOT}/${ANDROID_ABI}/usr/include) + set(CMAKE_LIBRARY_PATH $ENV{USER_ROOT}/${ANDROID_ABI}/usr/lib) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NO) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NO) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NO) + + find_package(CPPREST) + find_package(Boost COMPONENTS system) + + find_package(OpenSSL REQUIRED) + find_package(FFMPEG) + + if (EXISTS $ENV{USER_ROOT}/${ANDROID_ABI}/usr/lib/cmake/opencv4/OpenCVConfig.cmake) + set(OpenCV_DIR $ENV{USER_ROOT}/${ANDROID_ABI}/usr/lib/cmake/opencv4) + find_package(OpenCV) + endif() + + if (DEFINED ENV{MINDSPORE_PATH}) + find_package(MINDSPORE) + endif() + + # Resume the settings. + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set(CMAKE_INCLUDE_PATH "") + set(CMAKE_LIBRARY_PATH "") +else() + find_package(CPPREST) + find_package(OpenSSL REQUIRED) + find_package(Boost COMPONENTS system) + find_package(CUDA 10.0) + find_package(TENSORRT) + find_package(TENSORFLOW) + find_package(OBS) + find_package(DIS) + find_package(VCN) + find_package(NVCUVID) + find_package(FFMPEG) + find_package(ACL) + find_package(DSMI) + find_package(OpenCV) + find_package(DUKTAPE) + find_package(MINDSPORE) + find_package(FUSE) + find_package(JNI) + find_package(Java) +endif() add_subdirectory(thirdparty) add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bf16af3ba..3b9e21f8f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,6 +22,14 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) message(FATAL_ERROR "Do not build in source directory!") endif() +if (DEFINED ENV{USER_ROOT} AND ANDROID_ABI) + include_directories($ENV{USER_ROOT}/${ANDROID_ABI}/usr/include) + link_directories($ENV{USER_ROOT}/${ANDROID_ABI}/usr/lib) + + set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed ${CMAKE_SHARED_LINKER_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed ${CMAKE_SHARED_LINKER_FLAGS}") +endif() + add_subdirectory(libmodelbox) add_subdirectory(drivers) add_subdirectory(develop) diff --git a/src/drivers/devices/cpu/flowunit/python/CMakeLists.txt b/src/drivers/devices/cpu/flowunit/python/CMakeLists.txt index 8903f544d..7f217fd01 100644 --- a/src/drivers/devices/cpu/flowunit/python/CMakeLists.txt +++ b/src/drivers/devices/cpu/flowunit/python/CMakeLists.txt @@ -51,7 +51,6 @@ target_link_libraries(${MODELBOX_UNIT_STATIC} PRIVATE pybind11::embed) set_property(TARGET ${MODELBOX_UNIT_STATIC} PROPERTY POSITION_INDEPENDENT_CODE ON) add_library(${MODELBOX_UNIT_SHARED} SHARED ${EMPTY_SOURCE_FILE}) -target_link_libraries(${MODELBOX_UNIT_SHARED} ${MODELBOX_UNIT_STATIC} ) target_link_libraries(${MODELBOX_UNIT_SHARED} -Wl,--whole-archive ${MODELBOX_UNIT_STATIC} -Wl,--no-whole-archive) set(LIBMODELBOX_FLOWUNIT_PYTHON_SHARED ${MODELBOX_UNIT_SHARED}) target_link_libraries(${MODELBOX_UNIT_SHARED} ${MODELBOX_COMMON_MODELBOX_API_LIBRARY}) diff --git a/src/drivers/devices/cpu/flowunit/python/python_flowunit.cc b/src/drivers/devices/cpu/flowunit/python/python_flowunit.cc index 4f2af7526..10da497ca 100644 --- a/src/drivers/devices/cpu/flowunit/python/python_flowunit.cc +++ b/src/drivers/devices/cpu/flowunit/python/python_flowunit.cc @@ -16,6 +16,7 @@ #include "python_flowunit.h" +#include "modelbox/base/memory_stub.h" #include "modelbox/device/cpu/device_cpu.h" using namespace pybind11::literals; @@ -44,7 +45,7 @@ void PythonFlowUnit::EnablePythonDebug() { modelbox::Status PythonFlowUnit::Open( const std::shared_ptr& opts) { - python_desc_ = std::dynamic_pointer_cast( + python_desc_ = modelbox_dynamic_pointer_cast( this->GetFlowUnitDesc()); auto python_entry = python_desc_->GetPythonEntry(); @@ -249,7 +250,7 @@ modelbox::Status PythonFlowUnit::Close() { void PythonFlowUnit::SetFlowUnitDesc( std::shared_ptr desc) { - python_desc_ = std::dynamic_pointer_cast(desc); + python_desc_ = modelbox_dynamic_pointer_cast(desc); } std::shared_ptr PythonFlowUnit::GetFlowUnitDesc() { diff --git a/src/drivers/devices/cpu/flowunit/video_encoder/ffmpeg_video_muxer.cc b/src/drivers/devices/cpu/flowunit/video_encoder/ffmpeg_video_muxer.cc index 8fc23a274..ac16c7e61 100644 --- a/src/drivers/devices/cpu/flowunit/video_encoder/ffmpeg_video_muxer.cc +++ b/src/drivers/devices/cpu/flowunit/video_encoder/ffmpeg_video_muxer.cc @@ -58,7 +58,16 @@ Status FfmpegVideoMuxer::Mux(const AVRational &time_base, av_packet_rescale_ts(av_packet.get(), time_base, stream_->time_base); av_packet->stream_index = stream_->index; if (!is_header_wrote_) { + #ifndef ANDROID auto ret = avformat_write_header(format_ctx_.get(), nullptr); + #else + AVDictionary *options = nullptr; + av_dict_set(&options, "rtsp_transport", "tcp", 0); + av_dict_set(&options, "recv_buffer_size", "10240000", 0); + av_dict_set(&options, "stimeout", "2000000", 0); + auto ret = avformat_write_header(format_ctx_.get(), &options); + #endif + if (ret < 0) { GET_FFMPEG_ERR(ret, ffmpeg_err); MBLOG_ERROR << "avformat_write_header failed, ret " << ffmpeg_err; diff --git a/src/drivers/virtual/inference/virtualdriver_inference.cc b/src/drivers/virtual/inference/virtualdriver_inference.cc index 5d267d365..152bda76f 100644 --- a/src/drivers/virtual/inference/virtualdriver_inference.cc +++ b/src/drivers/virtual/inference/virtualdriver_inference.cc @@ -16,6 +16,7 @@ #include "virtualdriver_inference.h" #include "modelbox/base/driver.h" +#include "modelbox/base/memory_stub.h" using namespace modelbox; @@ -363,7 +364,7 @@ void VirtualInferenceFlowUnitFactory::SetFlowUnitFactory( bind_flowunit_factory_list) { for (auto &bind_flowunit_factory : bind_flowunit_factory_list) { bind_flowunit_factory_list_.push_back( - std::dynamic_pointer_cast(bind_flowunit_factory)); + modelbox_dynamic_pointer_cast(bind_flowunit_factory)); } } @@ -372,17 +373,17 @@ VirtualInferenceFlowUnitFactory::VirtualCreateFlowUnit( const std::string &unit_name, const std::string &unit_type, const std::string &virtual_type) { for (auto &flowunit_factory : bind_flowunit_factory_list_) { - if (std::dynamic_pointer_cast(flowunit_factory) + if (modelbox_dynamic_pointer_cast(flowunit_factory) ->GetFlowUnitFactoryType() != unit_type) { continue; } - if (std::dynamic_pointer_cast(flowunit_factory) + if (modelbox_dynamic_pointer_cast(flowunit_factory) ->GetVirtualType() != virtual_type) { continue; } - return std::dynamic_pointer_cast(flowunit_factory) + return modelbox_dynamic_pointer_cast(flowunit_factory) ->CreateFlowUnit(unit_name, unit_type); } StatusError = {STATUS_NOTFOUND, "Cannot found virtual flowunit " + diff --git a/src/drivers/virtual/python/virtualdriver_python.cc b/src/drivers/virtual/python/virtualdriver_python.cc index 226c04793..ab3d186ef 100644 --- a/src/drivers/virtual/python/virtualdriver_python.cc +++ b/src/drivers/virtual/python/virtualdriver_python.cc @@ -15,7 +15,7 @@ */ #include "virtualdriver_python.h" - +#include "modelbox/base/memory_stub.h" #include using namespace modelbox; @@ -386,7 +386,7 @@ void VirtualPythonFlowUnitFactory::SetFlowUnitFactory( bind_flowunit_factory_list) { for (auto &bind_flowunit_factory : bind_flowunit_factory_list) { bind_flowunit_factory_list_.push_back( - std::dynamic_pointer_cast(bind_flowunit_factory)); + modelbox_dynamic_pointer_cast(bind_flowunit_factory)); } } @@ -394,11 +394,11 @@ std::shared_ptr VirtualPythonFlowUnitFactory::CreateFlowUnit(const std::string &unit_name, const std::string &unit_type) { for (auto &flowunit_factory : bind_flowunit_factory_list_) { - if (std::dynamic_pointer_cast(flowunit_factory) + if (modelbox_dynamic_pointer_cast(flowunit_factory) ->GetFlowUnitFactoryType() != unit_type) { continue; } - return std::dynamic_pointer_cast(flowunit_factory) + return modelbox_dynamic_pointer_cast(flowunit_factory) ->CreateFlowUnit(unit_name, unit_type); } return nullptr; diff --git a/src/libmodelbox/base/device/device_manager.cc b/src/libmodelbox/base/device/device_manager.cc index 7f67f8b27..ec7f0c977 100644 --- a/src/libmodelbox/base/device/device_manager.cc +++ b/src/libmodelbox/base/device/device_manager.cc @@ -24,6 +24,7 @@ #include "modelbox/base/driver.h" #include "modelbox/base/log.h" #include "modelbox/base/status.h" +#include "modelbox/base/memory_stub.h" namespace modelbox { DeviceManager::DeviceManager() {} @@ -87,7 +88,7 @@ Status DeviceManager::InitDeviceFactory(std::shared_ptr driver) { } desc = device_driver->GetDriverDesc(); std::shared_ptr device_factory = - std::dynamic_pointer_cast(temp_factory); + modelbox_dynamic_pointer_cast(temp_factory); device_factory_.insert(std::make_pair(desc->GetType(), device_factory)); } diff --git a/src/libmodelbox/base/graph_manager/graph_manager.cc b/src/libmodelbox/base/graph_manager/graph_manager.cc index b7ca62978..21420d4aa 100644 --- a/src/libmodelbox/base/graph_manager/graph_manager.cc +++ b/src/libmodelbox/base/graph_manager/graph_manager.cc @@ -15,6 +15,7 @@ */ #include +#include namespace modelbox { @@ -397,7 +398,7 @@ Status GraphConfigManager::InitGraphConfigFactory( } std::shared_ptr graph_conf_factory = - std::dynamic_pointer_cast(temp_factory); + modelbox_dynamic_pointer_cast(temp_factory); graph_conf_factories_.insert(std::make_pair( graph_conf_factory->GetGraphConfFactoryType(), graph_conf_factory)); diff --git a/src/libmodelbox/base/include/modelbox/base/any.h b/src/libmodelbox/base/include/modelbox/base/any.h index d0c77981a..ed4db05e3 100644 --- a/src/libmodelbox/base/include/modelbox/base/any.h +++ b/src/libmodelbox/base/include/modelbox/base/any.h @@ -188,6 +188,15 @@ class Collection { return false; } + #ifdef ANDROID + /* When they come from different so files, they may have different hash + * codes even if they have the same names. */ + if (strcmp(typeid(T).name(), entrys_[key].type().name()) == 0) { + value = any_cast(entrys_[key]); + return true; + } + #endif + if (!CanConvert(typeid(T).hash_code(), entrys_[key].type().hash_code())) { // always a bad condition MBLOG_ERROR << "Get value for " << key diff --git a/src/libmodelbox/base/include/modelbox/base/driver.h b/src/libmodelbox/base/include/modelbox/base/driver.h index 27c0cdf51..1983b3df3 100644 --- a/src/libmodelbox/base/include/modelbox/base/driver.h +++ b/src/libmodelbox/base/include/modelbox/base/driver.h @@ -31,7 +31,11 @@ namespace modelbox { constexpr const char *DRIVER_CLASS_VIRTUAL = "DRIVER-VIRTUAL"; constexpr const char *DRIVER_CLASS_INFERENCE = "DRIVER-INFERENCE"; constexpr const char *DRIVER_TYPE_VIRTUAL = "virtual"; +#ifdef ANDROID +constexpr const char *DEFAULT_SCAN_INFO = "./tmp/modelbox-driver-info"; +#else constexpr const char *DEFAULT_SCAN_INFO = "/tmp/modelbox-driver-info"; +#endif constexpr const char *DEFAULT_LD_CACHE = "/etc/ld.so.cache"; class Driver; diff --git a/src/libmodelbox/base/include/modelbox/base/memory_stub.h b/src/libmodelbox/base/include/modelbox/base/memory_stub.h new file mode 100644 index 000000000..2f79a816f --- /dev/null +++ b/src/libmodelbox/base/include/modelbox/base/memory_stub.h @@ -0,0 +1,55 @@ +/* + * Copyright 2021 The Modelbox Project Authors. All Rights Reserved. + * + * 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. + */ + +#ifndef MODELBOX_MEMORY_STUB_H_ +#define MODELBOX_MEMORY_STUB_H_ + +#include + +#ifndef ANDROID + +#define modelbox_dynamic_pointer_cast std::dynamic_pointer_cast + +#else /* ANDROID */ + +#define modelbox_dynamic_pointer_cast modelbox::dynamic_pointer_cast + +namespace modelbox { + +/* LLVM __dynamic_cast calls is_equal() with use_strcmp=false, + * so the string names are not compared. It will return NULL + * if the object is allocated in one so file and dynamicly casted + * in another so file. */ +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + !std::is_array<_Tp>::value && !std::is_array<_Up>::value, + std::shared_ptr<_Tp> +>::type +dynamic_pointer_cast(const std::shared_ptr<_Up>& __r) _NOEXCEPT +{ + auto __p = std::dynamic_pointer_cast<_Tp>(__r); + if (__p) { + return __p; + } + return std::static_pointer_cast<_Tp>(__r); +} + +} // namespace modelbox +#endif /* ANDROID */ + +#endif /* MODELBOX_MEMORY_STUB_H_ */ diff --git a/src/libmodelbox/base/utils/backtrace.cc b/src/libmodelbox/base/utils/backtrace.cc new file mode 100644 index 000000000..c7e3568d8 --- /dev/null +++ b/src/libmodelbox/base/utils/backtrace.cc @@ -0,0 +1,139 @@ +/* Android does not provide execinfo.h. We implement backtrace and + * backtrace_symbols in this file. */ + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef ANDROID + +int backtrace(void **buffer, int size); +char **backtrace_symbols(void *const *buffer, int size); + +typedef struct _BacktraceCtrl +{ + void** buffer; + int size; + int index; +} BacktraceCtrl; + +static _Unwind_Reason_Code unwind_callback(struct _Unwind_Context* context, void* arg) +{ + BacktraceCtrl *ctrl; + unsigned long pc; + + ctrl = (BacktraceCtrl *)arg; + if (ctrl->index >= ctrl->size) + { + return _URC_END_OF_STACK; + } + + pc = _Unwind_GetIP(context); + if (pc) + { + ctrl->buffer[ctrl->index] = (void *)pc; + ctrl->index++; + } + return _URC_NO_REASON; +} + +int backtrace(void **buffer, int size) +{ + BacktraceCtrl ctrl; + + ctrl.buffer = buffer; + ctrl.size = size; + ctrl.index = 0; + + _Unwind_Backtrace(unwind_callback, &ctrl); + + return ctrl.index; +} + +#define MEM_BLK_SiZE 4096 + +char **backtrace_symbols(void *const *buffer, int size) +{ + char *symbols; + char *ptr; + int pos; + int len; + + int index; + char *addr; + Dl_info info; + + if (size <= 0) + { + return NULL; + } + + symbols = (char *)malloc(size * sizeof(void *) + MEM_BLK_SiZE); + if (symbols == NULL) + { + return NULL; + } + + memset(symbols, 0, sizeof(void *)); + + pos = size * sizeof(void *); + len = pos + MEM_BLK_SiZE; + + for (index = 0; index < size; index++) + { + addr = (char *)buffer[index]; + + /* Need more space? */ + if (len - pos < MEM_BLK_SiZE / 4) + { + ptr = (char *)realloc(symbols, len + MEM_BLK_SiZE); + + /* If realloc() fails, the original block is left untouched; it is not + freed or moved. */ + if (ptr == NULL) + { + break; + } + + symbols = ptr; + len += MEM_BLK_SiZE; + } + + *((char **)symbols + index) = symbols + pos; + + /* If the address specified in addr could not be matched to a shared + object, then these functions return 0. */ + if (!dladdr(addr, &info) || info.dli_fname == NULL) + { + pos += snprintf(symbols + pos, len - pos, "Unknown(+0) [%p]", addr) + 1; + continue; + } + + /* If no symbol matching addr could be found, then dli_sname and + dli_saddr are set to NULL. */ + if (info.dli_sname == NULL || info.dli_saddr == NULL) + { + pos += snprintf(symbols + pos, len - pos, "%s(+%lx) [%p]", info.dli_fname, + addr - (char *)info.dli_fbase, addr) + 1; + continue; + } + + pos += snprintf(symbols + pos, len - pos, "%s(%s+%lx) [%p]", info.dli_fname, + info.dli_sname, addr - (char *)info.dli_saddr, addr) + 1; + } + + return (char **)symbols; +} + +#endif /* ANDROID */ + +#ifdef __cplusplus +} +#endif + diff --git a/src/libmodelbox/base/utils/utils.cc b/src/libmodelbox/base/utils/utils.cc index d17859f3f..4d5891295 100644 --- a/src/libmodelbox/base/utils/utils.cc +++ b/src/libmodelbox/base/utils/utils.cc @@ -20,7 +20,14 @@ #include #include #include +#ifndef ANDROID #include +#else +extern "C" { + extern int backtrace(void **buffer, int size); + extern char **backtrace_symbols(void *const *buffer, int size); +} +#endif #include #include #include diff --git a/src/libmodelbox/engine/flowunit_manager.cc b/src/libmodelbox/engine/flowunit_manager.cc index ba42c01c7..38ce6b7f0 100644 --- a/src/libmodelbox/engine/flowunit_manager.cc +++ b/src/libmodelbox/engine/flowunit_manager.cc @@ -17,6 +17,7 @@ #include #include "modelbox/base/log.h" +#include "modelbox/base/memory_stub.h" #include "modelbox/flowunit.h" namespace modelbox { @@ -91,7 +92,7 @@ Status FlowUnitManager::InitFlowUnitFactory(std::shared_ptr driver) { } desc = flowunit_driver->GetDriverDesc(); std::shared_ptr flowunit_factory = - std::dynamic_pointer_cast(temp_factory); + modelbox_dynamic_pointer_cast(temp_factory); flowunit_factory->SetDriver(flowunit_driver); diff --git a/src/libmodelbox/include/modelbox/node.h b/src/libmodelbox/include/modelbox/node.h index 5ab25fb58..2b05e5f40 100644 --- a/src/libmodelbox/include/modelbox/node.h +++ b/src/libmodelbox/include/modelbox/node.h @@ -33,7 +33,7 @@ class OutPort; struct CmpByInputKey { bool operator()(const std::shared_ptr& k1, - const std::shared_ptr& k2) { + const std::shared_ptr& k2) const { if (k1->GetOrder() == k2->GetOrder()) { return k1.get() < k2.get(); } diff --git a/src/modelbox/manager/src/log.c b/src/modelbox/manager/src/log.c index 8e9f95816..fc7b28723 100644 --- a/src/modelbox/manager/src/log.c +++ b/src/modelbox/manager/src/log.c @@ -16,8 +16,11 @@ #include "log.h" - +#ifndef ANDROID #include +#else +#include "../../../libmodelbox/base/utils/backtrace.cc" +#endif #include #include #include diff --git a/src/modelbox/manager/src/manager.c b/src/modelbox/manager/src/manager.c index a94b7841c..d63f0fc91 100644 --- a/src/modelbox/manager/src/manager.c +++ b/src/modelbox/manager/src/manager.c @@ -357,8 +357,13 @@ int manager_init(char *conf_file, char *name) { tlog_setlogscreen(g_is_verbose); tlog_setlevel(conf_log_level); + #ifndef ANDROID manager_log(MANAGER_LOG_INFO, "%s starting... (Build : %s %s)", program_invocation_short_name, __DATE__, __TIME__); + #else + manager_log(MANAGER_LOG_INFO, "%s starting... (Build : %s %s)", + getprogname(), __DATE__, __TIME__); + #endif if (manager_init_server() != 0) { manager_log(MANAGER_LOG_ERR, "init master server failed."); diff --git a/src/modelbox/server/include/modelbox/server/utils.h b/src/modelbox/server/include/modelbox/server/utils.h index 47ea459a5..b0cc745e2 100644 --- a/src/modelbox/server/include/modelbox/server/utils.h +++ b/src/modelbox/server/include/modelbox/server/utils.h @@ -17,6 +17,8 @@ #ifndef MODELBOX_SERVER_UTILS_H_ #define MODELBOX_SERVER_UTILS_H_ +#include +#include #include #include #include diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index 9a5cb6242..189241b83 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -104,7 +104,7 @@ add_custom_command(TARGET modelbox-python WORKING_DIRECTORY ${MODELBOX_PYTHON_TARGET_DIR} POST_BUILD COMMENT "Building python wheel package.." - COMMAND strip -s ${MODELBOX_PYTHON_TARGET_DIR}/modelbox/*.so + COMMAND ${CMAKE_STRIP} -s ${MODELBOX_PYTHON_TARGET_DIR}/modelbox/*.so COMMAND umask 0022 && chmod -R a+rX . && ${PYTHON_EXECUTABLE} setup.py -q sdist -d ${MODELBOX_PYTHON_RELEASE_DIR} bdist_wheel -d ${MODELBOX_PYTHON_RELEASE_DIR}) install(CODE diff --git a/thirdparty/CMake/APIGW_CPP_CMakeList.in b/thirdparty/CMake/APIGW_CPP_CMakeList.in index 27f41a599..902223320 100644 --- a/thirdparty/CMake/APIGW_CPP_CMakeList.in +++ b/thirdparty/CMake/APIGW_CPP_CMakeList.in @@ -20,6 +20,8 @@ project(APIGW_CPP) include_directories(${CMAKE_CURRENT_LIST_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${OPENSSL_INCLUDE_DIR}) +link_directories(${OPENSSL_SSL_LIBRARY}) aux_source_directory(. DIR_SRCS) FILE(GLOB SRC_LIST_CPP diff --git a/thirdparty/CMake/cpp_httplib_cmakelist.in b/thirdparty/CMake/cpp_httplib_cmakelist.in index f3421889b..6a0152947 100644 --- a/thirdparty/CMake/cpp_httplib_cmakelist.in +++ b/thirdparty/CMake/cpp_httplib_cmakelist.in @@ -18,6 +18,8 @@ cmake_minimum_required(VERSION 3.10) project(cpp-httplib) +include_directories(${OPENSSL_INCLUDE_DIR}) + file(GLOB CPP_HTTPLIB_SOURCE *.c *.cpp *.cc) add_library(cpp-httplib SHARED EXCLUDE_FROM_ALL ${CPP_HTTPLIB_SOURCE}) add_library(cpp-httplib-static STATIC EXCLUDE_FROM_ALL ${CPP_HTTPLIB_SOURCE}) diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index 55faba800..e1f0c358c 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -31,10 +31,17 @@ else() endif() file(MAKE_DIRECTORY ${THIRDPARTY_DOWNLOAD_WORKING_DIR}) -execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .. - RESULT_VARIABLE COMMAND_RESULT - WORKING_DIRECTORY ${THIRDPARTY_DOWNLOAD_WORKING_DIR} -) +if (NOT ANDROID_NDK) + execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .. + RESULT_VARIABLE COMMAND_RESULT + WORKING_DIRECTORY ${THIRDPARTY_DOWNLOAD_WORKING_DIR} + ) +else() + execute_process(COMMAND ${CMAKE_COMMAND} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DPYTHON_VERSION_STRING=${PYTHON_VERSION_STRING} -DANDROID_ABI=${ANDROID_ABI} -DANDROID_PLATFORM=${ANDROID_PLATFORM} -DANDROID_NDK=${ANDROID_NDK} -DANDROID_TOOLCHAIN=${ANDROID_TOOLCHAIN} -DANDROID_STL=${ANDROID_STL} -Wno-deprecated -Wno-dev -G "${CMAKE_GENERATOR}" .. + RESULT_VARIABLE COMMAND_RESULT + WORKING_DIRECTORY ${THIRDPARTY_DOWNLOAD_WORKING_DIR} + ) +endif() if(COMMAND_RESULT) message(FATAL_ERROR "Download thirdparty failed: ${COMMAND_RESULT}") @@ -55,15 +62,47 @@ set(GOOGLETEST_SOURCE_DIR ${THIRDPARTY_DOWNLOAD_DIR}/googletest) add_subdirectory(${GOOGLETEST_SOURCE_DIR} ${THIRDPARTY_DOWNLOAD_WORKING_DIR}/googletest EXCLUDE_FROM_ALL) set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_OLD}) -set(PYTHON_VER 3.5) -find_package(PythonInterp ${PYTHON_VER}) -if(NOT ${PYTHONINTERP_FOUND}) +if (DEFINED ENV{USER_ROOT} AND ANDROID_ABI AND PYTHON_VERSION_STRING) + if(EXISTS "$ENV{USER_ROOT}/${ANDROID_ABI}/usr/lib/libpython${PYTHON_VERSION_STRING}.so") + string(REPLACE "." ";" _PYVER_LIST ${PYTHON_VERSION_STRING}) + list(LENGTH _PYVER_LIST _PYVER_LIST_LEN) + + if(${_PYVER_LIST_LEN} GREATER 0) + list(GET _PYVER_LIST 0 PYTHON_VERSION_MAJOR) + endif() + if(${_PYVER_LIST_LEN} GREATER 1) + list(GET _PYVER_LIST 1 PYTHON_VERSION_MINOR) + endif() + + if(${_PYVER_LIST_LEN} GREATER 2) + list(GET _PYVER_LIST 2 PYTHON_VERSION_PATCH) + if(PYTHON_VERSION_PATCH EQUAL 0) + string(REGEX REPLACE "\\.0$" "" PYTHON_VERSION_STRING "${PYTHON_VERSION_STRING}") + endif() + endif() + + # No use for Android. + set(PYTHONINTERP_FOUND TRUE CACHE INTERNAL "") set(PYTHON_EXECUTABLE /usr/bin/python3) + + set(PYTHONLIBS_FOUND TRUE CACHE INTERNAL "") + set(PYTHON_LIBRARIES $ENV{USER_ROOT}/${ANDROID_ABI}/usr/lib/libpython${PYTHON_VERSION_STRING}.so) + set(PYTHON_INCLUDE_DIRS $ENV{USER_ROOT}/${ANDROID_ABI}/usr/include/python${PYTHON_VERSION_STRING}) + + set(PYTHON_MODULE_EXTENSION ".cpython-${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}.so") + message(WARNING "Using python lib $ENV{USER_ROOT}/${ANDROID_ABI}/usr/lib/libpython${PYTHON_VERSION_STRING}.so") + endif() +else() + set(PYTHON_VER 3.5) find_package(PythonInterp ${PYTHON_VER}) -endif() + if(NOT ${PYTHONINTERP_FOUND}) + set(PYTHON_EXECUTABLE /usr/bin/python3) + find_package(PythonInterp ${PYTHON_VER}) + endif() -find_package(PythonLibs ${PYTHON_VER}) -set(PYTHONLIBS_FOUND ${PYTHONLIBS_FOUND} CACHE INTERNAL "") + find_package(PythonLibs ${PYTHON_VER}) + set(PYTHONLIBS_FOUND ${PYTHONLIBS_FOUND} CACHE INTERNAL "") +endif() if (NOT ${PYTHONE_DISABLED} AND ${PYTHONLIBS_FOUND}) set(PYBIND_SOURCE_DIR ${THIRDPARTY_DOWNLOAD_DIR}/pybind11)