aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/curl/.yandex_meta/__init__.py
blob: c0b275ea2123ab6bd12c87474db572fd8a6b8b49 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
from devtools.yamaker import fileutil
from devtools.yamaker.arcpath import ArcPath
from devtools.yamaker.modules import GLOBAL, Switch, Linkable, Words
from devtools.yamaker.project import GNUMakeNixProject


def post_install(self):
    curl_config = f"{self.dstdir}/lib/curl_config.h"
    fileutil.re_sub_file(
        curl_config,
        "#pragma once\n",
        r"""\g<0>
#include <util/system/platform.h>
""",
    )
    with open(curl_config, "a") as config:
        config.write(
            """
// Do not misrepresent host on Android and iOS.
#undef OS
#define OS "arcadia"

// c-ares resolver is known to be buggy.
//
// There is no way to configure it properly without a JVM on Android,
// because Android lacks traditional resolv.conf.
//
// For standalone Android programs, it is impossible
// to contact ConnectionManager outside the JVM; this breaks c-ares DNS resolution.
// As we can not distinguish builds of Android apps from standalone Android programs.
//
// During mapkit experiments, c-ares was adding about 10ms to each query timespan.
//
//
// On Linux it caches /etc/resolv.conf contents and does not invalidate it properly

#if defined(ARCADIA_CURL_DNS_RESOLVER_ARES)
    #define USE_ARES
#elif defined(ARCADIA_CURL_DNS_RESOLVER_MULTITHREADED)
    #undef USE_ARES
    #if defined(_MSC_VER)
        #define USE_THREADS_WIN32 1
    #else
        #define USE_THREADS_POSIX 1
    #endif
#elif defined(ARCADIA_CURL_DNS_RESOLVER_SYNCHRONOUS)
    #undef USE_ARES
    #undef USE_THREADS_POSIX
    #undef USE_THREADS_WIN32
#else
    #error "No dns resolver is specified or resolver specification is wrong"
#endif
"""
        )

    # curl uses SIZEOF_ macros to test current platform bitness in compile-time
    # As we only control curl_config-linux.h during yamaker installation,
    # we can not ensure if the proper define is set.
    #
    # SIZEOF_SIZE_T is controlled by curl_config-x(32|64).h
    # SIZEOF_SHORT..SIZEOF_LONG are expected to be defined by util/system/platform.h.
    curl_config_linux = f"{self.dstdir}/lib/curl_config-linux.h"
    fileutil.re_sub_file(
        curl_config_linux,
        "(?m)^#define (SIZEOF_(SHORT|INT|LONG)) .*",
        r"#ifndef \1\n#error undefined \1\n#endif",
    )
    # time_t is long (4 or 8 bytes), except on Windows it is long long (always 8 bytes).
    fileutil.re_sub_file(
        curl_config_linux,
        "(?m)^(#define SIZEOF_TIME_T) .*",
        r"\1 SIZEOF_LONG",
    )

    with self.yamakes["."] as m:
        m.before("CFLAGS", "DEFAULT(ARCADIA_CURL_DNS_RESOLVER ARES)")
        m.CFLAGS = [
            GLOBAL("-DCURL_STATICLIB"),
            "-DBUILDING_LIBCURL",
            "-DHAVE_CONFIG_H",
            "-DARCADIA_CURL_DNS_RESOLVER_${ARCADIA_CURL_DNS_RESOLVER}",
        ]

        # add ifaddrs implementation if needed
        m.PEERDIR.add("contrib/libs/libc_compat")

        # make c-ares dependency conditional,
        # but leave ADDINCL in place to make CONFIGURE work
        m.ADDINCL.append("contrib/libs/c-ares/include")
        m.ADDINCL = sorted(m.ADDINCL, key=ArcPath._as_cmp_tuple)
        m.PEERDIR.remove("contrib/libs/c-ares")
        m.after(
            "CFLAGS",
            Switch(
                {
                    "ARCADIA_CURL_DNS_RESOLVER == ARES": Linkable(
                        PEERDIR=["contrib/libs/c-ares"],
                    )
                }
            ),
        )

        # curl calls system functions for address synthesis on macOS
        # https://github.com/curl/curl/pull/7121
        m.after(
            "LDFLAGS",
            Switch(
                OS_DARWIN=Linkable(LDFLAGS=[Words("-framework", "SystemConfiguration")]),
            ),
        )

        # Remove to avoid disabling lots of unneeded includes
        m.SRCS -= {
            "lib/vtls/cyassl.c",
            "lib/vtls/gskit.c",
            "lib/vtls/gtls.c",
            "lib/vtls/mbedtls.c",
            "lib/vtls/mesalink.c",
            "lib/vtls/nss.c",
            "lib/vtls/polarssl.c",
            "lib/vtls/polarssl_threadlock.c",
            "lib/vtls/schannel.c",
            "lib/vtls/schannel_verify.c",
        }

    with self.yamakes["bin"] as cli:
        # cli is intended to be built on development hosts.
        # c-ares dns resolver is expected to function here.
        cli.CFLAGS.append("-DARCADIA_CURL_DNS_RESOLVER_ARES")
        cli.PEERDIR.add("contrib/libs/c-ares")


curl = GNUMakeNixProject(
    owners=["g:cpp-contrib", "g:geoapps_infra"],
    arcdir="contrib/libs/curl",
    nixattr="curl",
    ignore_commands=[
        "bash",
    ],
    put={
        "Library curl": ".",
        "Program curl": "bin",
    },
    copy_sources=[
        "include/curl/stdcheaders.h",
        "lib/curl_sspi.h",
        "lib/setup-win32.h",
    ],
    disable_includes=[
        "afunix.h",
        "amitcp/",
        "bsdsocket/socketbasetags.h",
        "cipher.mih",
        "config-*",
        "curl_gssapi.h",
        "curl_path.h",
        "curlmsg_vms.h",
        "exec/execbase.h",
        "exec/types.h",
        "extra/",
        "fabdef.h",
        "floss.h",
        "gnutls/",
        "gss.h",
        "idn2.h",
        "lber.h",
        "ldap.h",
        "ldap_ssl.h",
        "libpsl.h",
        "librtmp/rtmp.h",
        "libssh/",
        "libssh2.h",
        "libssh2_sftp.h",
        "lwip/",
        "mbedtls/",
        "mbedtls_threadlock.h",
        "msh3.h",
        "nspr.h",
        "netinet/in6.h",
        "nettle/",
        "nghttp3/",
        "ngtcp2.h",
        "ngtcp2/",
        "nwconio.h",
        # NB: openssl/core_names.h appeared in OpenSSL 3.0, while we have only 1.1.1l at the time
        "openssl/core_names.h",
        "openssl/ech.h",
        "plarenas.h",
        "proto/",
        "quiche.h",
        "setup-os400.h",
        "setup-vms.h",
        "stabs.h",
        "subauth.h",
        "unicode/uidna.h",
        "uv.h",
        "vquic-*",
        "wolfssh/*",
        "wolfssl/*",
        "hyper.h",
        "gsasl.h",
        "descrip",
        "iodef",
        "starlet",
        "x509asn1.h",
        "cipher_suite.h",
        # Disable system includes of these headers, yet allow including lib/vtls/{rustls,bearssl}.h
        "<rustls.h>",
        "<bearssl.h>",
    ],
    addincl_global={".": {"./include"}},
    platform_dispatchers=["lib/curl_config.h"],
    post_install=post_install,
)

# CHANGES file is just a git log, it is not intended for humans, yet increases diff size dramatically
curl.copy_top_sources_except.add("CHANGES")