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 rm tests/aws-cpp-sdk-core-tests/aws/client/AWSClientTest.cpp
49 rm tests/aws-cpp-sdk-core-tests/aws/client/AwsConfigTest.cpp
50 # Includes aws-c-auth private headers, so only works with submodule build
51 rm tests/aws-cpp-sdk-core-tests/aws/auth/AWSAuthSignerTest.cpp
52 # TestRandomURLMultiThreaded fails
53 rm tests/aws-cpp-sdk-core-tests/http/HttpClientTest.cpp
54 '' + lib.optionalString stdenv.isi686 ''
55 # EPSILON is exceeded
56 rm tests/aws-cpp-sdk-core-tests/aws/client/AdaptiveRetryStrategyTest.cpp
57 '';
58
59 # FIXME: might be nice to put different APIs in different outputs
60 # (e.g. libaws-cpp-sdk-s3.so in output "s3").
61 outputs = [ "out" "dev" ];
62
63 nativeBuildInputs = [ cmake curl ];
64
65 buildInputs = [
66 curl openssl zlib
67 ] ++ lib.optionals (stdenv.isDarwin &&
68 ((builtins.elem "text-to-speech" apis) ||
69 (builtins.elem "*" apis)))
70 [ CoreAudio AudioToolbox ];
71
72 # propagation is needed for Security.framework to be available when linking
73 propagatedBuildInputs = [ aws-crt-cpp ];
74 # Ensure the linker is using atomic when compiling for RISC-V, otherwise fails
75 LDFLAGS = lib.optionalString stdenv.hostPlatform.isRiscV "-latomic";
76
77 cmakeFlags = [
78 "-DBUILD_DEPS=OFF"
79 ] ++ lib.optional (!customMemoryManagement) "-DCUSTOM_MEMORY_MANAGEMENT=0"
80 ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
81 "-DENABLE_TESTING=OFF"
82 "-DCURL_HAS_H2=1"
83 "-DCURL_HAS_TLS_PROXY=1"
84 "-DTARGET_ARCH=${host_os}"
85 ] ++ lib.optional (apis != ["*"])
86 "-DBUILD_ONLY=${lib.concatStringsSep ";" apis}";
87
88 env.NIX_CFLAGS_COMPILE = toString [
89 # openssl 3 generates several deprecation warnings
90 "-Wno-error=deprecated-declarations"
91 ];
92
93 postFixupHooks = [
94 # This bodge is necessary so that the file that the generated -config.cmake file
95 # points to an existing directory.
96 "mkdir -p $out/include"
97 ];
98
99 __darwinAllowLocalNetworking = true;
100
101 # Builds in 2+h with 2 cores, and ~10m with a big-parallel builder.
102 requiredSystemFeatures = [ "big-parallel" ];
103
104 meta = with lib; {
105 description = "A C++ interface for Amazon Web Services";
106 homepage = "https://github.com/aws/aws-sdk-cpp";
107 license = licenses.asl20;
108 platforms = platforms.unix;
109 maintainers = with maintainers; [ eelco orivej ];
110 # building ec2 runs out of memory: cc1plus: out of memory allocating 33554372 bytes after a total of 74424320 bytes
111 broken = stdenv.buildPlatform.is32bit && ((builtins.elem "ec2" apis) || (builtins.elem "*" apis));
112 };
113}