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