Skip to content

Commit 59ec14b

Browse files
committed
Start to bazel rules for curl
- mostly generated with configure2bazel - Fix IDN configure flags and update overlay - Add macos and linux arm overlays. - generates working curl library of the right size for macos cc toolchain is injectined a link arg that doesn't work. ``` /root/.cache/bazel/_bazel_root/81a15fa9a2846e82038a778136785275/external/gcc_toolchain++gcc_toolchains+gcc_toolchain_aarch64/bin/aarch64-unknown-linux-gnu-ld.bfd: unrecognized option '--start-lib' ``` There is some real ugly stuff going on to try to use the output of configure_make as shared libarries. - copying the ssl headers to a new place so we can make a cc_library This is needed because the `includes` attribute on cc_import doesn't work. We need to create a real cc_library to depend on to get that right. - the cc_library / cc_shared_library pair for everything Again, cc_import doesn't seem to work Look at /opt/datadog-agent on local laptop ``` -rwxr-xr-x 1 root wheel 4815040 Dec 9 14:57 /opt/datadog-agent/embedded/lib/libcrypto.3.dylib -rwxr-xr-x 1 root wheel 4857760 Dec 9 14:57 /opt/datadog-agent/embedded/lib/python3.13/site-packages/confluent_kafka/.dylibs/libcrypto.3.dylib -rwxr-xr-x 1 root wheel 4857760 Dec 9 14:57 /opt/datadog-agent/embedded/lib/python3.13/site-packages/psycopg_c/.dylibs/libcrypto.3.dylib -rwxr-xr-x 1 root wheel 965408 Dec 9 14:57 /opt/datadog-agent/embedded/lib/libssl.3.dylib -rwxr-xr-x 1 root wheel 946896 Dec 9 14:57 /opt/datadog-agent/embedded/lib/python3.13/site-packages/confluent_kafka/.dylibs/libssl.3.dylib -rwxr-xr-x 1 root wheel 946896 Dec 9 14:57 /opt/datadog-agent/embedded/lib/python3.13/site-packages/psycopg_c/.dylibs/libssl.3.dylib -rwxr-xr-x 1 root wheel 731904 Dec 9 14:57 /opt/datadog-agent/embedded/lib/python3.13/site-packages/confluent_kafka/.dylibs/libcurl.4.dylib ``` ``` ls -l bazel-bin/external/+_repo_rules+curl/libcurl.dylib bazel-bin/external/+_repo_rules+openssl/libimported_*dylib -r-xr-xr-x 1 tony.aiuto wheel 803968 Jan 13 23:02 bazel-bin/external/+_repo_rules+curl/libcurl.dylib -r-xr-xr-x 1 tony.aiuto wheel 4839472 Jan 13 16:54 bazel-bin/external/+_repo_rules+openssl/libimported_crypto_shared.dylib -r-xr-xr-x 1 tony.aiuto wheel 949008 Jan 13 22:06 bazel-bin/external/+_repo_rules+openssl/libimported_ssl_shared.dylib Note the similar sizes. Drift is probably because of nghttp2. Looking at the linking ``` $ otool -L /opt/datadog-agent/embedded/lib/python3.13/site-packages/confluent_kafka/.dylibs/libcurl.4.dylib /opt/datadog-agent/embedded/lib/python3.13/site-packages/confluent_kafka/.dylibs/libcurl.4.dylib: /DLC/confluent_kafka/.dylibs/libcurl.4.dylib (compatibility version 13.0.0, current version 13.0.0) @loader_path/libssl.3.dylib (compatibility version 3.0.0, current version 3.0.0) @loader_path/libcrypto.3.dylib (compatibility version 3.0.0, current version 3.0.0) @loader_path/libz.1.3.1.dylib (compatibility version 1.0.0, current version 1.3.1) /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation ... /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices ... /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration ... /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1345.120.2) $ otool -L bazel-bin/external/+_repo_rules+curl/libcurl.dylib bazel-bin/external/+_repo_rules+curl/libcurl.dylib: @rpath/libcurl.dylib (compatibility version 0.0.0, current version 0.0.0) @rpath/nghttp2.so.14 (compatibility version 0.0.0, current version 0.0.0) @rpath/libimported_crypto_shared.dylib (compatibility version 0.0.0, current version 0.0.0) @rpath/libimported_ssl_shared.dylib (compatibility version 0.0.0, current version 0.0.0) @rpath/libz.dylib (compatibility version 0.0.0, current version 0.0.0) /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation ... /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration ... /usr/lib/libc++.1.dylib ... /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1356.0.0) ``` The extra CoreServices in the other version is unexpected, but may be a fault in the way Kafka builds it. checkpoint curl got it back to linking no time for jokes maybe readme readme tmp finally delete some apis we do not need comments comments allow haxx.se in adms config log the generated curl_config.h split curl / curlu - does not help
1 parent 0333647 commit 59ec14b

File tree

5 files changed

+88
-33
lines changed

5 files changed

+88
-33
lines changed

.adms/bazel/adms.mirror.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ rewrite (mirrors.edge.kernel.org)/(.*) depot-read-api-bzl.us1.ddbuild.io/$1/$2
104104
rewrite (pyyaml.org)/(.*) depot-read-api-bzl.us1.ddbuild.io/$1/$2
105105
rewrite (python.org)/(.*) depot-read-api-bzl.us1.ddbuild.io/$1/$2
106106
rewrite (mirrors.kernel.org)/(.*) depot-read-api-bzl.us1.ddbuild.io/$1/$2
107+
rewrite (curl.haxx.se)/(.*) depot-read-api-bzl.us1.ddbuild.io/$1/$2
107108

108109
# Rewrite Rules for External Hosts - Specific Language Ecosystems
109110
#######################################################################

deps/curl/overlay/curl.BUILD.bazel

Lines changed: 78 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ load(
1616
"LIB_CURLTOOL_SRCS_LINUX_ARM64",
1717
"LIB_CURLU_SRCS_DARWIN_ARM64",
1818
"LIB_CURLU_SRCS_LINUX_ARM64",
19+
"LIB_CURL_SRCS_LINUX_ARM64",
1920
)
2021

2122
package(
@@ -53,27 +54,25 @@ PUBLIC_HEADERS = [
5354
]
5455

5556
LOCAL_DEFINES = [
56-
"-DHAVE_CONFIG_H",
57-
]
57+
"HAVE_CONFIG_H",
58+
"CURL_DISABLE_DIGEST_AUTH",
59+
"BSAES_ASM",
60+
"ECP_NISTZ256_ASM",
61+
"ECP_SM2P256_ASM",
62+
"KECCAK1600_ASM",
63+
"L_ENDIAN",
64+
"OPENSSL_CPUID_OBJ",
65+
"OPENSSL_PIC",
66+
"SHA1_ASM",
67+
"SHA256_ASM",
68+
"SHA512_ASM",
69+
"SM4_ASM",
70+
"VPAES_ASM",
71+
"VPSM4_ASM",
5872

59-
# TODO: Bring this into LOCAL_DEFINES
60-
XLOCAL_DEFINES = [
61-
"-DOPENSSLDIR='\"/opt/datadog/embedded/ssl/cacerts\"'",
62-
"-DENGINESDIR='\"_/opt/datadog/embedded/lib/engines-3\"'",
63-
"-DMODULESDIR='\"/opt/datadog/embedded/lib/ossl-modules\"'",
64-
"-DBSAES_ASM",
65-
"-DECP_NISTZ256_ASM",
66-
"-DECP_SM2P256_ASM",
67-
"-DKECCAK1600_ASM",
68-
"-DOPENSSL_CPUID_OBJ",
69-
"-DSHA1_ASM",
70-
"-DSHA256_ASM",
71-
"-DSHA512_ASM",
72-
"-DSM4_ASM",
73-
"-DVPAES_ASM",
74-
"-DVPSM4_ASM",
75-
"-DL_ENDIAN",
76-
"-DOPENSSL_PIC",
73+
#"OPENSSLDIR='\"/opt/datadog/embedded/ssl/cacerts\"'",
74+
#"ENGINESDIR='\"_/opt/datadog/embedded/lib/engines-3\"'",
75+
#"MODULESDIR='\"/opt/datadog/embedded/lib/ossl-modules\"'",
7776
]
7877

7978
ARCH_HDRS_COND = {
@@ -87,13 +86,13 @@ cc_binary(
8786
"@platforms//os:linux": LIB_CURLTOOL_SRCS_LINUX_ARM64,
8887
"@platforms//os:macos": LIB_CURLTOOL_SRCS_DARWIN_ARM64,
8988
}),
90-
defines = ["HAVE_CONFIG_H"],
89+
defines = LOCAL_DEFINES,
9190
includes = [
9291
".",
9392
"include",
9493
"lib",
9594
],
96-
copts = LOCAL_DEFINES + [
95+
copts = [
9796
"-I.",
9897
],
9998
dynamic_deps = [
@@ -121,6 +120,57 @@ cc_binary(
121120

122121
cc_library(
123122
name = "curl_static",
123+
srcs = ["lib/curl_config.h"] + HDRS + select(ARCH_HDRS_COND) + select({
124+
"@platforms//os:linux": LIB_CURL_SRCS_LINUX_ARM64,
125+
"@platforms//os:macos": LIB_CURLU_SRCS_DARWIN_ARM64,
126+
}) + ["@openssl//:headers"],
127+
hdrs = PUBLIC_HEADERS,
128+
# Using includes because -I just does not work with bzlmod.
129+
# But yuch. What we need is to port local_incudes concept from Google out
130+
# to rules_cc.
131+
includes = [
132+
"include",
133+
],
134+
local_defines = LOCAL_DEFINES + [
135+
"BUILDING_LIBCURL",
136+
"NDEBUG",
137+
"CURL_STATICLIB",
138+
] + select({
139+
"@platforms//os:macos": [
140+
"CURL_MACOS_CALL_COPYPROXIES",
141+
],
142+
"//conditions:default": [],
143+
}),
144+
copts = [
145+
"-Wno-implicit-function-declaration",
146+
"-Wno-int-conversion",
147+
"-Wno-system-headers",
148+
"-I.",
149+
"-O2",
150+
# "-fvisibility=hidden",
151+
],
152+
linkopts = select({
153+
"@platforms//os:macos": [
154+
"-Wl,-framework,CoreFoundation",
155+
"-Wl,-framework,SystemConfiguration",
156+
],
157+
"//conditions:default": [],
158+
}),
159+
visibility = ["//visibility:public"],
160+
deps = [
161+
"@nghttp2//:nghttp2",
162+
"@openssl//:openssl",
163+
"@zlib//:zlib",
164+
],
165+
# Do not build in ... expansion. It triggers an incompatiblity between
166+
# the toolchain decls, rules_cc, and the compiler we use. rules_cc
167+
# ends up using --start-lib/--end-lib options, which are not recognize
168+
# by the compiler we use as of 2026-02-03.
169+
tags = ["manual"],
170+
)
171+
172+
cc_library(
173+
name = "curlu_static",
124174
srcs = ["lib/curl_config.h"] + HDRS + select(ARCH_HDRS_COND) + select({
125175
"@platforms//os:linux": LIB_CURLU_SRCS_LINUX_ARM64,
126176
"@platforms//os:macos": LIB_CURLU_SRCS_DARWIN_ARM64,
@@ -132,10 +182,10 @@ cc_library(
132182
includes = [
133183
"include",
134184
],
135-
local_defines = [
185+
local_defines = LOCAL_DEFINES + [
136186
"BUILDING_LIBCURL",
137-
"HAVE_CONFIG_H",
138187
"NDEBUG",
188+
# "CURL_STATICLIB",
139189
] + select({
140190
"@platforms//os:macos": [
141191
"CURL_MACOS_CALL_COPYPROXIES",
@@ -145,6 +195,7 @@ cc_library(
145195
copts = [
146196
"-Wno-implicit-function-declaration",
147197
"-Wno-int-conversion",
198+
"-Wno-system-headers",
148199
"-I.",
149200
"-O2",
150201
],
@@ -157,6 +208,7 @@ cc_library(
157208
}),
158209
visibility = ["//visibility:public"],
159210
deps = [
211+
":curl_static",
160212
"@nghttp2//:nghttp2",
161213
"@openssl//:openssl",
162214
"@zlib//:zlib",
@@ -172,6 +224,7 @@ cc_shared_library(
172224
name = "curl",
173225
deps = [
174226
":curl_static",
227+
":curlu_static",
175228
],
176229
dynamic_deps = [
177230
"@nghttp2//:nghttp2_shared",
@@ -180,6 +233,7 @@ cc_shared_library(
180233
],
181234
user_link_flags = select({
182235
"@platforms//os:linux": [
236+
"-fvisibility=hidden",
183237
"-Wl,-L/opt/datadog-agent/embedded/lib",
184238
"-Wl,-rpath=/opt/datadog-agent/embedded/lib",
185239
],

deps/curl/overlay/lib_contents.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,11 @@ LIB_CURLU_SRCS_LINUX_ARM64 = [
695695
"lib/uint-table.c",
696696
"lib/url.c",
697697
"lib/urlapi.c",
698+
"lib/version.c",
699+
"lib/ws.c",
700+
]
701+
702+
LIB_CURL_SRCS_LINUX_ARM64 = [
698703
"lib/vauth/cleartext.c",
699704
"lib/vauth/cram.c",
700705
"lib/vauth/digest_sspi.c",
@@ -708,7 +713,6 @@ LIB_CURLU_SRCS_LINUX_ARM64 = [
708713
"lib/vauth/spnego_gssapi.c",
709714
"lib/vauth/spnego_sspi.c",
710715
"lib/vauth/vauth.c",
711-
"lib/version.c",
712716
"lib/vquic/curl_ngtcp2.c",
713717
"lib/vquic/curl_osslq.c",
714718
"lib/vquic/curl_quiche.c",
@@ -732,7 +736,6 @@ LIB_CURLU_SRCS_LINUX_ARM64 = [
732736
"lib/vtls/vtls.c",
733737
"lib/vtls/wolfssl.c",
734738
"lib/vtls/x509asn1.c",
735-
"lib/ws.c",
736739
]
737740

738741
# Textual headers (included .c files and other non-.h files)

deps/curl/overlay/linux_arm64/lib/curl_config.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444

4545
/* to disable digest authentication */
4646
/* #undef CURL_DISABLE_DIGEST_AUTH */
47-
#define CURL_DISABLE_DIGEST_AUTH 1
4847

4948
/* disable DoH */
5049
/* #undef CURL_DISABLE_DOH */
@@ -54,7 +53,6 @@
5453

5554
/* disable form API */
5655
/* #undef CURL_DISABLE_FORM_API */
57-
#define CURL_DISABLE_FORM_API 1
5856

5957
/* to disable FTP */
6058
/* #undef CURL_DISABLE_FTP */
@@ -64,7 +62,6 @@
6462

6563
/* to disable Gopher */
6664
/* #undef CURL_DISABLE_GOPHER */
67-
#define CURL_DISABLE_GOPHER 1
6865

6966
/* disable headers-api */
7067
/* #undef CURL_DISABLE_HEADERS_API */
@@ -80,7 +77,6 @@
8077

8178
/* to disable IMAP */
8279
/* #undef CURL_DISABLE_IMAP */
83-
#define CURL_DISABLE_IMAP 1
8480

8581
/* to disable IPFS */
8682
/* #undef CURL_DISABLE_IPFS */
@@ -111,7 +107,6 @@
111107

112108
/* to disable NTLM support */
113109
/* #undef CURL_DISABLE_NTLM */
114-
#define CURL_DISABLE_NTLM 1
115110

116111
/* if the OpenSSL configuration will not be loaded automatically */
117112
/* #undef CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG */
@@ -643,6 +638,7 @@
643638
#define HAVE_STRING_H 1
644639

645640
/* Define to 1 if you have the <stropts.h> header file. */
641+
// #define HAVE_STROPTS_H 1
646642
/* #undef HAVE_STROPTS_H */
647643

648644
/* if struct sockaddr_storage is defined */

omnibus/config/software/curl.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
]
6363
configure(*configure_options, env: env)
6464

65-
command "make -j #{workers}", env: env
66-
command "make install"
65+
command "make -j #{workers}", env: env, :live_stream => Omnibus.logger.live_stream(:info)
66+
command "echo === OMNI ENV; printenv | sort ; echo === OMNI CONFIG ; cat lib/curl_config.h", env: env, :live_stream => Omnibus.logger.live_stream(:info)
67+
command "make install", :live_stream => Omnibus.logger.live_stream(:info)
6768
end

0 commit comments

Comments
 (0)