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