Skip to content

Commit

Permalink
[Thrift] Build thrift library with cmake. (#5427)
Browse files Browse the repository at this point in the history
* Build thrift library with cmake.

* Add Thrift as new package.

* Revert ThriftJuliaCompiler.

* Name package Thrift.

* Build dir outside of src dir.

* Apply patch for Windows.

* Disable tutorials and add another patch.

* Also lowercase <windows.h>.

* Patch FreeBSD and fix patches.

* Build under src dir.

* More case-sensitive fixes.

* Another patch update...

* More case-sensitive fixes.

* Fix double patch. Exclude Delphi compiler, it uses unsupported codecvt on win-cxx03.

* Update T/Thrift/build_tarballs.jl

Co-authored-by: Mosè Giordano <[email protected]>

Co-authored-by: Mosè Giordano <[email protected]>
  • Loading branch information
evetion and giordano authored Sep 5, 2022
1 parent ee1024f commit c02cb5c
Show file tree
Hide file tree
Showing 3 changed files with 259 additions and 0 deletions.
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__
+
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)

0 comments on commit c02cb5c

Please sign in to comment.