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