|
| 1 | +""" Agent specific curl build.""" |
| 2 | + |
| 3 | +load("@@//bazel/rules:so_symlink.bzl", "so_symlink") |
| 4 | + |
| 5 | +# load("@bazel_skylib//rules:copy_file.bzl", "copy_file") |
| 6 | +load("@rules_cc//cc:cc_binary.bzl", "cc_binary") |
| 7 | +load("@rules_cc//cc:cc_library.bzl", "cc_library") |
| 8 | +load("@rules_cc//cc:cc_shared_library.bzl", "cc_shared_library") |
| 9 | +load("@rules_license//rules:license.bzl", "license") |
| 10 | +load("@rules_pkg//pkg:install.bzl", "pkg_install") |
| 11 | +load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_files") |
| 12 | +load( |
| 13 | + "lib_contents.bzl", |
| 14 | + "HDRS", |
| 15 | + "HDRS_DARWIN_ARM64", |
| 16 | + "HDRS_LINUX_ARM64", |
| 17 | + "LIB_CURLTOOL_SRCS_DARWIN_ARM64", |
| 18 | + "LIB_CURLTOOL_SRCS_LINUX_ARM64", |
| 19 | + "LIB_CURLU_SRCS_DARWIN_ARM64", |
| 20 | + "LIB_CURLU_SRCS_LINUX_ARM64", |
| 21 | +) |
| 22 | + |
| 23 | +SO_VERSION = "4.8.0" |
| 24 | + |
| 25 | +package( |
| 26 | + default_package_metadata = [":license"], |
| 27 | + default_visibility = ["@@//packages:__subpackages__"], |
| 28 | +) |
| 29 | + |
| 30 | +license( |
| 31 | + name = "license", |
| 32 | + # The "curl" license is a specially designated type. |
| 33 | + license_kinds = ["@rules_license//licenses/spdx:curl"], |
| 34 | + license_text = "COPYING", |
| 35 | + visibility = ["//visibility:public"], |
| 36 | +) |
| 37 | + |
| 38 | +VERSION = "8.16.0" |
| 39 | +SONAME = "libcurl.so.%s" % VERSION |
| 40 | + |
| 41 | +PUBLIC_HEADERS = [ |
| 42 | + "include/curl/curl.h", |
| 43 | + "include/curl/curlver.h", |
| 44 | + "include/curl/easy.h", |
| 45 | + "include/curl/header.h", |
| 46 | + "include/curl/mprintf.h", |
| 47 | + "include/curl/multi.h", |
| 48 | + "include/curl/options.h", |
| 49 | + "include/curl/stdcheaders.h", |
| 50 | + "include/curl/system.h", |
| 51 | + "include/curl/typecheck-gcc.h", |
| 52 | + "include/curl/urlapi.h", |
| 53 | + "include/curl/websockets.h", |
| 54 | +] |
| 55 | + |
| 56 | +LOCAL_DEFINES = [ |
| 57 | + "-DHAVE_CONFIG_H", |
| 58 | +] |
| 59 | + |
| 60 | +# TODO: Bring this into LOCAL_DEFINES |
| 61 | +XLOCAL_DEFINES = [ |
| 62 | + "-DOPENSSLDIR='\"/opt/datadog/embedded/ssl/cacerts\"'", |
| 63 | + "-DENGINESDIR='\"_/opt/datadog/embedded/lib/engines-3\"'", |
| 64 | + "-DMODULESDIR='\"/opt/datadog/embedded/lib/ossl-modules\"'", |
| 65 | + "-DBSAES_ASM", |
| 66 | + "-DECP_NISTZ256_ASM", |
| 67 | + "-DECP_SM2P256_ASM", |
| 68 | + "-DKECCAK1600_ASM", |
| 69 | + "-DOPENSSL_CPUID_OBJ", |
| 70 | + "-DSHA1_ASM", |
| 71 | + "-DSHA256_ASM", |
| 72 | + "-DSHA512_ASM", |
| 73 | + "-DSM4_ASM", |
| 74 | + "-DVPAES_ASM", |
| 75 | + "-DVPSM4_ASM", |
| 76 | + "-DL_ENDIAN", |
| 77 | + "-DOPENSSL_PIC", |
| 78 | +] |
| 79 | + |
| 80 | +ARCH_HDRS_COND = { |
| 81 | + "@platforms//os:linux": HDRS_LINUX_ARM64, |
| 82 | + "@platforms//os:macos": HDRS_DARWIN_ARM64, |
| 83 | +} |
| 84 | + |
| 85 | +cc_binary( |
| 86 | + name = "curl_bin", |
| 87 | + srcs = ["lib/curl_config.h"] + HDRS + PUBLIC_HEADERS + select(ARCH_HDRS_COND) + select({ |
| 88 | + "@platforms//os:linux": LIB_CURLTOOL_SRCS_LINUX_ARM64, |
| 89 | + "@platforms//os:macos": LIB_CURLTOOL_SRCS_DARWIN_ARM64, |
| 90 | + }), |
| 91 | + defines = ["HAVE_CONFIG_H"], |
| 92 | + includes = [ |
| 93 | + ".", |
| 94 | + "include", |
| 95 | + "lib", |
| 96 | + ], |
| 97 | + copts = LOCAL_DEFINES + [ |
| 98 | + "-I.", |
| 99 | + ], |
| 100 | + dynamic_deps = ["curl"], |
| 101 | + linkstatic = False, |
| 102 | + linkopts = select({ |
| 103 | + "@platforms//os:linux": [ |
| 104 | + "-Wl,-L/opt/datadog-agent/embedded/lib", |
| 105 | + "-Wl,-rpath=/opt/datadog-agent/embedded/lib", |
| 106 | + # "-Wl,-lnghttp2", |
| 107 | + #"-Wl,-lz", |
| 108 | + ], |
| 109 | + "@platforms//os:macos": [ |
| 110 | + "-Wl,-framework,CoreFoundation", |
| 111 | + "-Wl,-framework,SystemConfiguration", |
| 112 | + # "-Wl,-rpath=/opt/datadog-agent/embedded/lib", |
| 113 | + ], |
| 114 | + "//conditions:default": [], |
| 115 | + }), |
| 116 | + visibility = ["//visibility:public"], |
| 117 | +) |
| 118 | + |
| 119 | +cc_library( |
| 120 | + name = "curl_static", |
| 121 | + srcs = ["lib/curl_config.h"] + HDRS + select(ARCH_HDRS_COND) + select({ |
| 122 | + "@platforms//os:linux": LIB_CURLU_SRCS_LINUX_ARM64, |
| 123 | + "@platforms//os:macos": LIB_CURLU_SRCS_DARWIN_ARM64, |
| 124 | + }) + ["@openssl//:headers"], |
| 125 | + hdrs = PUBLIC_HEADERS, |
| 126 | + # Using includes because -I just does not work with bzlmod. |
| 127 | + # But yuch. What we need is to port local_incudes concept from Google out |
| 128 | + # to rules_cc. |
| 129 | + includes = [ |
| 130 | + "include", |
| 131 | + ], |
| 132 | + local_defines = [ |
| 133 | + "BUILDING_LIBCURL", |
| 134 | + "HAVE_CONFIG_H", |
| 135 | + "NDEBUG", |
| 136 | + ] + select({ |
| 137 | + "@platforms//os:macos": [ |
| 138 | + "CURL_MACOS_CALL_COPYPROXIES", |
| 139 | + ], |
| 140 | + "//conditions:default": [], |
| 141 | + }), |
| 142 | + copts = [ |
| 143 | + "-Wno-implicit-function-declaration", |
| 144 | + "-Wno-int-conversion", |
| 145 | + "-I.", |
| 146 | + ] + select({ |
| 147 | + "@platforms//os:linux": [ |
| 148 | + "-fvisibility=hidden", |
| 149 | + "-O2", |
| 150 | + ], |
| 151 | + "@platforms//os:macos": [ |
| 152 | + "-O2", |
| 153 | + ], |
| 154 | + }), |
| 155 | + linkopts = select({ |
| 156 | + "@platforms//os:macos": [ |
| 157 | + "-Wl,-framework,CoreFoundation", |
| 158 | + "-Wl,-framework,SystemConfiguration", |
| 159 | + ], |
| 160 | + "//conditions:default": [], |
| 161 | + }), |
| 162 | + visibility = ["//visibility:public"], |
| 163 | + deps = [ |
| 164 | + "@nghttp2//:nghttp2", |
| 165 | + "@openssl//:crypto", |
| 166 | + "@openssl//:ssl", |
| 167 | + "@openssl//:imported_ssl_headers", |
| 168 | + "@zlib//:zlib", |
| 169 | + ], |
| 170 | +) |
| 171 | + |
| 172 | +cc_shared_library( |
| 173 | + name = "curl", |
| 174 | + deps = [ |
| 175 | + ":curl_static", |
| 176 | + ], |
| 177 | + dynamic_deps = [ |
| 178 | + "@nghttp2//:nghttp2_shared", |
| 179 | + "@openssl//:ssl_shared", |
| 180 | + "@openssl//:crypto_shared", |
| 181 | + "@zlib//:z", |
| 182 | + ], |
| 183 | + visibility = ["//visibility:public"], |
| 184 | +) |
| 185 | + |
| 186 | +pkg_files( |
| 187 | + name = "bin_files", |
| 188 | + srcs = [ |
| 189 | + ":curl_bin", |
| 190 | + ], |
| 191 | + attributes = pkg_attributes(mode = "0755"), |
| 192 | + renames = { |
| 193 | + "curl_bin": "curl", |
| 194 | + }, |
| 195 | + prefix = "embedded/bin", |
| 196 | +) |
| 197 | + |
| 198 | +so_symlink( |
| 199 | + name = "lib_files", |
| 200 | + src = ":curl", |
| 201 | + libname = "libcurl", |
| 202 | + version = SO_VERSION, |
| 203 | + prefix = "embedded", |
| 204 | +) |
| 205 | + |
| 206 | +pkg_files( |
| 207 | + name = "hdr_files", |
| 208 | + srcs = PUBLIC_HEADERS, |
| 209 | + prefix = "embedded/include/curl", |
| 210 | +) |
| 211 | + |
| 212 | +pkg_filegroup( |
| 213 | + name = "all_files", |
| 214 | + srcs = [ |
| 215 | + ":bin_files", |
| 216 | + ":hdr_files", |
| 217 | + ":lib_files", |
| 218 | + ], |
| 219 | +) |
| 220 | + |
| 221 | +pkg_install( |
| 222 | + name = "install", |
| 223 | + srcs = [":all_files"], |
| 224 | +) |
0 commit comments