1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 fetchpatch,
7 cython_0,
8 certifi,
9 CFNetwork,
10 cmake,
11 CoreFoundation,
12 openssl,
13 Security,
14 pytestCheckHook,
15 pytest-asyncio,
16}:
17
18buildPythonPackage rec {
19 pname = "uamqp";
20 version = "1.6.8";
21 format = "setuptools";
22
23 src = fetchFromGitHub {
24 owner = "Azure";
25 repo = "azure-uamqp-python";
26 rev = "refs/tags/v${version}";
27 hash = "sha256-L4E7nnsVZ/VrOM0t4KtztU9ALmtGfi1vDzUi0ogtZOc=";
28 };
29
30 patches =
31 lib.optionals (stdenv.isDarwin && stdenv.isx86_64) [
32 ./darwin-azure-c-shared-utility-corefoundation.patch
33 ]
34 ++ [
35 (fetchpatch {
36 name = "CVE-2024-25110.patch";
37 url = "https://github.com/Azure/azure-uamqp-c/commit/30865c9ccedaa32ddb036e87a8ebb52c3f18f695.patch";
38 stripLen = 1;
39 extraPrefix = "src/vendor/azure-uamqp-c/";
40 hash = "sha256-igzZqTLUUyuNcpCUbYHI4RXmWxg+7EC/yyD4DBurR2M=";
41 })
42 (fetchpatch {
43 name = "CVE-2024-27099.patch";
44 url = "https://github.com/Azure/azure-uamqp-c/commit/2ca42b6e4e098af2d17e487814a91d05f6ae4987.patch";
45 stripLen = 1;
46 extraPrefix = "src/vendor/azure-uamqp-c/";
47 # other files are just tests which aren't run from the python
48 # builder anyway
49 includes = [ "src/vendor/azure-uamqp-c/src/link.c" ];
50 hash = "sha256-EqDfG1xAz5CG8MssSSrz8Yrje5qwF8ri1Kdw+UUu5ms=";
51 })
52 # Fix incompatible function pointer conversion error with clang 16.
53 ./clang-fix-incompatible-function-pointer-conversion.patch
54 ];
55
56 postPatch = lib.optionalString (stdenv.isDarwin && !stdenv.isx86_64) ''
57 # force darwin aarch64 to use openssl instead of applessl, removing
58 # some quirks upstream thinks they need to use openssl on macos
59 sed -i \
60 -e '/^use_openssl =/cuse_openssl = True' \
61 -e 's/\bazssl\b/ssl/' \
62 -e 's/\bazcrypto\b/crypto/' \
63 setup.py
64 sed -i \
65 -e '/#define EVP_PKEY_id/d' \
66 src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/x509_openssl.c
67 sed -z -i \
68 -e 's/OpenSSL 3\nif(LINUX)/OpenSSL 3\nif(1)/' \
69 src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/CMakeLists.txt
70 '';
71
72 nativeBuildInputs = [
73 cmake
74 cython_0
75 ];
76
77 buildInputs =
78 [ openssl ]
79 ++ lib.optionals stdenv.isDarwin [
80 CoreFoundation
81 CFNetwork
82 Security
83 ];
84
85 propagatedBuildInputs = [ certifi ];
86
87 dontUseCmakeConfigure = true;
88
89 preCheck = ''
90 # remove src module, so tests use the installed module instead
91 rm -r uamqp
92 '';
93
94 nativeCheckInputs = [
95 pytestCheckHook
96 pytest-asyncio
97 ];
98
99 pythonImportsCheck = [ "uamqp" ];
100
101 meta = with lib; {
102 description = "An AMQP 1.0 client library for Python";
103 homepage = "https://github.com/Azure/azure-uamqp-python";
104 license = licenses.mit;
105 maintainers = with maintainers; [ maxwilson ];
106 };
107}