Skip to content

Commit 699f736

Browse files
committed
modules: add thrift module
Add glue code for the thrift module. This includes: * workarounds for Zephyr's missing C++ facilities * thrift config.h This code was merged from the following repository at the commit specified below, with minor formatting and coding-style modifications. https://github.com/zephyrproject-rtos/gsoc-2022-thrift e12e014d295918cc5ba0b4c507d1bf595a2f539a Signed-off-by: Chris Friedt <[email protected]>
1 parent 276f632 commit 699f736

21 files changed

+3559
-0
lines changed

modules/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ source "modules/Kconfig.st"
3636
source "modules/Kconfig.stm32"
3737
source "modules/Kconfig.syst"
3838
source "modules/Kconfig.telink"
39+
source "modules/thrift/Kconfig"
3940
source "modules/Kconfig.tinycrypt"
4041
source "modules/Kconfig.vega"
4142
source "modules/Kconfig.wurthelektronik"
@@ -95,6 +96,9 @@ comment "zcbor module not available."
9596
comment "CHRE module not available."
9697
depends on !ZEPHYR_CHRE_MODULE
9798

99+
comment "THRIFT module not available."
100+
depends on !ZEPHYR_THRIFT_MODULE
101+
98102
# This ensures that symbols are available in Kconfig for dependency checking
99103
# and referencing, while keeping the settings themselves unavailable when the
100104
# modules are not present in the workspace

modules/thrift/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2022 Meta
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if(CONFIG_THRIFT)
5+
6+
set(THRIFT_UPSTREAM ${ZEPHYR_THRIFT_MODULE_DIR})
7+
8+
zephyr_library()
9+
10+
zephyr_include_directories(src)
11+
zephyr_include_directories(include)
12+
zephyr_include_directories(${THRIFT_UPSTREAM}/lib/cpp/src)
13+
14+
zephyr_library_sources(
15+
src/_stat.c
16+
src/thrift/server/TFDServer.cpp
17+
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/protocol/TProtocol.cpp
18+
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/server/TConnectedClient.cpp
19+
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/server/TSimpleServer.cpp
20+
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/transport/SocketCommon.cpp
21+
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/transport/TBufferTransports.cpp
22+
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/transport/TFDTransport.cpp
23+
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/transport/TTransportException.cpp
24+
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/transport/TServerSocket.cpp
25+
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/transport/TSocket.cpp
26+
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/TApplicationException.cpp
27+
${THRIFT_UPSTREAM}/lib/cpp/src/thrift/TOutput.cpp
28+
29+
# Replace with upstream equivalents when Zephyr's std::thread, etc, are fixed
30+
src/thrift/concurrency/Mutex.cpp
31+
src/thrift/server/TServerFramework.cpp
32+
)
33+
34+
zephyr_library_sources_ifdef(CONFIG_THRIFT_SSL_SOCKET
35+
# Replace with upstream equivalents when Zephyr's std::thread, etc, are fixed
36+
src/thrift/transport/TSSLSocket.cpp
37+
src/thrift/transport/TSSLServerSocket.cpp
38+
)
39+
40+
# needed because std::iterator was deprecated with -std=c++17
41+
zephyr_library_compile_options(-Wno-deprecated-declarations)
42+
43+
endif(CONFIG_THRIFT)

modules/thrift/Kconfig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2022 Meta
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config ZEPHYR_THRIFT_MODULE
5+
bool
6+
7+
menuconfig THRIFT
8+
bool "Support for Thrift [EXPERIMENTAL]"
9+
select EXPERIMENTAL
10+
depends on CPP
11+
depends on STD_CPP17
12+
depends on CPP_EXCEPTIONS
13+
depends on POSIX_API
14+
help
15+
Enable this option to support Apache Thrift
16+
17+
if THRIFT
18+
19+
config THRIFT_SSL_SOCKET
20+
bool "TSSLSocket support for Thrift"
21+
depends on MBEDTLS
22+
depends on MBEDTLS_PEM_CERTIFICATE_FORMAT
23+
depends on NET_SOCKETS_SOCKOPT_TLS
24+
help
25+
Enable this option to support TSSLSocket for Thrift
26+
27+
module = THRIFT
28+
module-str = THRIFT
29+
source "subsys/logging/Kconfig.template.log_config"
30+
31+
endif # THRIFT

modules/thrift/cmake/thrift.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2022 Meta
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
find_program(THRIFT_EXECUTABLE thrift)
5+
if(NOT THRIFT_EXECUTABLE)
6+
message(FATAL_ERROR "The 'thrift' command was not found")
7+
endif()
8+
9+
function(thrift
10+
target # CMake target (for dependencies / headers)
11+
lang # The language for generated sources
12+
lang_opts # Language options (e.g. ':no_skeleton')
13+
out_dir # Output directory for generated files
14+
# (do not include 'gen-cpp', etc)
15+
source_file # The .thrift source file
16+
options # Additional thrift options
17+
18+
# Generated files in ${ARGN}
19+
)
20+
file(MAKE_DIRECTORY ${out_dir})
21+
add_custom_command(
22+
OUTPUT ${ARGN}
23+
COMMAND
24+
${THRIFT_EXECUTABLE}
25+
--gen ${lang}${lang_opts}
26+
-o ${out_dir}
27+
${source_file}
28+
${options}
29+
DEPENDS ${source_file}
30+
)
31+
32+
target_include_directories(${target} PRIVATE ${out_dir}/gen-${lang})
33+
endfunction()

modules/thrift/src/_stat.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2022 Meta
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <errno.h>
8+
#include <sys/stat.h>
9+
10+
#include <zephyr/kernel.h>
11+
12+
int stat(const char *restrict path, struct stat *restrict buf)
13+
{
14+
ARG_UNUSED(path);
15+
ARG_UNUSED(buf);
16+
17+
errno = ENOTSUP;
18+
19+
return -1;
20+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2022 Meta
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <thrift/concurrency/Mutex.h>
8+
9+
namespace apache
10+
{
11+
namespace thrift
12+
{
13+
namespace concurrency
14+
{
15+
16+
Mutex::Mutex()
17+
{
18+
}
19+
20+
void Mutex::lock() const
21+
{
22+
}
23+
24+
bool Mutex::trylock() const
25+
{
26+
return false;
27+
}
28+
29+
bool Mutex::timedlock(int64_t milliseconds) const
30+
{
31+
return false;
32+
}
33+
34+
void Mutex::unlock() const
35+
{
36+
}
37+
38+
void *Mutex::getUnderlyingImpl() const
39+
{
40+
return nullptr;
41+
}
42+
} // namespace concurrency
43+
} // namespace thrift
44+
} // namespace apache

modules/thrift/src/thrift/config.h

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
/*
2+
* Copyright (c) 2023 Meta
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* config.h. Generated from config.hin by configure. */
7+
/* config.hin. Generated from configure.ac by autoheader. */
8+
9+
#ifndef ZEPHYR_MODULES_THRIFT_SRC_THRIFT_CONFIG_H_
10+
#define ZEPHYR_MODULES_THRIFT_SRC_THRIFT_CONFIG_H_
11+
12+
/* Possible value for SIGNED_RIGHT_SHIFT_IS */
13+
#define ARITHMETIC_RIGHT_SHIFT 1
14+
15+
/* Define to 1 if you have the <arpa/inet.h> header file. */
16+
#define HAVE_ARPA_INET_H 1
17+
18+
/* Define to 1 if you have the `clock_gettime' function. */
19+
#define HAVE_CLOCK_GETTIME 1
20+
21+
/* define if the compiler supports basic C++11 syntax */
22+
#define HAVE_CXX11 1
23+
24+
/* Define to 1 if you have the <fcntl.h> header file. */
25+
#define HAVE_FCNTL_H 1
26+
27+
/* Define to 1 if you have the `gethostbyname' function. */
28+
#define HAVE_GETHOSTBYNAME 1
29+
30+
/* Define to 1 if you have the `gettimeofday' function. */
31+
#define HAVE_GETTIMEOFDAY 1
32+
33+
/* Define to 1 if you have the `inet_ntoa' function. */
34+
#define HAVE_INET_NTOA 1
35+
36+
/* Define to 1 if you have the <inttypes.h> header file. */
37+
#define HAVE_INTTYPES_H 1
38+
39+
/* Define to 1 if you have the <limits.h> header file. */
40+
#define HAVE_LIMITS_H 1
41+
42+
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and to 0 otherwise. */
43+
#define HAVE_MALLOC 1
44+
45+
/* Define to 1 if you have the `memmove' function. */
46+
#define HAVE_MEMMOVE 1
47+
48+
/* Define to 1 if you have the <memory.h> header file. */
49+
#define HAVE_MEMORY_H 1
50+
51+
/* Define to 1 if you have the `memset' function. */
52+
#define HAVE_MEMSET 1
53+
54+
/* Define to 1 if you have the `mkdir' function. */
55+
#define HAVE_MKDIR 1
56+
57+
/* Define to 1 if you have the <netdb.h> header file. */
58+
#define HAVE_NETDB_H 1
59+
60+
/* Define to 1 if you have the <netinet/in.h> header file. */
61+
#define HAVE_NETINET_IN_H 1
62+
63+
/* Define to 1 if you have the <poll.h> header file. */
64+
#define HAVE_POLL_H 1
65+
66+
/* Define to 1 if you have the <pthread.h> header file. */
67+
#define HAVE_PTHREAD_H 1
68+
69+
/* Define to 1 if the system has the type `ptrdiff_t'. */
70+
#define HAVE_PTRDIFF_T 1
71+
72+
/* Define to 1 if your system has a GNU libc compatible `realloc' function, and to 0 otherwise. */
73+
#define HAVE_REALLOC 1
74+
75+
/* Define to 1 if you have the <sched.h> header file. */
76+
#define HAVE_SCHED_H 1
77+
78+
/* Define to 1 if you have the `select' function. */
79+
#define HAVE_SELECT 1
80+
81+
/* Define to 1 if you have the `socket' function. */
82+
#define HAVE_SOCKET 1
83+
84+
/* Define to 1 if stdbool.h conforms to C99. */
85+
#define HAVE_STDBOOL_H 1
86+
87+
/* Define to 1 if you have the <stddef.h> header file. */
88+
#define HAVE_STDDEF_H 1
89+
90+
/* Define to 1 if you have the <stdint.h> header file. */
91+
#define HAVE_STDINT_H 1
92+
93+
/* Define to 1 if you have the <stdlib.h> header file. */
94+
#define HAVE_STDLIB_H 1
95+
96+
/* Define to 1 if you have the `strchr' function. */
97+
#define HAVE_STRCHR 1
98+
99+
/* Define to 1 if you have the `strdup' function. */
100+
#define HAVE_STRDUP 1
101+
102+
/* Define to 1 if you have the `strerror' function. */
103+
#define HAVE_STRERROR 1
104+
105+
/* Define to 1 if you have the `strerror_r' function. */
106+
#define HAVE_STRERROR_R 1
107+
108+
/* Define to 1 if you have the `strftime' function. */
109+
#define HAVE_STRFTIME 1
110+
111+
/* Define to 1 if you have the <strings.h> header file. */
112+
#define HAVE_STRINGS_H 1
113+
114+
/* Define to 1 if you have the <string.h> header file. */
115+
#define HAVE_STRING_H 1
116+
117+
/* Define to 1 if you have the `strstr' function. */
118+
#define HAVE_STRSTR 1
119+
120+
/* Define to 1 if you have the `strtol' function. */
121+
#define HAVE_STRTOL 1
122+
123+
/* Define to 1 if you have the `strtoul' function. */
124+
#define HAVE_STRTOUL 1
125+
126+
/* Define to 1 if you have the <sys/ioctl.h> header file. */
127+
#define HAVE_SYS_IOCTL_H 1
128+
129+
/* Define to 1 if you have the <sys/resource.h> header file. */
130+
#define HAVE_SYS_RESOURCE_H 1
131+
132+
/* Define to 1 if you have the <sys/select.h> header file. */
133+
#define HAVE_SYS_SELECT_H 1
134+
135+
/* Define to 1 if you have the <sys/socket.h> header file. */
136+
#define HAVE_SYS_SOCKET_H 1
137+
138+
/* Define to 1 if you have the <sys/stat.h> header file. */
139+
#define HAVE_SYS_STAT_H 1
140+
141+
/* Define to 1 if you have the <sys/time.h> header file. */
142+
#define HAVE_SYS_TIME_H 1
143+
144+
/* Define to 1 if you have the <sys/types.h> header file. */
145+
#define HAVE_SYS_TYPES_H 1
146+
147+
/* Define to 1 if you have the <unistd.h> header file. */
148+
#define HAVE_UNISTD_H 1
149+
150+
/* Define to 1 if you have the `vprintf' function. */
151+
#define HAVE_VPRINTF 1
152+
153+
/* define if zlib is available */
154+
/* #undef HAVE_ZLIB */
155+
156+
/* Possible value for SIGNED_RIGHT_SHIFT_IS */
157+
#define LOGICAL_RIGHT_SHIFT 2
158+
159+
/* Define as the return type of signal handlers (`int' or `void'). */
160+
#define RETSIGTYPE void
161+
162+
/* Define to the type of arg 1 for `select'. */
163+
#define SELECT_TYPE_ARG1 int
164+
165+
/* Define to the type of args 2, 3 and 4 for `select'. */
166+
#define SELECT_TYPE_ARG234 (fd_set *)
167+
168+
/* Define to the type of arg 5 for `select'. */
169+
#define SELECT_TYPE_ARG5 (struct timeval *)
170+
171+
/* Indicates the effect of the right shift operator on negative signed integers */
172+
#define SIGNED_RIGHT_SHIFT_IS 1
173+
174+
/* Define to 1 if you have the ANSI C header files. */
175+
#define STDC_HEADERS 1
176+
177+
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
178+
#define TIME_WITH_SYS_TIME 1
179+
180+
/* Possible value for SIGNED_RIGHT_SHIFT_IS */
181+
#define UNKNOWN_RIGHT_SHIFT 3
182+
183+
#endif /* ZEPHYR_MODULES_THRIFT_SRC_THRIFT_CONFIG_H_ */

0 commit comments

Comments
 (0)