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] Build thrift library with cmake. #5427

Merged
merged 16 commits into from
Sep 5, 2022
Merged
60 changes: 60 additions & 0 deletions T/Thrift/build_tarballs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Note that this script can accept some limited command-line arguments, run
# `julia build_tarballs.jl --help` to see a usage message.
using BinaryBuilder, Pkg

name = "Thrift"
version = v"0.16.0"

# Collection of sources required to complete build
sources = [
GitSource("https://github.com/apache/thrift.git", "2a93df80f27739ccabb5b885cb12a8dc7595ecdf")
DirectorySource("./bundled")
]

# Bash recipe for building across all platforms
script = raw"""
cd $WORKSPACE/srcdir/thrift

# Needed as https://github.com/apache/thrift/pull/2518 isn't released yet
for f in ${WORKSPACE}/srcdir/patches/*.patch; do
atomic_patch -p1 ${f}
done

mkdir build_dir && cd build_dir

CMAKE_FLAGS=(-DCMAKE_INSTALL_PREFIX=$prefix
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN}
-DCMAKE_BUILD_TYPE=Release
-DBUILD_COMPILER=ON
-DBUILD_CPP=ON
-DBUILD_PYTHON=OFF
-DBUILD_TESTING=OFF
-DBUILD_JAVASCRIPT=OFF
-DBUILD_NODEJS=OFF
-DWITH_SHARED_LIB=ON
-DBUILD_TUTORIALS=OFF
-DTHRIFT_COMPILER_DELPHI=OFF)

cmake .. "${CMAKE_FLAGS[@]}"

make -j${nproc}
make install
"""

# These are the platforms we will build for by default, unless further
# platforms are passed in on the command line
platforms = expand_cxxstring_abis(supported_platforms())

# The products that we will ensure are always built
products = [
ExecutableProduct("thrift", :thrift)
LibraryProduct("libthrift", :libthrift)
]

# Dependencies that must be installed before this package can be built
dependencies = [
Dependency("boost_jll", compat="=1.76.0")
]

# Build the tarballs, and possibly a `build.jl` as well.
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies; julia_compat="1.6")
15 changes: 15 additions & 0 deletions T/Thrift/bundled/patches/freebsd.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/lib/cpp/src/thrift/transport/TSocket.cpp b/lib/cpp/src/thrift/transport/TSocket.cpp
index 9991fd6bd..e46daeba8 100644
--- a/lib/cpp/src/thrift/transport/TSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TSocket.cpp
@@ -432,6 +432,10 @@ void TSocket::local_open() {
TWinsockSingleton::create();
#endif // _WIN32

+#if __FreeBSD__
+ #define EAI_NODATA EAI_NONAME
+#endif // __FreeBSD__
+
Comment on lines +9 to +12
Copy link
Member

@giordano giordano Sep 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very convinced by this patch. How did you come up with that? EAI_NODATA is in netdb.h on FreeBSD with value 7, EAI_NONAME has value 8 (but EAI_NODATA is inside an #if 0):

% julia --compile=min -e 'using BinaryBuilderBase; BinaryBuilderBase.runshell(Platform("x86_64", "freebsd"))'
sandbox:${WORKSPACE} # grep -B2 -A2 -r '\<EAI_NODATA\>' /opt/${target}/${target}/sys-root/include/
/opt/x86_64-unknown-freebsd12.2/x86_64-unknown-freebsd12.2/sys-root/include/netdb.h-#if 0
/opt/x86_64-unknown-freebsd12.2/x86_64-unknown-freebsd12.2/sys-root/include/netdb.h-/* Obsoleted on RFC 2553bis-02 */
/opt/x86_64-unknown-freebsd12.2/x86_64-unknown-freebsd12.2/sys-root/include/netdb.h:#define     EAI_NODATA       7      /* no address associated with hostname */
/opt/x86_64-unknown-freebsd12.2/x86_64-unknown-freebsd12.2/sys-root/include/netdb.h-#endif
/opt/x86_64-unknown-freebsd12.2/x86_64-unknown-freebsd12.2/sys-root/include/netdb.h-#define     EAI_NONAME       8      /* name does not resolve */
--
/opt/x86_64-unknown-freebsd12.2/x86_64-unknown-freebsd12.2/sys-root/include/roken-common.h-#define EAI_FAMILY   5       /* ai_family not supported */
/opt/x86_64-unknown-freebsd12.2/x86_64-unknown-freebsd12.2/sys-root/include/roken-common.h-#define EAI_MEMORY   6       /* memory allocation failure */
/opt/x86_64-unknown-freebsd12.2/x86_64-unknown-freebsd12.2/sys-root/include/roken-common.h:#define EAI_NODATA   7       /* no address associated with nodename */
/opt/x86_64-unknown-freebsd12.2/x86_64-unknown-freebsd12.2/sys-root/include/roken-common.h-#define EAI_NONAME   8       /* nodename nor servname provided, or not known */
/opt/x86_64-unknown-freebsd12.2/x86_64-unknown-freebsd12.2/sys-root/include/roken-common.h-#define EAI_SERVICE  9       /* servname not supported for ai_socktype */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a C++ programmer so I could be wrong here. I got the following error on freebsd

[12:12:24] /workspace/srcdir/thrift/lib/cpp/src/thrift/transport/TSocket.cpp:461:16: error: use of undeclared identifier 'EAI_NODATA'
[12:12:24]       error == EAI_NODATA
[12:12:24]                ^
[12:12:24] 1 error generated.

in a previous build.

There are many hits when you google this, but essentially FreeBSD obsoleted it in an RFC, as it states in your netdb.h example. Similarly, the manual doesn't mention it anymore: https://www.freebsd.org/cgi/man.cgi?query=gai_strerror&sektion=3&apropos=0&manpath=FreeBSD+7.1-RELEASE and the mailing list states that:

Now, getaddrinfo(3) returns EAI_NONAME instead of
EAI_NODATA.

Eventlet patched this in a similar way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, if FreeBSD devs tell to use EAI_NONAME instead of EAI_NODATA then this is good I guess.

if (isOpen()) {
return;
}
184 changes: 184 additions & 0 deletions T/Thrift/bundled/patches/include_case_sensitive.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
diff --git a/compiler/cpp/tests/catch/catch.hpp b/compiler/cpp/tests/catch/catch.hpp
index 33d037e55..1744c742d 100644
--- a/compiler/cpp/tests/catch/catch.hpp
+++ b/compiler/cpp/tests/catch/catch.hpp
@@ -6338,7 +6338,7 @@ namespace Catch {
#endif

#ifdef __AFXDLL
-#include <AfxWin.h>
+#include <afxwin.h>
#else
#include <windows.h>
#endif
diff --git a/lib/cpp/src/thrift/protocol/TProtocol.h b/lib/cpp/src/thrift/protocol/TProtocol.h
index 867ceb079..b691c4169 100644
--- a/lib/cpp/src/thrift/protocol/TProtocol.h
+++ b/lib/cpp/src/thrift/protocol/TProtocol.h
@@ -22,7 +22,7 @@

#ifdef _WIN32
// Need to come before any Windows.h includes
-#include <Winsock2.h>
+#include <winsock2.h>
#endif

#include <thrift/transport/TTransport.h>
diff --git a/lib/cpp/src/thrift/transport/THttpServer.cpp b/lib/cpp/src/thrift/transport/THttpServer.cpp
index 91a1c39af..6fc281674 100644
--- a/lib/cpp/src/thrift/transport/THttpServer.cpp
+++ b/lib/cpp/src/thrift/transport/THttpServer.cpp
@@ -25,7 +25,7 @@
#include <thrift/transport/THttpServer.h>
#include <thrift/transport/TSocket.h>
#if defined(_MSC_VER) || defined(__MINGW32__)
- #include <Shlwapi.h>
+ #include <shlwapi.h>
#endif

using std::string;
diff --git a/lib/cpp/src/thrift/transport/TPipeServer.cpp b/lib/cpp/src/thrift/transport/TPipeServer.cpp
index e4234b180..fd1aeee95 100644
--- a/lib/cpp/src/thrift/transport/TPipeServer.cpp
+++ b/lib/cpp/src/thrift/transport/TPipeServer.cpp
@@ -27,8 +27,8 @@
#ifdef _WIN32
#include <thrift/windows/OverlappedSubmissionThread.h>
#include <thrift/windows/Sync.h>
-#include <AccCtrl.h>
-#include <Aclapi.h>
+#include <accctrl.h>
+#include <aclapi.h>
#include <sddl.h>
#endif //_WIN32

diff --git a/lib/cpp/src/thrift/transport/TServerSocket.cpp b/lib/cpp/src/thrift/transport/TServerSocket.cpp
index 25ec789e0..8dda1072b 100644
--- a/lib/cpp/src/thrift/transport/TServerSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TServerSocket.cpp
@@ -70,7 +70,7 @@
// adds problematic macros like min() and max(). Try to work around:
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
-#include <Windows.h>
+#include <windows.h>
#undef NOMINMAX
#undef WIN32_LEAN_AND_MEAN
#endif
diff --git a/lib/cpp/src/thrift/transport/TWebSocketServer.h b/lib/cpp/src/thrift/transport/TWebSocketServer.h
index 7f39f36b9..2a3e076cf 100644
--- a/lib/cpp/src/thrift/transport/TWebSocketServer.h
+++ b/lib/cpp/src/thrift/transport/TWebSocketServer.h
@@ -31,7 +31,7 @@
#include <thrift/transport/TSocket.h>
#include <thrift/transport/THttpServer.h>
#if defined(_MSC_VER) || defined(__MINGW32__)
-#include <Shlwapi.h>
+#include <shlwapi.h>
#define THRIFT_strncasecmp(str1, str2, len) _strnicmp(str1, str2, len)
#define THRIFT_strcasestr(haystack, needle) StrStrIA(haystack, needle)
#else
diff --git a/lib/cpp/src/thrift/windows/GetTimeOfDay.cpp b/lib/cpp/src/thrift/windows/GetTimeOfDay.cpp
index ac24124b3..d3696053b 100644
--- a/lib/cpp/src/thrift/windows/GetTimeOfDay.cpp
+++ b/lib/cpp/src/thrift/windows/GetTimeOfDay.cpp
@@ -38,7 +38,7 @@ int thrift_gettimeofday(struct timeval* tv, struct timezone* tz) {
}
#else
#define WIN32_LEAN_AND_MEAN
-#include <Winsock2.h>
+#include <winsock2.h>
#include <cstdint>
#include <sstream>
#include <thrift/transport/TTransportException.h>
diff --git a/lib/cpp/src/thrift/windows/SocketPair.cpp b/lib/cpp/src/thrift/windows/SocketPair.cpp
index 2650b37d4..9271b0294 100644
--- a/lib/cpp/src/thrift/windows/SocketPair.cpp
+++ b/lib/cpp/src/thrift/windows/SocketPair.cpp
@@ -34,7 +34,7 @@
#include <string.h>

// Win32
-#include <WS2tcpip.h>
+#include <ws2tcpip.h>

int thrift_socketpair(int d, int type, int protocol, THRIFT_SOCKET sv[2]) {
THRIFT_UNUSED_VARIABLE(protocol);
diff --git a/lib/cpp/src/thrift/windows/SocketPair.h b/lib/cpp/src/thrift/windows/SocketPair.h
index 86bf43150..74b65dfaa 100644
--- a/lib/cpp/src/thrift/windows/SocketPair.h
+++ b/lib/cpp/src/thrift/windows/SocketPair.h
@@ -29,7 +29,7 @@
#endif

// Win32
-#include <Winsock2.h>
+#include <winsock2.h>
#include <thrift/thrift-config.h>

int thrift_socketpair(int d, int type, int protocol, THRIFT_SOCKET sv[2]);
diff --git a/lib/cpp/src/thrift/windows/Sync.h b/lib/cpp/src/thrift/windows/Sync.h
index f5b8a052d..df93e7436 100644
--- a/lib/cpp/src/thrift/windows/Sync.h
+++ b/lib/cpp/src/thrift/windows/Sync.h
@@ -31,7 +31,7 @@
// adds problematic macros like min() and max(). Try to work around:
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
-#include <Windows.h>
+#include <windows.h>
#undef NOMINMAX
#undef WIN32_LEAN_AND_MEAN

diff --git a/lib/cpp/src/thrift/windows/WinFcntl.h b/lib/cpp/src/thrift/windows/WinFcntl.h
index 4816fc5ec..39e5efd13 100644
--- a/lib/cpp/src/thrift/windows/WinFcntl.h
+++ b/lib/cpp/src/thrift/windows/WinFcntl.h
@@ -33,7 +33,7 @@
#endif

// Win32
-#include <Winsock2.h>
+#include <winsock2.h>
#include <thrift/transport/PlatformSocket.h>

extern "C" {
diff --git a/lib/cpp/src/thrift/windows/config.h b/lib/cpp/src/thrift/windows/config.h
index ce10c5524..19296d63f 100644
--- a/lib/cpp/src/thrift/windows/config.h
+++ b/lib/cpp/src/thrift/windows/config.h
@@ -57,7 +57,7 @@
#include <thrift/windows/SocketPair.h>

// windows
-#include <Winsock2.h>
+#include <winsock2.h>
#include <ws2tcpip.h>

#ifndef __MINGW32__
diff --git a/lib/cpp/test/OpenSSLManualInitTest.cpp b/lib/cpp/test/OpenSSLManualInitTest.cpp
index 935a20514..bf6c15369 100644
--- a/lib/cpp/test/OpenSSLManualInitTest.cpp
+++ b/lib/cpp/test/OpenSSLManualInitTest.cpp
@@ -21,7 +21,7 @@
// which will cause the test to fail
#define MANUAL_OPENSSL_INIT 1
#ifdef _WIN32
-#include <WinSock2.h>
+#include <winsock2.h>
#endif

#include <boost/test/unit_test.hpp>
diff --git a/lib/py/src/ext/endian.h b/lib/py/src/ext/endian.h
index 1660cbd98..a2cf594ed 100644
--- a/lib/py/src/ext/endian.h
+++ b/lib/py/src/ext/endian.h
@@ -25,7 +25,7 @@
#ifndef _WIN32
#include <netinet/in.h>
#else
-#include <WinSock2.h>
+#include <winsock2.h>
#pragma comment(lib, "ws2_32.lib")
#define BIG_ENDIAN (4321)
#define LITTLE_ENDIAN (1234)