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.118";
28
29 src = fetchFromGitHub {
30 owner = "aws";
31 repo = "aws-sdk-cpp";
32 rev = version;
33 sha256 = "sha256-jqGXh8xLD2gIjV9kSvlldrxA5TxTTXQoC/B66FVprvk=";
34 };
35
36 patches = [
37 ./cmake-dirs.patch
38 ];
39
40 postPatch = ''
41 # Append the dev output to path hints in finding Aws.h to avoid
42 # having to pass `AWS_CORE_HEADER_FILE` explicitly to cmake configure
43 # when using find_package(AWSSDK CONFIG)
44 substituteInPlace cmake/AWSSDKConfig.cmake \
45 --replace 'C:/AWSSDK/''${AWSSDK_INSTALL_INCLUDEDIR}/aws/core' \
46 'C:/AWSSDK/''${AWSSDK_INSTALL_INCLUDEDIR}/aws/core"
47 "${placeholder "dev"}/include/aws/core'
48
49 # Avoid blanket -Werror to evade build failures on less
50 # tested compilers.
51 substituteInPlace cmake/compiler_settings.cmake \
52 --replace '"-Werror"' ' '
53
54 # Flaky on Hydra
55 rm tests/aws-cpp-sdk-core-tests/aws/auth/AWSCredentialsProviderTest.cpp
56 rm tests/aws-cpp-sdk-core-tests/aws/client/AWSClientTest.cpp
57 rm tests/aws-cpp-sdk-core-tests/aws/client/AwsConfigTest.cpp
58 # Includes aws-c-auth private headers, so only works with submodule build
59 rm tests/aws-cpp-sdk-core-tests/aws/auth/AWSAuthSignerTest.cpp
60 # TestRandomURLMultiThreaded fails
61 rm tests/aws-cpp-sdk-core-tests/http/HttpClientTest.cpp
62 '' + lib.optionalString stdenv.isi686 ''
63 # EPSILON is exceeded
64 rm tests/aws-cpp-sdk-core-tests/aws/client/AdaptiveRetryStrategyTest.cpp
65 '';
66
67 # FIXME: might be nice to put different APIs in different outputs
68 # (e.g. libaws-cpp-sdk-s3.so in output "s3").
69 outputs = [ "out" "dev" ];
70
71 nativeBuildInputs = [ cmake curl ];
72
73 buildInputs = [
74 curl openssl zlib
75 ] ++ lib.optionals (stdenv.isDarwin &&
76 ((builtins.elem "text-to-speech" apis) ||
77 (builtins.elem "*" apis)))
78 [ CoreAudio AudioToolbox ];
79
80 # propagation is needed for Security.framework to be available when linking
81 propagatedBuildInputs = [ aws-crt-cpp ];
82 # Ensure the linker is using atomic when compiling for RISC-V, otherwise fails
83 LDFLAGS = lib.optionalString stdenv.hostPlatform.isRiscV "-latomic";
84
85 cmakeFlags = [
86 "-DBUILD_DEPS=OFF"
87 ] ++ lib.optional (!customMemoryManagement) "-DCUSTOM_MEMORY_MANAGEMENT=0"
88 ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
89 "-DENABLE_TESTING=OFF"
90 "-DCURL_HAS_H2=1"
91 "-DCURL_HAS_TLS_PROXY=1"
92 "-DTARGET_ARCH=${host_os}"
93 ] ++ lib.optional (apis != ["*"])
94 "-DBUILD_ONLY=${lib.concatStringsSep ";" apis}";
95
96 env.NIX_CFLAGS_COMPILE = toString [
97 # openssl 3 generates several deprecation warnings
98 "-Wno-error=deprecated-declarations"
99 ];
100
101 postFixupHooks = [
102 # This bodge is necessary so that the file that the generated -config.cmake file
103 # points to an existing directory.
104 "mkdir -p $out/include"
105 ];
106
107 __darwinAllowLocalNetworking = true;
108
109 # Builds in 2+h with 2 cores, and ~10m with a big-parallel builder.
110 requiredSystemFeatures = [ "big-parallel" ];
111
112 meta = with lib; {
113 description = "A C++ interface for Amazon Web Services";
114 homepage = "https://github.com/aws/aws-sdk-cpp";
115 license = licenses.asl20;
116 platforms = platforms.unix;
117 maintainers = with maintainers; [ eelco orivej ];
118 # building ec2 runs out of memory: cc1plus: out of memory allocating 33554372 bytes after a total of 74424320 bytes
119 broken = stdenv.buildPlatform.is32bit && ((builtins.elem "ec2" apis) || (builtins.elem "*" apis));
120 };
121}