1{ lib
2, stdenv
3, fetchurl
4, fetchpatch
5, boost
6, zlib
7, libevent
8, openssl
9, python3
10, cmake
11, pkg-config
12, bison
13, flex
14, static ? stdenv.hostPlatform.isStatic
15}:
16
17stdenv.mkDerivation rec {
18 pname = "thrift";
19 version = "0.18.1";
20
21 src = fetchurl {
22 url = "https://archive.apache.org/dist/thrift/${version}/${pname}-${version}.tar.gz";
23 hash = "sha256-BMbxDl14jKeOE+4u8NIVLHsHDAr1VIPWuULinP8pZyY=";
24 };
25
26 # Workaround to make the Python wrapper not drop this package:
27 # pythonFull.buildEnv.override { extraLibs = [ thrift ]; }
28 pythonPath = [];
29
30 nativeBuildInputs = [
31 bison
32 cmake
33 flex
34 pkg-config
35 ];
36
37 buildInputs = [
38 boost
39 ] ++ lib.optionals (!static) [
40 (python3.withPackages (ps: [ps.twisted]))
41 ];
42
43 propagatedBuildInputs = [
44 libevent
45 openssl
46 zlib
47 ];
48
49 postPatch = ''
50 # Python 3.10 related failures:
51 # SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
52 # AttributeError: module 'collections' has no attribute 'Hashable'
53 substituteInPlace test/py/RunClientServer.py \
54 --replace "'FastbinaryTest.py'," "" \
55 --replace "'TestEof.py'," "" \
56 --replace "'TestFrozen.py'," ""
57 '';
58
59 preConfigure = ''
60 export PY_PREFIX=$out
61 '';
62
63 patches = [
64 # ToStringTest.cpp is failing from some reason due to locale issue, this
65 # doesn't disable all UnitTests as in Darwin.
66 ./disable-failing-test.patch
67 (fetchpatch {
68 name = "setuptools-gte-62.1.0.patch"; # https://github.com/apache/thrift/pull/2635
69 url = "https://github.com/apache/thrift/commit/c41ad9d5119e9bdae1746167e77e224f390f2c42.diff";
70 hash = "sha256-FkErrg/6vXTomS4AsCsld7t+Iccc55ZiDaNjJ3W1km0=";
71 })
72 (fetchpatch {
73 name = "thrift-install-FindLibevent.patch"; # https://github.com/apache/thrift/pull/2726
74 url = "https://github.com/apache/thrift/commit/2ab850824f75d448f2ba14a468fb77d2594998df.diff";
75 hash = "sha256-ejMKFG/cJgoPlAFzVDPI4vIIL7URqaG06/IWdQ2NkhY=";
76 })
77 (fetchpatch {
78 name = "thrift-fix-tests-OpenSSL3.patch"; # https://github.com/apache/thrift/pull/2760
79 url = "https://github.com/apache/thrift/commit/eae3ac418f36c73833746bcd53e69ed8a12f0e1a.diff";
80 hash = "sha256-0jlN4fo94cfGFUKcLFQgVMI/x7uxn5OiLiFk6txVPzs=";
81 })
82 ];
83
84 cmakeFlags = [
85 "-DBUILD_JAVASCRIPT:BOOL=OFF"
86 "-DBUILD_NODEJS:BOOL=OFF"
87
88 # FIXME: Fails to link in static mode with undefined reference to
89 # `boost::unit_test::unit_test_main(bool (*)(), int, char**)'
90 "-DBUILD_TESTING:BOOL=${if static then "OFF" else "ON"}"
91 ] ++ lib.optionals static [
92 "-DWITH_STATIC_LIB:BOOL=ON"
93 "-DOPENSSL_USE_STATIC_LIBS=ON"
94 ];
95
96 disabledTests = [
97 "PythonTestSSLSocket"
98 "PythonThriftTNonblockingServer"
99 ] ++ lib.optionals stdenv.isDarwin [
100 # Tests that hang up in the Darwin sandbox
101 "SecurityTest"
102 "SecurityFromBufferTest"
103 "python_test"
104
105 # fails on hydra, passes locally
106 "concurrency_test"
107
108 # Tests that fail in the Darwin sandbox when trying to use network
109 "UnitTests"
110 "TInterruptTest"
111 "TServerIntegrationTest"
112 "processor"
113 "TNonblockingServerTest"
114 "TNonblockingSSLServerTest"
115 "StressTest"
116 "StressTestConcurrent"
117 "StressTestNonBlocking"
118 ];
119
120 doCheck = !static;
121
122 checkPhase = ''
123 runHook preCheck
124
125 ${lib.optionalString stdenv.isDarwin "DY"}LD_LIBRARY_PATH=$PWD/lib ctest -E "($(echo "$disabledTests" | tr " " "|"))"
126
127 runHook postCheck
128 '';
129
130 enableParallelChecking = false;
131
132 meta = with lib; {
133 description = "Library for scalable cross-language services";
134 homepage = "https://thrift.apache.org/";
135 license = licenses.asl20;
136 platforms = platforms.linux ++ platforms.darwin;
137 maintainers = with maintainers; [ bjornfor ];
138 };
139}