1{ lib
2, stdenv
3, fetchFromGitHub
4, cmake
5, curl
6, openssl
7, zlib
8, aws-crt-cpp
9, CoreAudio
10, AudioToolbox
11, # Allow building a limited set of APIs, e.g. ["s3" "ec2"].
12 apis ? ["*"]
13, # Whether to enable AWS' custom memory management.
14 customMemoryManagement ? true
15}:
16
17let
18 host_os = if stdenv.hostPlatform.isDarwin then "APPLE"
19 else if stdenv.hostPlatform.isAndroid then "ANDROID"
20 else if stdenv.hostPlatform.isWindows then "WINDOWS"
21 else if stdenv.hostPlatform.isLinux then "LINUX"
22 else throw "Unknown host OS";
23in
24
25stdenv.mkDerivation rec {
26 pname = "aws-sdk-cpp";
27 version = "1.11.37";
28
29 src = fetchFromGitHub {
30 owner = "aws";
31 repo = "aws-sdk-cpp";
32 rev = version;
33 sha256 = "sha256-C1PdLNagoIMk9/AAV2Pp7kWcspasJtN9Tx679FnEprc=";
34 };
35
36 patches = [
37 ./cmake-dirs.patch
38 ];
39
40 postPatch = ''
41 # Avoid blanket -Werror to evade build failures on less
42 # tested compilers.
43 substituteInPlace cmake/compiler_settings.cmake \
44 --replace '"-Werror"' ' '
45
46 # Flaky on Hydra
47 rm tests/aws-cpp-sdk-core-tests/aws/auth/AWSCredentialsProviderTest.cpp
48 # Includes aws-c-auth private headers, so only works with submodule build
49 rm tests/aws-cpp-sdk-core-tests/aws/auth/AWSAuthSignerTest.cpp
50 # TestRandomURLMultiThreaded fails
51 rm tests/aws-cpp-sdk-core-tests/http/HttpClientTest.cpp
52 '' + lib.optionalString stdenv.isi686 ''
53 # EPSILON is exceeded
54 rm tests/aws-cpp-sdk-core-tests/aws/client/AdaptiveRetryStrategyTest.cpp
55 '';
56
57 # FIXME: might be nice to put different APIs in different outputs
58 # (e.g. libaws-cpp-sdk-s3.so in output "s3").
59 outputs = [ "out" "dev" ];
60
61 nativeBuildInputs = [ cmake curl ];
62
63 buildInputs = [
64 curl openssl zlib
65 ] ++ lib.optionals (stdenv.isDarwin &&
66 ((builtins.elem "text-to-speech" apis) ||
67 (builtins.elem "*" apis)))
68 [ CoreAudio AudioToolbox ];
69
70 # propagation is needed for Security.framework to be available when linking
71 propagatedBuildInputs = [ aws-crt-cpp ];
72 # Ensure the linker is using atomic when compiling for RISC-V, otherwise fails
73 LDFLAGS = lib.optionalString stdenv.hostPlatform.isRiscV "-latomic";
74
75 cmakeFlags = [
76 "-DBUILD_DEPS=OFF"
77 ] ++ lib.optional (!customMemoryManagement) "-DCUSTOM_MEMORY_MANAGEMENT=0"
78 ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
79 "-DENABLE_TESTING=OFF"
80 "-DCURL_HAS_H2=1"
81 "-DCURL_HAS_TLS_PROXY=1"
82 "-DTARGET_ARCH=${host_os}"
83 ] ++ lib.optional (apis != ["*"])
84 "-DBUILD_ONLY=${lib.concatStringsSep ";" apis}";
85
86 env.NIX_CFLAGS_COMPILE = toString [
87 # openssl 3 generates several deprecation warnings
88 "-Wno-error=deprecated-declarations"
89 ];
90
91 # aws-cpp-sdk-core-tests/aws/client/AWSClientTest.cpp
92 # seem to have a datarace
93 enableParallelChecking = false;
94
95 postFixupHooks = [
96 # This bodge is necessary so that the file that the generated -config.cmake file
97 # points to an existing directory.
98 "mkdir -p $out/include"
99 ];
100
101 __darwinAllowLocalNetworking = true;
102
103 # Builds in 2+h with 2 cores, and ~10m with a big-parallel builder.
104 requiredSystemFeatures = [ "big-parallel" ];
105
106 meta = with lib; {
107 description = "A C++ interface for Amazon Web Services";
108 homepage = "https://github.com/aws/aws-sdk-cpp";
109 license = licenses.asl20;
110 platforms = platforms.unix;
111 maintainers = with maintainers; [ eelco orivej ];
112 # building ec2 runs out of memory: cc1plus: out of memory allocating 33554372 bytes after a total of 74424320 bytes
113 broken = stdenv.buildPlatform.is32bit && ((builtins.elem "ec2" apis) || (builtins.elem "*" apis));
114 };
115}