__init__.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. from devtools.yamaker import fileutil
  2. from devtools.yamaker.arcpath import ArcPath
  3. from devtools.yamaker.modules import GLOBAL, Switch, Linkable, Words
  4. from devtools.yamaker.project import GNUMakeNixProject
  5. def post_install(self):
  6. curl_config = f"{self.dstdir}/lib/curl_config.h"
  7. fileutil.re_sub_file(
  8. curl_config,
  9. "#pragma once\n",
  10. r"""\g<0>
  11. #include <util/system/platform.h>
  12. """,
  13. )
  14. with open(curl_config, "a") as config:
  15. config.write(
  16. """
  17. // Do not misrepresent host on Android and iOS.
  18. #undef OS
  19. #define OS "arcadia"
  20. // c-ares resolver is known to be buggy.
  21. //
  22. // There is no way to configure it properly without a JVM on Android,
  23. // because Android lacks traditional resolv.conf.
  24. //
  25. // For standalone Android programs, it is impossible
  26. // to contact ConnectionManager outside the JVM; this breaks c-ares DNS resolution.
  27. // As we can not distinguish builds of Android apps from standalone Android programs.
  28. //
  29. // During mapkit experiments, c-ares was adding about 10ms to each query timespan.
  30. //
  31. //
  32. // On Linux it caches /etc/resolv.conf contents and does not invalidate it properly
  33. #if defined(ARCADIA_CURL_DNS_RESOLVER_ARES)
  34. #define USE_ARES
  35. #elif defined(ARCADIA_CURL_DNS_RESOLVER_MULTITHREADED)
  36. #undef USE_ARES
  37. #if defined(_MSC_VER)
  38. #define USE_THREADS_WIN32 1
  39. #else
  40. #define USE_THREADS_POSIX 1
  41. #endif
  42. #elif defined(ARCADIA_CURL_DNS_RESOLVER_SYNCHRONOUS)
  43. #undef USE_ARES
  44. #undef USE_THREADS_POSIX
  45. #undef USE_THREADS_WIN32
  46. #else
  47. #error "No dns resolver is specified or resolver specification is wrong"
  48. #endif
  49. """
  50. )
  51. # curl uses SIZEOF_ macros to test current platform bitness in compile-time
  52. # As we only control curl_config-linux.h during yamaker installation,
  53. # we can not ensure if the proper define is set.
  54. #
  55. # SIZEOF_SIZE_T is controlled by curl_config-x(32|64).h
  56. # SIZEOF_SHORT..SIZEOF_LONG are expected to be defined by util/system/platform.h.
  57. curl_config_linux = f"{self.dstdir}/lib/curl_config-linux.h"
  58. fileutil.re_sub_file(
  59. curl_config_linux,
  60. "(?m)^#define (SIZEOF_(SHORT|INT|LONG)) .*",
  61. r"#ifndef \1\n#error undefined \1\n#endif",
  62. )
  63. # time_t is long (4 or 8 bytes), except on Windows it is long long (always 8 bytes).
  64. fileutil.re_sub_file(
  65. curl_config_linux,
  66. "(?m)^(#define SIZEOF_TIME_T) .*",
  67. r"\1 SIZEOF_LONG",
  68. )
  69. with self.yamakes["."] as m:
  70. m.before("CFLAGS", "DEFAULT(ARCADIA_CURL_DNS_RESOLVER ARES)")
  71. m.CFLAGS = [
  72. GLOBAL("-DCURL_STATICLIB"),
  73. "-DBUILDING_LIBCURL",
  74. "-DHAVE_CONFIG_H",
  75. "-DARCADIA_CURL_DNS_RESOLVER_${ARCADIA_CURL_DNS_RESOLVER}",
  76. ]
  77. # add ifaddrs implementation if needed
  78. m.PEERDIR.add("contrib/libs/libc_compat")
  79. # make c-ares dependency conditional,
  80. # but leave ADDINCL in place to make CONFIGURE work
  81. m.ADDINCL.append("contrib/libs/c-ares/include")
  82. m.ADDINCL = sorted(m.ADDINCL, key=ArcPath._as_cmp_tuple)
  83. m.PEERDIR.remove("contrib/libs/c-ares")
  84. m.after(
  85. "CFLAGS",
  86. Switch(
  87. {
  88. "ARCADIA_CURL_DNS_RESOLVER == ARES": Linkable(
  89. PEERDIR=["contrib/libs/c-ares"],
  90. )
  91. }
  92. ),
  93. )
  94. # curl calls system functions for address synthesis on macOS
  95. # https://github.com/curl/curl/pull/7121
  96. m.after(
  97. "LDFLAGS",
  98. Switch(
  99. OS_DARWIN=Linkable(LDFLAGS=[Words("-framework", "SystemConfiguration")]),
  100. ),
  101. )
  102. # Remove to avoid disabling lots of unneeded includes
  103. m.SRCS -= {
  104. "lib/vtls/cyassl.c",
  105. "lib/vtls/gskit.c",
  106. "lib/vtls/gtls.c",
  107. "lib/vtls/mbedtls.c",
  108. "lib/vtls/mesalink.c",
  109. "lib/vtls/nss.c",
  110. "lib/vtls/polarssl.c",
  111. "lib/vtls/polarssl_threadlock.c",
  112. "lib/vtls/schannel.c",
  113. "lib/vtls/schannel_verify.c",
  114. }
  115. with self.yamakes["bin"] as cli:
  116. # cli is intended to be built on development hosts.
  117. # c-ares dns resolver is expected to function here.
  118. cli.CFLAGS.append("-DARCADIA_CURL_DNS_RESOLVER_ARES")
  119. cli.PEERDIR.add("contrib/libs/c-ares")
  120. curl = GNUMakeNixProject(
  121. owners=["g:cpp-contrib", "g:geoapps_infra"],
  122. arcdir="contrib/libs/curl",
  123. nixattr="curl",
  124. ignore_commands=[
  125. "bash",
  126. ],
  127. put={
  128. "Library curl": ".",
  129. "Program curl": "bin",
  130. },
  131. copy_sources=[
  132. "include/curl/stdcheaders.h",
  133. "lib/curl_sspi.h",
  134. "lib/setup-win32.h",
  135. ],
  136. disable_includes=[
  137. "afunix.h",
  138. "amitcp/",
  139. "bsdsocket/socketbasetags.h",
  140. "cipher.mih",
  141. "config-*",
  142. "curl_gssapi.h",
  143. "curl_path.h",
  144. "curlmsg_vms.h",
  145. "exec/execbase.h",
  146. "exec/types.h",
  147. "extra/",
  148. "fabdef.h",
  149. "floss.h",
  150. "gnutls/",
  151. "gss.h",
  152. "idn2.h",
  153. "lber.h",
  154. "ldap.h",
  155. "ldap_ssl.h",
  156. "libpsl.h",
  157. "librtmp/rtmp.h",
  158. "libssh/",
  159. "libssh2.h",
  160. "libssh2_sftp.h",
  161. "lwip/",
  162. "mbedtls/",
  163. "mbedtls_threadlock.h",
  164. "msh3.h",
  165. "nspr.h",
  166. "netinet/in6.h",
  167. "nettle/",
  168. "ngtcp2/ngtcp2_crypto_boringssl.h",
  169. "ngtcp2/ngtcp2_crypto_gnutls.h",
  170. "ngtcp2/ngtcp2_crypto_wolfssl.h",
  171. "nwconio.h",
  172. # NB: openssl/core_names.h appeared in OpenSSL 3.0, while we have only 1.1.1l at the time
  173. "openssl/core_names.h",
  174. "plarenas.h",
  175. "proto/",
  176. "quiche.h",
  177. "setup-os400.h",
  178. "setup-vms.h",
  179. "stabs.h",
  180. "subauth.h",
  181. "vquic/msh3.h",
  182. "vquic/ngtcp2.h",
  183. "vquic/quiche.h",
  184. "wolfssh/",
  185. "wolfssl/",
  186. "hyper.h",
  187. "gsasl.h",
  188. "descrip",
  189. "iodef",
  190. "starlet",
  191. # Disable system includes of these headers, yet allow including lib/vtls/{rustls,bearssl}.h
  192. "<rustls.h>",
  193. "<bearssl.h>",
  194. ],
  195. addincl_global={".": {"./include"}},
  196. platform_dispatchers=["lib/curl_config.h"],
  197. post_install=post_install,
  198. )
  199. # CHANGES file is just a git log, it is not intended for humans, yet increases diff size dramatically
  200. curl.copy_top_sources_except.add("CHANGES")