Skip to content

Commit

Permalink
Add stub generation feature
Browse files Browse the repository at this point in the history
  • Loading branch information
elbakramer committed Mar 3, 2024
1 parent 9f5db6f commit 5ff7e25
Show file tree
Hide file tree
Showing 65 changed files with 4,302 additions and 1,206 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,7 @@ cython_debug/

# PyPI Publish
.pypirc

# Others
.ignore/
TODO
24 changes: 15 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://github.com/google/googletest.git
[submodule "third_party/zlib"]
path = third_party/zlib
url = https://github.com/zlib-ng/zlib-ng.git
[submodule "third_party/abseil-cpp"]
path = third_party/abseil-cpp
url = https://github.com/abseil/abseil-cpp.git
[submodule "third_party/protobuf"]
path = third_party/protobuf
url = https://github.com/protocolbuffers/protobuf.git
branch = 20240116.1
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://github.com/google/googletest.git
branch = v1.14.0
[submodule "third_party/grpc"]
path = third_party/grpc
url = https://github.com/grpc/grpc.git
branch = v1.62.0
[submodule "third_party/protobuf"]
path = third_party/protobuf
url = https://github.com/protocolbuffers/protobuf.git
branch = v25.3
[submodule "third_party/qt"]
path = third_party/qt
url = https://code.qt.io/qt/qt5.git
branch = v6.6.2
[submodule "third_party/zlib"]
path = third_party/zlib
url = https://github.com/zlib-ng/zlib-ng.git
branch = 2.1.6
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" CACHE PATH "Det
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/cmake/toolchain/toolchain-msvc-auto.cmake" CACHE STRING "CMake toolchain file")

# project definition
project(AxServe VERSION 0.1.4 LANGUAGES CXX)
project(AxServe VERSION 0.1.5 LANGUAGES CXX)

# cache variable for executable's name
string(TOLOWER "${PROJECT_NAME}" PROJECT_NAME_LOWERCASE)
Expand Down Expand Up @@ -63,8 +63,8 @@ file(GLOB_RECURSE TS_FILES
# gather all project sources
set(PROJECT_SOURCE_FILES ${CXX_FILES} ${PROTO_FILES} ${TS_FILES})

# use cxx standard 20
set(CMAKE_CXX_STANDARD 20 CACHE STRING "C++ compiler standard")
# use cxx standard 17
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ compiler standard")
set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE BOOL "C++ compiler standard required")

# cache variables for dependency resolution
Expand Down
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ Just started working on a Python client.

Check the following codes for more information, until relevant documentations are added:

- Python client implementation [stub.py](https://github.com/elbakramer/axserve/blob/main/src/python/axserve/client/stub.py)
- Example usage of it [example_client.py](https://github.com/elbakramer/axserve/blob/main/src/python/example_client.py)
- Example usages from tests:
- Normal synchronous API: [test_iexplorer.py](https://github.com/elbakramer/axserve/blob/main/tests/test_iexplorer.py)
- Asynchronous API under `asyncio` framework: [test_iexplorer_async.py](https://github.com/elbakramer/axserve/blob/main/tests/test_iexplorer_async.py)
- Python client implementation [stub.py](https://github.com/elbakramer/axserve/blob/main/src/python/axserve/client/stub.py)
- Proto file for gRPC service definition [active.proto](https://github.com/elbakramer/axserve/blob/main/src/proto/active.proto)

# Building
Expand Down Expand Up @@ -169,7 +172,7 @@ https://ninja-build.org/
choco install ninja
```

## Build Project
## Build Project using CMake

### List Configure Presets

Expand All @@ -188,3 +191,17 @@ cmake --preset x86-win32-debug .
```
cmake --build .\build\x86-win32-debug --parallel
```

## Build Project using Hatch and publish

### Build Project for Python client package

```
hatch build
```

## Publish to PyPI

```
hatch publish
```
6 changes: 1 addition & 5 deletions cmake/dependencies/abseil-cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if(AXSERVE_ABSL_PROVIDER STREQUAL "module")

if(NOT EXISTS "${ABSL_SOURCE_DIR}/CMakeLists.txt")
set(ABSL_GIT_REPOSITORY "https://github.com/abseil/abseil-cpp.git")
set(ABSL_GIT_TAG "20230802.1")
set(ABSL_GIT_TAG "20240116.1")
endif()

set(ABSL_CMAKE_COMMAND "${CMAKE_COMMAND}")
Expand All @@ -33,10 +33,6 @@ if(AXSERVE_ABSL_PROVIDER STREQUAL "module")
"--parallel")
endif()

set(ABSL_PATCH_COMMAND
git restore * &&
git apply --ignore-whitespace "${CMAKE_CURRENT_LIST_DIR}/../../patches/absl-20230802.1.patch")

include("${CMAKE_CURRENT_LIST_DIR}/googletest.cmake")
set(ABSL_CMAKE_CACHE_ARGS
"-DCMAKE_INSTALL_PREFIX:PATH=${ABSL_PREFIX_DIR}"
Expand Down
2 changes: 1 addition & 1 deletion cmake/dependencies/grpc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if(AXSERVE_GRPC_PROVIDER STREQUAL "module")

if(NOT EXISTS "${GRPC_SOURCE_DIR}/CMakeLists.txt")
set(GRPC_GIT_REPOSITORY "https://github.com/grpc/grpc.git")
set(GRPC_GIT_TAG "v1.60.0")
set(GRPC_GIT_TAG "v1.62.0")
endif()

set(GRPC_CMAKE_COMMAND "${CMAKE_COMMAND}")
Expand Down
4 changes: 2 additions & 2 deletions cmake/dependencies/protobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if(AXSERVE_PROTOBUF_PROVIDER STREQUAL "module")

if(NOT EXISTS "${PROTOBUF_SOURCE_DIR}/CMakeLists.txt")
set(PROTOBUF_GIT_REPOSITORY "https://github.com/protocolbuffers/protobuf.git")
set(PROTOBUF_GIT_TAG "v25.1")
set(PROTOBUF_GIT_TAG "v25.3")
endif()

set(PROTOBUF_CMAKE_COMMAND "${CMAKE_COMMAND}")
Expand All @@ -48,7 +48,7 @@ if(AXSERVE_PROTOBUF_PROVIDER STREQUAL "module")
"--install" "${PROTOBUF_BINARY_DIR}")
set(PROTOBUF_PATCH_COMMAND
git restore * &&
git apply --ignore-whitespace "${CMAKE_CURRENT_LIST_DIR}/../../patches/protobuf-v25.1.patch")
git apply --ignore-whitespace "${CMAKE_CURRENT_LIST_DIR}/../../patches/protobuf-v25.3.patch")
endif()

include("${CMAKE_CURRENT_LIST_DIR}/googletest.cmake")
Expand Down
2 changes: 1 addition & 1 deletion cmake/dependencies/qt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if(AXSERVE_QT6_PROVIDER STREQUAL "module")

if(NOT EXISTS "${QT6_SOURCE_DIR}/CMakeLists.txt")
set(QT6_GIT_REPOSITORY "https://code.qt.io/qt/qt5.git")
set(QT6_GIT_TAG "v6.6.1")
set(QT6_GIT_TAG "v6.6.2")
set(QT6_GIT_SUBMODULES ${QT6_SUBMODULES})
endif()

Expand Down
4 changes: 2 additions & 2 deletions cmake/dependencies/zlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if(AXSERVE_ZLIB_PROVIDER STREQUAL "module")

if(NOT EXISTS "${ZLIB_SOURCE_DIR}/CMakeLists.txt")
set(ZLIB_GIT_REPOSITORY "https://github.com/zlib-ng/zlib-ng.git")
set(ZLIB_GIT_TAG "2.1.5")
set(ZLIB_GIT_TAG "2.1.6")
endif()

set(ZLIB_CMAKE_COMMAND "${CMAKE_COMMAND}")
Expand All @@ -37,7 +37,7 @@ if(AXSERVE_ZLIB_PROVIDER STREQUAL "module")
"--parallel")
set(ZLIB_PATCH_COMMAND
git restore * &&
git apply --ignore-whitespace "${CMAKE_CURRENT_LIST_DIR}/../../patches/zlib-ng-2.1.5.patch")
git apply --ignore-whitespace "${CMAKE_CURRENT_LIST_DIR}/../../patches/zlib-ng-2.1.6.patch")
endif()

include("${CMAKE_CURRENT_LIST_DIR}/googletest.cmake")
Expand Down
37 changes: 29 additions & 8 deletions hatch_build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# Copyright 2023 Yunseong Hwang
#
# 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.
#
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations

import re
Expand All @@ -11,14 +27,12 @@
from packaging.requirements import Requirement


class BuildHookInterfaceWithCheckCommand(BuildHookInterface):
def check_command(self, cmd):
return subprocess.check_call(cmd)


class CMakeBuildHook(BuildHookInterfaceWithCheckCommand):
class CMakeBuildHook(BuildHookInterface):
PLUGIN_NAME = "cmake"

def check_command(self, cmd):
return subprocess.check_call(cmd, shell=False)

def clean(self, versions: list[str]) -> None:
builds = self.config.get("builds", [])
for build in builds:
Expand Down Expand Up @@ -117,9 +131,12 @@ def finalize(self, version: str, build_data: dict[str, Any], artifact_path: str)
pass


class ProtocBuildHook(BuildHookInterfaceWithCheckCommand):
class ProtocBuildHook(BuildHookInterface):
PLUGIN_NAME = "protoc"

def check_command(self, cmd):
return subprocess.check_call(cmd)

def _fix_import_in_grpc_py(self, filename):
with open(filename, "r+", encoding="utf-8") as f:
data = f.read()
Expand Down Expand Up @@ -160,7 +177,11 @@ class CustomBuildHook(BuildHookInterface):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
assert not hasattr(self, "_hooks")

if hasattr(self, "_hooks"):
msg = "Attribute alreay exists: _hooks"
raise RuntimeError(msg)

self._hooks: list[BuildHookInterface] = [
ProtocBuildHook(*args, **kwargs),
CMakeBuildHook(*args, **kwargs),
Expand Down
12 changes: 0 additions & 12 deletions patches/absl-20230802.1.patch

This file was deleted.

12 changes: 6 additions & 6 deletions patches/protobuf-v25.1.patch → patches/protobuf-v25.2.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f78fccc27..f830c8258 100644
index 162fb1c72..f4f32842b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,7 +41,7 @@ else (BUILD_SHARED_LIBS)
Expand All @@ -12,7 +12,7 @@ index f78fccc27..f830c8258 100644
set(protobuf_WITH_ZLIB_DEFAULT ON)
option(protobuf_WITH_ZLIB "Build with zlib support" ${protobuf_WITH_ZLIB_DEFAULT})
@@ -158,24 +158,16 @@ endif()

set(_protobuf_FIND_ZLIB)
if (protobuf_WITH_ZLIB)
- find_package(ZLIB)
Expand Down Expand Up @@ -44,16 +44,16 @@ index f78fccc27..f830c8258 100644
+ set(ZLIB_LIBRARIES ZLIB::ZLIB)
+ set(_protobuf_FIND_ZLIB "if(NOT ZLIB_FOUND AND NOT TARGET ZLIB::ZLIB)\n find_package(ZLIB REQUIRED)\nendif()")
endif (protobuf_WITH_ZLIB)

# We need to link with libatomic on systems that do not have builtin atomics, or
@@ -277,7 +269,6 @@ else (MSVC)
endif (MSVC)

include_directories(
- ${ZLIB_INCLUDE_DIRECTORIES}
${protobuf_BINARY_DIR}
${protobuf_SOURCE_DIR}/src)

diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake
index 422754a1a..ea91898d5 100644
--- a/cmake/libprotobuf.cmake
Expand Down Expand Up @@ -81,4 +81,4 @@ index 8aa9e45fe..8388f8a2e 100644
+PROTOBUF_CONSTINIT const MapFieldBase::VTable
MapField<Derived, Key, T, kKeyFieldType_, kValueFieldType_>::kVTable =
MapField::template MakeVTable<MapField>();

84 changes: 84 additions & 0 deletions patches/protobuf-v25.3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 162fb1c72..f4f32842b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,7 +41,7 @@ else (BUILD_SHARED_LIBS)
endif (BUILD_SHARED_LIBS)
option(protobuf_BUILD_SHARED_LIBS "Build Shared Libraries" ${protobuf_BUILD_SHARED_LIBS_DEFAULT})
include(CMakeDependentOption)
-cmake_dependent_option(protobuf_MSVC_STATIC_RUNTIME "Link static runtime libraries" ON
+cmake_dependent_option(protobuf_MSVC_STATIC_RUNTIME "Link static runtime libraries" OFF
"NOT protobuf_BUILD_SHARED_LIBS" OFF)
set(protobuf_WITH_ZLIB_DEFAULT ON)
option(protobuf_WITH_ZLIB "Build with zlib support" ${protobuf_WITH_ZLIB_DEFAULT})
@@ -158,24 +158,16 @@ endif()

set(_protobuf_FIND_ZLIB)
if (protobuf_WITH_ZLIB)
- find_package(ZLIB)
- if (ZLIB_FOUND)
- set(HAVE_ZLIB 1)
- # FindZLIB module define ZLIB_INCLUDE_DIRS variable
- # Set ZLIB_INCLUDE_DIRECTORIES for compatible
- set(ZLIB_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRECTORIES} ${ZLIB_INCLUDE_DIRS})
- # Using imported target if exists
- if (TARGET ZLIB::ZLIB)
- set(ZLIB_LIBRARIES ZLIB::ZLIB)
- set(_protobuf_FIND_ZLIB "if(NOT ZLIB_FOUND)\n find_package(ZLIB)\nendif()")
- endif (TARGET ZLIB::ZLIB)
- else (ZLIB_FOUND)
- set(HAVE_ZLIB 0)
- # Explicitly set these to empty (override NOT_FOUND) so cmake doesn't
- # complain when we use them later.
- set(ZLIB_INCLUDE_DIRECTORIES)
- set(ZLIB_LIBRARIES)
- endif (ZLIB_FOUND)
+ if (NOT TARGET ZLIB::ZLIB)
+ find_package(ZLIB REQUIRED)
+ endif()
+ set(HAVE_ZLIB 1)
+ # FindZLIB module define ZLIB_INCLUDE_DIRS variable
+ # Set ZLIB_INCLUDE_DIRECTORIES for compatible
+ set(ZLIB_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRECTORIES} ${ZLIB_INCLUDE_DIRS})
+ # Using imported target if exists
+ set(ZLIB_LIBRARIES ZLIB::ZLIB)
+ set(_protobuf_FIND_ZLIB "if(NOT ZLIB_FOUND AND NOT TARGET ZLIB::ZLIB)\n find_package(ZLIB REQUIRED)\nendif()")
endif (protobuf_WITH_ZLIB)

# We need to link with libatomic on systems that do not have builtin atomics, or
@@ -277,7 +269,6 @@ else (MSVC)
endif (MSVC)

include_directories(
- ${ZLIB_INCLUDE_DIRECTORIES}
${protobuf_BINARY_DIR}
${protobuf_SOURCE_DIR}/src)

diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake
index 422754a1a..ea91898d5 100644
--- a/cmake/libprotobuf.cmake
+++ b/cmake/libprotobuf.cmake
@@ -26,7 +26,9 @@ endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
target_link_libraries(libprotobuf PRIVATE log)
endif()
-target_include_directories(libprotobuf PUBLIC ${protobuf_SOURCE_DIR}/src)
+target_include_directories(libprotobuf PUBLIC
+ ${protobuf_SOURCE_DIR}/src
+ ${protobuf_SOURCE_DIR})
target_link_libraries(libprotobuf PUBLIC ${protobuf_ABSL_USED_TARGETS})
protobuf_configure_target(libprotobuf)
if(protobuf_BUILD_SHARED_LIBS)
diff --git a/src/google/protobuf/map_field.h b/src/google/protobuf/map_field.h
index 8aa9e45fe..8388f8a2e 100644
--- a/src/google/protobuf/map_field.h
+++ b/src/google/protobuf/map_field.h
@@ -678,7 +678,7 @@ class MapField final : public TypeDefinedMapFieldBase<Key, T> {
template <typename Derived, typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType_,
WireFormatLite::FieldType kValueFieldType_>
-constexpr MapFieldBase::VTable
+PROTOBUF_CONSTINIT const MapFieldBase::VTable
MapField<Derived, Key, T, kKeyFieldType_, kValueFieldType_>::kVTable =
MapField::template MakeVTable<MapField>();

15 changes: 15 additions & 0 deletions patches/zlib-ng-2.1.6.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/test/test_main.cc b/test/test_main.cc
index 82b39e48..fb2db610 100644
--- a/test/test_main.cc
+++ b/test/test_main.cc
@@ -11,7 +11,9 @@ extern "C" {
struct cpu_features test_cpu_features;
}

-GTEST_API_ int main(int argc, char **argv) {
+GTEST_API_ int main(int argc, char **argv);
+
+int main(int argc, char **argv) {
printf("Running main() from %s\n", __FILE__);
cpu_check_features(&test_cpu_features);
testing::InitGoogleTest(&argc, argv);
Loading

0 comments on commit 5ff7e25

Please sign in to comment.