Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Drogon windows compilation #2884

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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" : [],
}) + [
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -1680,7 +1680,7 @@ cc_library(
],
deps = [
"libdrogon_http_async_writer_interface",
"@drogon//:drogon_cmake",
"@drogon//:drogon",
"@mediapipe//mediapipe/framework/port:threadpool",
"libovmslogging",
],
Expand Down
10 changes: 10 additions & 0 deletions src/http_rest_api_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
#include <utility>
#include <vector>

#ifdef __linux__
#include <curl/curl.h>
#endif
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
#include <spdlog/spdlog.h>
Expand Down Expand Up @@ -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();
Expand All @@ -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
185 changes: 143 additions & 42 deletions third_party/drogon/drogon.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -83,23 +126,20 @@ 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",
"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\"
"CMAKE_CXX_STANDARD": "17",
"CXX_FILESYSTEM_HAVE_FS": "1",
}} | select({{
"//conditions:default": dict(
build_release
Expand All @@ -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,
)
30 changes: 30 additions & 0 deletions third_party/drogon/ovms_drogon.patch
Original file line number Diff line number Diff line change
@@ -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 <algorithm> // std::reverse()

template <typename T>
@@ -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<uint64_t>(value);
@@ -81,8 +82,6 @@ inline uint64_t ntohll(uint64_t value)
{
return htonll(value);
}
-#endif
-#endif

namespace drogon
{