diff --git a/BUILD.bazel b/BUILD.bazel index a86ce8fb2f..fd29b82bad 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -41,7 +41,7 @@ cc_library( "@org_tensorflow//tensorflow/core:framework", "@com_github_gabime_spdlog//:spdlog", "@com_github_jarro2783_cxxopts//:cxxopts", - "@drogon//:drogon_cmake", + "@drogon//:drogon", #"@tensorflow_serving//tensorflow_serving/util/net_http/server/public:http_server_api", #"@tensorflow_serving//tensorflow_serving/util:threadpool_executor", "@tensorflow_serving//tensorflow_serving/util:json_tensor", diff --git a/WORKSPACE b/WORKSPACE index 61141a1f90..947b30fe08 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -33,6 +33,14 @@ bazel_skylib_workspace() load("@bazel_skylib//lib:versions.bzl", "versions") versions.check(minimum_bazel_version = "6.0.0") +http_archive( + name = "zlib", + build_file = "@mediapipe//third_party:zlib.BUILD", + sha256 = "9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23", + strip_prefix = "zlib-1.3.1", + url = "http://zlib.net/fossils/zlib-1.3.1.tar.gz", +) + # RapidJSON # Must be defined earlier than tensorflow_serving because TFS is using older rapidjson # Version must match openvino.genai -> jinja2cpp -> rapidjson diff --git a/src/BUILD b/src/BUILD index abc5ffd978..e52aeeeca6 100644 --- a/src/BUILD +++ b/src/BUILD @@ -380,22 +380,22 @@ cc_library( "get_model_metadata_impl.cpp", "get_model_metadata_impl.hpp", "global_sequences_viewer.hpp", - "global_sequences_viewer.cpp",] + "global_sequences_viewer.cpp", + "http_server.hpp", + "http_server.cpp", + "httpservermodule.hpp", + "httpservermodule.cpp", + "http_rest_api_handler.hpp", + "http_rest_api_handler.cpp", + "http_frontend/http_graph_executor_impl.cpp", + "http_frontend/http_graph_executor_impl.hpp",] + select({ "//:is_windows_or_mediapipe_is_disabled_no_http": [], - "//conditions:default" : [ - "http_frontend/http_graph_executor_impl.cpp", - "http_frontend/http_graph_executor_impl.hpp",], + "//conditions:default" : [], }) #TODO : add to server lib and cleanup headers too many includes + select({ "//conditions:default": [ - "http_server.hpp", - "http_server.cpp", - "http_rest_api_handler.hpp", - "httpservermodule.hpp", - "http_rest_api_handler.cpp", - "httpservermodule.cpp", ], "//src:windows" : [], }) + [ @@ -467,10 +467,10 @@ cc_library( "//:disable_python": [] }) + select({ "//:is_windows_or_mediapipe_is_disabled_no_http": [], - "//conditions:default" : [ - "//src/embeddings:embeddingscalculator", - "//src/rerank:rerankcalculator",], + "//conditions:default" : [], }) + [ + "//src/embeddings:embeddingscalculator", + "//src/rerank:rerankcalculator", "cpp_headers", "libovms_capi_servable_metadata", "libmodelconfigjsonparser", @@ -1680,7 +1680,7 @@ cc_library( ], deps = [ "libdrogon_http_async_writer_interface", - "@drogon//:drogon_cmake", + "@drogon//:drogon", "@mediapipe//mediapipe/framework/port:threadpool", "libovmslogging", ], diff --git a/src/http_rest_api_handler.cpp b/src/http_rest_api_handler.cpp index 48dbe7ec48..05bf0d5806 100644 --- a/src/http_rest_api_handler.cpp +++ b/src/http_rest_api_handler.cpp @@ -25,7 +25,9 @@ #include #include +#ifdef __linux__ #include +#endif #include #include #include @@ -1141,6 +1143,8 @@ Status HttpRestApiHandler::processConfigStatusRequest(std::string& response, Mod return StatusCode::OK; } +// TODO: Windows +#ifdef __linux__ std::string urlDecode(const std::string& encoded) { int output_length; CURL* curl = curl_easy_init(); @@ -1156,5 +1160,11 @@ std::string urlDecode(const std::string& encoded) { } return encoded; } +#elif _WIN32 +// TODO: Windows +std::string urlDecode(const std::string& encoded) { + return encoded; +} +#endif } // namespace ovms diff --git a/third_party/drogon/drogon.bzl b/third_party/drogon/drogon.bzl index 67ea691c98..03b632294d 100644 --- a/third_party/drogon/drogon.bzl +++ b/third_party/drogon/drogon.bzl @@ -16,45 +16,88 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "patch") -def drogon_cpp(): - drogon_cpp_repository(name="_drogon_cpp") - http_archive( - name = "jsoncpp", - sha256 = "f93b6dd7ce796b13d02c108bc9f79812245a82e577581c4c9aabe57075c90ea2", - strip_prefix = "jsoncpp-1.9.6", - urls = [ - "https://github.com/open-source-parsers/jsoncpp/archive/1.9.6.tar.gz", +def _is_windows(ctx): + return ctx.os.name.lower().find("windows") != -1 + +def _get_linux_build_file(): + build_file_content = """ +load("@rules_foreign_cc//foreign_cc:cmake.bzl", "cmake") +load("@bazel_skylib//rules:common_settings.bzl", "string_flag") +visibility = ["//visibility:public"] +config_setting( + name = "dbg", + values = {{"compilation_mode": "dbg"}}, +) +config_setting( + name = "opt", + values = {{"compilation_mode": "opt"}}, +) +filegroup( + name = "all_srcs", + srcs = glob(["**"]), + visibility = ["//visibility:public"], +) +build_release = {{"CMAKE_BUILD_TYPE": "Release"}} +build_debug = {{"CMAKE_BUILD_TYPE": "Debug"}} +cmake( + name = "drogon_cmake", + build_args = [ + "--verbose", + "--", # <- Pass remaining options to the native tool. + # https://github.com/bazelbuild/rules_foreign_cc/issues/329 + # there is no elegant parallel compilation support + "VERBOSE=1", + "-j 6", + ], + cache_entries = {{ + "JSONCPP_INCLUDE_DIR": "@jsoncpp//:jsoncpp", + "BUILD_CTL": "OFF", + "BUILD_EXAMPLES": "OFF", + "BUILD_ORM": "OFF", + "BUILD_BROTLI": "OFF", + "BUILD_YAML_CONFIG": "OFF", + "CMAKE_INSTALL_LIBDIR": "lib", + "CMAKE_POSITION_INDEPENDENT_CODE": "ON", + "CMAKE_CXX_FLAGS": " -s -D_GLIBCXX_USE_CXX11_ABI=1 -Wno-error=deprecated-declarations -Wuninitialized\" + }} | select({{ + "//conditions:default": dict( + build_release + ), + ":dbg": dict( + build_debug + ), + }}), + env = {{ + "HTTP_PROXY": "{http_proxy}", + "HTTPS_PROXY": "{https_proxy}", + "http_proxy": "{http_proxy}", + "https_proxy": "{https_proxy}", + }}, + deps = ["@jsoncpp//:jsoncpp",], + lib_source = ":all_srcs", + out_lib_dir = "lib", + # linking order + out_static_libs = [ + "libdrogon.a", + "libtrantor.a", ], - build_file_content = """ + tags = ["requires-network"], + visibility = ["//visibility:public"], +) + cc_library( - name = "jsoncpp", - srcs = glob(["src/lib_json/*.cpp"]), - hdrs = glob(["include/json/*.h", "src/lib_json/*.h"]), - includes = [ - "include", # Add the top-level include directory - "src/lib_json", # Add the source-level include directory + name = "drogon", + deps = [ + ":drogon_cmake", ], visibility = ["//visibility:public"], - linkstatic = True, ) - """, - ) - new_git_repository( - name = "drogon", - remote = "https://github.com/drogonframework/drogon", - tag = "v1.9.7", # Sep 10 2024 - build_file = "@_drogon_cpp//:BUILD", - init_submodules = True, - recursive_init_submodules = True, - patch_cmds = ["find . -name '中文.txt' -delete"], - ) - -def _impl(repository_ctx): - http_proxy = repository_ctx.os.environ.get("http_proxy", "") - https_proxy = repository_ctx.os.environ.get("https_proxy", "") +""" + return build_file_content - # Note we need to escape '{/}' by doubling them due to call to format +def _get_windows_build_file(): build_file_content = """ load("@rules_foreign_cc//foreign_cc:cmake.bzl", "cmake") load("@bazel_skylib//rules:common_settings.bzl", "string_flag") @@ -83,15 +126,11 @@ build_debug = {{"CMAKE_BUILD_TYPE": "Debug"}} cmake( name = "drogon_cmake", build_args = [ - "--verbose", - "--", # <- Pass remaining options to the native tool. - # https://github.com/bazelbuild/rules_foreign_cc/issues/329 - # there is no elegant parallel compilation support - "VERBOSE=1", "-j 6", ], cache_entries = {{ - "JSONCPP_INCLUDE_DIR": "@jsoncpp//:jsoncpp", + "ZLIB_INCLUDE_DIR": "C:/baze_tmp/tpoq5oxa/execroot/ovms/external/zlib", + "ZLIB_LIBRARY": "@zlib//:zlib", "BUILD_CTL": "OFF", "BUILD_EXAMPLES": "OFF", "BUILD_ORM": "OFF", @@ -99,7 +138,8 @@ cmake( "BUILD_YAML_CONFIG": "OFF", "CMAKE_INSTALL_LIBDIR": "lib", "CMAKE_POSITION_INDEPENDENT_CODE": "ON", - "CMAKE_CXX_FLAGS": " -s -D_GLIBCXX_USE_CXX11_ABI=1 -Wno-error=deprecated-declarations -Wuninitialized\" + "CMAKE_CXX_STANDARD": "17", + "CXX_FILESYSTEM_HAVE_FS": "1", }} | select({{ "//conditions:default": dict( build_release @@ -111,22 +151,83 @@ cmake( env = {{ "HTTP_PROXY": "{http_proxy}", "HTTPS_PROXY": "{https_proxy}", + "http_proxy": "{http_proxy}", + "https_proxy": "{https_proxy}", }}, deps = ["@jsoncpp//:jsoncpp",], lib_source = ":all_srcs", out_lib_dir = "lib", # linking order out_static_libs = [ - "libdrogon.a", - "libtrantor.a", + "drogon.lib", + "trantor.lib", ], tags = ["requires-network"], visibility = ["//visibility:public"], ) + +cc_library( + name = "drogon", + deps = [ + ":drogon_cmake", + ], + visibility = ["//visibility:public"], +) """ + return build_file_content + +def drogon_cpp(): + drogon_cpp_repository(name="_drogon_cpp") + http_archive( + name = "jsoncpp", + sha256 = "f93b6dd7ce796b13d02c108bc9f79812245a82e577581c4c9aabe57075c90ea2", + strip_prefix = "jsoncpp-1.9.6", + urls = [ + "https://github.com/open-source-parsers/jsoncpp/archive/1.9.6.tar.gz", + ], + build_file_content = """ +cc_library( + name = "jsoncpp", + srcs = glob(["src/lib_json/*.cpp"]), + hdrs = glob(["include/json/*.h", "src/lib_json/*.h"]), + includes = [ + "include", # Add the top-level include directory + "src/lib_json", # Add the source-level include directory + ], + visibility = ["//visibility:public"], + linkstatic = True, +) + """, + ) + new_git_repository( + name = "drogon", + remote = "https://github.com/drogonframework/drogon", + tag = "v1.9.7", # Sep 10 2024 + build_file = "@_drogon_cpp//:BUILD", + init_submodules = True, + recursive_init_submodules = True, + patches = ["@//third_party/drogon:ovms_drogon.patch"], + patch_args = ["-p1"], + #patch_cmds = ["patch -p0 < %s" % patch_file] + ) + +def _impl(repository_ctx): + http_proxy = repository_ctx.os.environ.get("HTTP_PROXY", "") + https_proxy = repository_ctx.os.environ.get("HTTPS_PROXY", "") + if not http_proxy: + http_proxy = repository_ctx.os.environ.get("http_proxy", "") + if not https_proxy: + https_proxy = repository_ctx.os.environ.get("https_proxy", "") + + # Note we need to escape '{/}' by doubling them due to call to format + if _is_windows(repository_ctx): + build_file_content = _get_windows_build_file() + else: + build_file_content = _get_linux_build_file() + repository_ctx.file("BUILD", build_file_content.format(http_proxy=http_proxy, https_proxy=https_proxy)) drogon_cpp_repository = repository_rule( implementation = _impl, - local=False, + local=True, ) diff --git a/third_party/drogon/ovms_drogon.patch b/third_party/drogon/ovms_drogon.patch new file mode 100644 index 0000000000..6416c62f91 --- /dev/null +++ b/third_party/drogon/ovms_drogon.patch @@ -0,0 +1,30 @@ +diff --git a/orm_lib/inc/drogon/orm/SqlBinder.h b/orm_lib/inc/drogon/orm/SqlBinder.h +index 3335e6ff..7874f18b 100644 +--- a/orm_lib/inc/drogon/orm/SqlBinder.h ++++ b/orm_lib/inc/drogon/orm/SqlBinder.h +@@ -57,6 +57,8 @@ + #define __LITTLE_ENDIAN LITTLE_ENDIAN + #endif + ++#endif ++ + #include // std::reverse() + + template +@@ -71,7 +73,6 @@ constexpr T htonT(T value) noexcept + #endif + } + +-#if (!defined _WIN32) || (defined _WIN32 && _WIN32_WINNT < _WIN32_WINNT_WIN8) + inline uint64_t htonll(uint64_t value) + { + return htonT(value); +@@ -81,8 +82,6 @@ inline uint64_t ntohll(uint64_t value) + { + return htonll(value); + } +-#endif +-#endif + + namespace drogon + {