Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 cmake,
6 curl,
7 openssl,
8 zlib,
9 aws-crt-cpp,
10 nix,
11 arrow-cpp,
12 aws-sdk-cpp,
13 # Allow building a limited set of APIs, e.g. ["s3" "ec2"].
14 apis ? [ "*" ],
15 # Whether to enable AWS' custom memory management.
16 customMemoryManagement ? true,
17}:
18
19let
20 host_os =
21 if stdenv.hostPlatform.isDarwin then
22 "APPLE"
23 else if stdenv.hostPlatform.isAndroid then
24 "ANDROID"
25 else if stdenv.hostPlatform.isWindows then
26 "WINDOWS"
27 else if stdenv.hostPlatform.isLinux then
28 "LINUX"
29 else
30 throw "Unknown host OS";
31in
32
33stdenv.mkDerivation rec {
34 pname = "aws-sdk-cpp";
35 # nixpkgs-update: no auto update
36 version = "1.11.612";
37
38 src = fetchFromGitHub {
39 owner = "aws";
40 repo = "aws-sdk-cpp";
41 rev = version;
42 hash = "sha256-W4eKgUvN2NLYEOO47HTJYJpEmyn10gNK29RIrvoXkek=";
43 };
44
45 postPatch = ''
46 # Append the dev output to path hints in finding Aws.h to avoid
47 # having to pass `AWS_CORE_HEADER_FILE` explicitly to cmake configure
48 # when using find_package(AWSSDK CONFIG)
49 substituteInPlace cmake/AWSSDKConfig.cmake \
50 --replace 'C:/AWSSDK/''${AWSSDK_INSTALL_INCLUDEDIR}/aws/core' \
51 'C:/AWSSDK/''${AWSSDK_INSTALL_INCLUDEDIR}/aws/core"
52 "${placeholder "dev"}/include/aws/core'
53
54 # Avoid blanket -Werror to evade build failures on less
55 # tested compilers.
56 substituteInPlace cmake/compiler_settings.cmake \
57 --replace '"-Werror"' ' '
58
59 # Flaky on Hydra
60 rm tests/aws-cpp-sdk-core-tests/aws/auth/AWSCredentialsProviderTest.cpp
61 rm tests/aws-cpp-sdk-core-tests/aws/client/AWSClientTest.cpp
62 rm tests/aws-cpp-sdk-core-tests/aws/client/AwsConfigTest.cpp
63 # Includes aws-c-auth private headers, so only works with submodule build
64 rm tests/aws-cpp-sdk-core-tests/aws/auth/AWSAuthSignerTest.cpp
65 # TestRandomURLMultiThreaded fails
66 rm tests/aws-cpp-sdk-core-tests/http/HttpClientTest.cpp
67 ''
68 + lib.optionalString stdenv.hostPlatform.isi686 ''
69 # EPSILON is exceeded
70 rm tests/aws-cpp-sdk-core-tests/aws/client/AdaptiveRetryStrategyTest.cpp
71 '';
72
73 # FIXME: might be nice to put different APIs in different outputs
74 # (e.g. libaws-cpp-sdk-s3.so in output "s3").
75 outputs = [
76 "out"
77 "dev"
78 ];
79
80 nativeBuildInputs = [
81 cmake
82 curl
83 ];
84
85 buildInputs = [
86 curl
87 openssl
88 zlib
89 ];
90
91 # propagation is needed for Security.framework to be available when linking
92 propagatedBuildInputs = [ aws-crt-cpp ];
93
94 cmakeFlags = [
95 "-DBUILD_DEPS=OFF"
96 ]
97 ++ lib.optional (!customMemoryManagement) "-DCUSTOM_MEMORY_MANAGEMENT=0"
98 ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
99 "-DENABLE_TESTING=OFF"
100 "-DCURL_HAS_H2=1"
101 "-DCURL_HAS_TLS_PROXY=1"
102 "-DTARGET_ARCH=${host_os}"
103 ]
104 ++ lib.optional (apis != [ "*" ]) "-DBUILD_ONLY=${lib.concatStringsSep ";" apis}";
105
106 env.NIX_CFLAGS_COMPILE = toString [
107 # openssl 3 generates several deprecation warnings
108 "-Wno-error=deprecated-declarations"
109 ];
110
111 postFixupHooks = [
112 # This bodge is necessary so that the file that the generated -config.cmake file
113 # points to an existing directory.
114 "mkdir -p $out/include"
115 ];
116
117 __darwinAllowLocalNetworking = true;
118
119 # Builds in 2+h with 2 cores, and ~10m with a big-parallel builder.
120 requiredSystemFeatures = [ "big-parallel" ];
121
122 passthru = {
123 tests = {
124 inherit nix arrow-cpp;
125 cmake-find-package = stdenv.mkDerivation {
126 pname = "aws-sdk-cpp-cmake-find-package-test";
127 version = "0";
128 dontUnpack = true;
129 nativeBuildInputs = [ cmake ];
130 buildInputs = [ aws-sdk-cpp ];
131 buildCommand = ''
132 cat > CMakeLists.txt <<'EOF'
133 find_package(AWSSDK)
134 EOF
135
136 # Intentionally not using 'cmakeConfigurePhase' to test that find_package works without it.
137 mkdir build && cd build
138 if output=$(cmake -Wno-dev .. 2>&1); then
139 if grep -Fw -- "Found AWS" - <<< "$output"; then
140 touch "$out"
141 else
142 echo "'Found AWS' not found in the cmake output!" >&2
143 echo "The output was:" >&2
144 echo "$output" >&2
145 exit 1
146 fi
147 else
148 echo -n "'cmake -Wno-dev ..'" >&2
149 echo " returned a non-zero exit code." >&2
150 echo "$output" >&2
151 exit 1
152 fi
153 '';
154 };
155 };
156 };
157
158 meta = with lib; {
159 description = "C++ interface for Amazon Web Services";
160 homepage = "https://github.com/aws/aws-sdk-cpp";
161 license = licenses.asl20;
162 platforms = platforms.unix;
163 maintainers = with maintainers; [ orivej ];
164 # building ec2 runs out of memory: cc1plus: out of memory allocating 33554372 bytes after a total of 74424320 bytes
165 broken = stdenv.buildPlatform.is32bit && ((builtins.elem "ec2" apis) || (builtins.elem "*" apis));
166 };
167}