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