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

thrift: module integration, samples, and tests #54013

Merged
Merged
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
11 changes: 11 additions & 0 deletions MAINTAINERS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2701,6 +2701,17 @@ West:
labels:
- manifest-tflite-micro

"West project: thrift":
status: maintained
maintainers:
- cfriedt
files:
- modules/thrift/Kconfig
- samples/modules/thrift/
- tests/lib/thrift/
labels:
- manifest-thrift

"West project: tinycrypt":
status: odd fixes
files:
Expand Down
4 changes: 4 additions & 0 deletions modules/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ source "modules/Kconfig.st"
source "modules/Kconfig.stm32"
source "modules/Kconfig.syst"
source "modules/Kconfig.telink"
source "modules/thrift/Kconfig"
source "modules/Kconfig.tinycrypt"
source "modules/Kconfig.vega"
source "modules/Kconfig.wurthelektronik"
Expand Down Expand Up @@ -95,6 +96,9 @@ comment "zcbor module not available."
comment "CHRE module not available."
depends on !ZEPHYR_CHRE_MODULE

comment "THRIFT module not available."
depends on !ZEPHYR_THRIFT_MODULE

# This ensures that symbols are available in Kconfig for dependency checking
# and referencing, while keeping the settings themselves unavailable when the
# modules are not present in the workspace
Expand Down
43 changes: 43 additions & 0 deletions modules/thrift/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2022 Meta
# SPDX-License-Identifier: Apache-2.0

if(CONFIG_THRIFT)

set(THRIFT_UPSTREAM ${ZEPHYR_THRIFT_MODULE_DIR})

zephyr_library()

zephyr_include_directories(src)
zephyr_include_directories(include)
zephyr_include_directories(${THRIFT_UPSTREAM}/lib/cpp/src)

zephyr_library_sources(
src/_stat.c
src/thrift/server/TFDServer.cpp
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/protocol/TProtocol.cpp
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/server/TConnectedClient.cpp
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/server/TSimpleServer.cpp
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/transport/SocketCommon.cpp
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/transport/TBufferTransports.cpp
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/transport/TFDTransport.cpp
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/transport/TTransportException.cpp
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/transport/TServerSocket.cpp
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/transport/TSocket.cpp
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/TApplicationException.cpp
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/TOutput.cpp

# Replace with upstream equivalents when Zephyr's std::thread, etc, are fixed
src/thrift/concurrency/Mutex.cpp
src/thrift/server/TServerFramework.cpp
)

zephyr_library_sources_ifdef(CONFIG_THRIFT_SSL_SOCKET
# Replace with upstream equivalents when Zephyr's std::thread, etc, are fixed
src/thrift/transport/TSSLSocket.cpp
src/thrift/transport/TSSLServerSocket.cpp
)

# needed because std::iterator was deprecated with -std=c++17
zephyr_library_compile_options(-Wno-deprecated-declarations)

endif(CONFIG_THRIFT)
31 changes: 31 additions & 0 deletions modules/thrift/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2022 Meta
# SPDX-License-Identifier: Apache-2.0

config ZEPHYR_THRIFT_MODULE
bool

menuconfig THRIFT
bool "Support for Thrift [EXPERIMENTAL]"
select EXPERIMENTAL
depends on CPP
depends on STD_CPP17
depends on CPP_EXCEPTIONS
depends on POSIX_API
help
Enable this option to support Apache Thrift

if THRIFT

config THRIFT_SSL_SOCKET
bool "TSSLSocket support for Thrift"
depends on MBEDTLS
depends on MBEDTLS_PEM_CERTIFICATE_FORMAT
depends on NET_SOCKETS_SOCKOPT_TLS
help
Enable this option to support TSSLSocket for Thrift

module = THRIFT
module-str = THRIFT
source "subsys/logging/Kconfig.template.log_config"

endif # THRIFT
33 changes: 33 additions & 0 deletions modules/thrift/cmake/thrift.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2022 Meta
# SPDX-License-Identifier: Apache-2.0

find_program(THRIFT_EXECUTABLE thrift)
if(NOT THRIFT_EXECUTABLE)
message(FATAL_ERROR "The 'thrift' command was not found")
endif()

function(thrift
cfriedt marked this conversation as resolved.
Show resolved Hide resolved
target # CMake target (for dependencies / headers)
lang # The language for generated sources
lang_opts # Language options (e.g. ':no_skeleton')
out_dir # Output directory for generated files
# (do not include 'gen-cpp', etc)
source_file # The .thrift source file
options # Additional thrift options

# Generated files in ${ARGN}
)
file(MAKE_DIRECTORY ${out_dir})
add_custom_command(
OUTPUT ${ARGN}
COMMAND
${THRIFT_EXECUTABLE}
--gen ${lang}${lang_opts}
-o ${out_dir}
${source_file}
${options}
DEPENDS ${source_file}
)

target_include_directories(${target} PRIVATE ${out_dir}/gen-${lang})
endfunction()
20 changes: 20 additions & 0 deletions modules/thrift/src/_stat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2022 Meta
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <errno.h>
#include <sys/stat.h>

#include <zephyr/kernel.h>

int stat(const char *restrict path, struct stat *restrict buf)
{
ARG_UNUSED(path);
ARG_UNUSED(buf);

errno = ENOTSUP;

return -1;
}
44 changes: 44 additions & 0 deletions modules/thrift/src/thrift/concurrency/Mutex.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2022 Meta
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <thrift/concurrency/Mutex.h>

namespace apache
{
namespace thrift
{
namespace concurrency
{
stephanosio marked this conversation as resolved.
Show resolved Hide resolved

Mutex::Mutex()
{
}

void Mutex::lock() const
{
}

bool Mutex::trylock() const
{
return false;
}

bool Mutex::timedlock(int64_t milliseconds) const
{
return false;
}

void Mutex::unlock() const
{
}

void *Mutex::getUnderlyingImpl() const
{
return nullptr;
}
} // namespace concurrency
} // namespace thrift
} // namespace apache
183 changes: 183 additions & 0 deletions modules/thrift/src/thrift/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*
* Copyright (c) 2023 Meta
*
* SPDX-License-Identifier: Apache-2.0
*/
/* config.h. Generated from config.hin by configure. */
/* config.hin. Generated from configure.ac by autoheader. */

#ifndef ZEPHYR_MODULES_THRIFT_SRC_THRIFT_CONFIG_H_
#define ZEPHYR_MODULES_THRIFT_SRC_THRIFT_CONFIG_H_

/* Possible value for SIGNED_RIGHT_SHIFT_IS */
#define ARITHMETIC_RIGHT_SHIFT 1

/* Define to 1 if you have the <arpa/inet.h> header file. */
#define HAVE_ARPA_INET_H 1

/* Define to 1 if you have the `clock_gettime' function. */
#define HAVE_CLOCK_GETTIME 1

/* define if the compiler supports basic C++11 syntax */
#define HAVE_CXX11 1

/* Define to 1 if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1

/* Define to 1 if you have the `gethostbyname' function. */
#define HAVE_GETHOSTBYNAME 1

/* Define to 1 if you have the `gettimeofday' function. */
#define HAVE_GETTIMEOFDAY 1

/* Define to 1 if you have the `inet_ntoa' function. */
#define HAVE_INET_NTOA 1

/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1

/* Define to 1 if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1

/* Define to 1 if your system has a GNU libc compatible `malloc' function, and to 0 otherwise. */
#define HAVE_MALLOC 1

/* Define to 1 if you have the `memmove' function. */
#define HAVE_MEMMOVE 1

/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1

/* Define to 1 if you have the `memset' function. */
#define HAVE_MEMSET 1

/* Define to 1 if you have the `mkdir' function. */
#define HAVE_MKDIR 1

/* Define to 1 if you have the <netdb.h> header file. */
#define HAVE_NETDB_H 1

/* Define to 1 if you have the <netinet/in.h> header file. */
#define HAVE_NETINET_IN_H 1

/* Define to 1 if you have the <poll.h> header file. */
#define HAVE_POLL_H 1

/* Define to 1 if you have the <pthread.h> header file. */
#define HAVE_PTHREAD_H 1

/* Define to 1 if the system has the type `ptrdiff_t'. */
#define HAVE_PTRDIFF_T 1

/* Define to 1 if your system has a GNU libc compatible `realloc' function, and to 0 otherwise. */
#define HAVE_REALLOC 1

/* Define to 1 if you have the <sched.h> header file. */
#define HAVE_SCHED_H 1

/* Define to 1 if you have the `select' function. */
#define HAVE_SELECT 1

/* Define to 1 if you have the `socket' function. */
#define HAVE_SOCKET 1

/* Define to 1 if stdbool.h conforms to C99. */
#define HAVE_STDBOOL_H 1

/* Define to 1 if you have the <stddef.h> header file. */
#define HAVE_STDDEF_H 1

/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1

/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1

/* Define to 1 if you have the `strchr' function. */
#define HAVE_STRCHR 1

/* Define to 1 if you have the `strdup' function. */
#define HAVE_STRDUP 1

/* Define to 1 if you have the `strerror' function. */
#define HAVE_STRERROR 1

/* Define to 1 if you have the `strerror_r' function. */
#define HAVE_STRERROR_R 1

/* Define to 1 if you have the `strftime' function. */
#define HAVE_STRFTIME 1

/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1

/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1

/* Define to 1 if you have the `strstr' function. */
#define HAVE_STRSTR 1

/* Define to 1 if you have the `strtol' function. */
#define HAVE_STRTOL 1

/* Define to 1 if you have the `strtoul' function. */
#define HAVE_STRTOUL 1

/* Define to 1 if you have the <sys/ioctl.h> header file. */
#define HAVE_SYS_IOCTL_H 1

/* Define to 1 if you have the <sys/resource.h> header file. */
#define HAVE_SYS_RESOURCE_H 1

/* Define to 1 if you have the <sys/select.h> header file. */
#define HAVE_SYS_SELECT_H 1

/* Define to 1 if you have the <sys/socket.h> header file. */
#define HAVE_SYS_SOCKET_H 1

/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1

/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1

/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1

/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1

/* Define to 1 if you have the `vprintf' function. */
#define HAVE_VPRINTF 1

/* define if zlib is available */
/* #undef HAVE_ZLIB */

/* Possible value for SIGNED_RIGHT_SHIFT_IS */
#define LOGICAL_RIGHT_SHIFT 2

/* Define as the return type of signal handlers (`int' or `void'). */
#define RETSIGTYPE void

/* Define to the type of arg 1 for `select'. */
#define SELECT_TYPE_ARG1 int

/* Define to the type of args 2, 3 and 4 for `select'. */
#define SELECT_TYPE_ARG234 (fd_set *)

/* Define to the type of arg 5 for `select'. */
#define SELECT_TYPE_ARG5 (struct timeval *)

/* Indicates the effect of the right shift operator on negative signed integers */
#define SIGNED_RIGHT_SHIFT_IS 1

/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1

/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#define TIME_WITH_SYS_TIME 1

/* Possible value for SIGNED_RIGHT_SHIFT_IS */
#define UNKNOWN_RIGHT_SHIFT 3

#endif /* ZEPHYR_MODULES_THRIFT_SRC_THRIFT_CONFIG_H_ */
Loading