Skip to content

Commit 75f632b

Browse files
dschoGit for Windows Build Agent
authored andcommitted
http: optionally load libcurl lazily
This compile-time option allows to ask Git to load libcurl dynamically at runtime. Together with a follow-up patch that optionally overrides the file name depending on the `http.sslBackend` setting, this kicks open the door for installing multiple libcurl flavors side by side, and load the one corresponding to the (runtime-)configured SSL/TLS backend. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent c63ace6 commit 75f632b

File tree

2 files changed

+375
-7
lines changed

2 files changed

+375
-7
lines changed

Makefile

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,11 @@ include shared.mak
470470
#
471471
# CURL_LDFLAGS=-lcurl
472472
#
473+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
474+
# if Multiple libcurl versions exist (with different file names) that link to
475+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
476+
# such a scenario.
477+
#
473478
# === Optional library: libpcre2 ===
474479
#
475480
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1662,10 +1667,19 @@ else
16621667
CURL_LIBCURL =
16631668
endif
16641669

1665-
ifndef CURL_LDFLAGS
1666-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1670+
ifdef LAZYLOAD_LIBCURL
1671+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1672+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1673+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1674+
# declared as DLL imports
1675+
CURL_CFLAGS = -DCURL_STATICLIB
1676+
CURL_LIBCURL = -ldl
1677+
else
1678+
ifndef CURL_LDFLAGS
1679+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1680+
endif
1681+
CURL_LIBCURL += $(CURL_LDFLAGS)
16671682
endif
1668-
CURL_LIBCURL += $(CURL_LDFLAGS)
16691683

16701684
ifndef CURL_CFLAGS
16711685
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1686,7 +1700,7 @@ else
16861700
endif
16871701
ifdef USE_CURL_FOR_IMAP_SEND
16881702
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1689-
IMAP_SEND_BUILDDEPS = http.o
1703+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16901704
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16911705
endif
16921706
ifndef NO_EXPAT
@@ -2892,10 +2906,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28922906
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28932907
$(IMAP_SEND_LDFLAGS) $(LIBS)
28942908

2895-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2909+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28962910
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28972911
$(CURL_LIBCURL) $(LIBS)
2898-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2912+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28992913
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29002914
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29012915

@@ -2905,7 +2919,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
29052919
ln -s $< $@ 2>/dev/null || \
29062920
cp $< $@
29072921

2908-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2922+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29092923
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29102924
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29112925

0 commit comments

Comments
 (0)