Skip to content

Commit 9cfbf2f

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 0a82c03 commit 9cfbf2f

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
@@ -472,6 +472,11 @@ include shared.mak
472472
#
473473
# CURL_LDFLAGS=-lcurl
474474
#
475+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
476+
# if Multiple libcurl versions exist (with different file names) that link to
477+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
478+
# such a scenario.
479+
#
475480
# === Optional library: libpcre2 ===
476481
#
477482
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1664,10 +1669,19 @@ else
16641669
CURL_LIBCURL =
16651670
endif
16661671

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

16721686
ifndef CURL_CFLAGS
16731687
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1688,7 +1702,7 @@ else
16881702
endif
16891703
ifdef USE_CURL_FOR_IMAP_SEND
16901704
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1691-
IMAP_SEND_BUILDDEPS = http.o
1705+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16921706
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16931707
endif
16941708
ifndef NO_EXPAT
@@ -2897,10 +2911,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28972911
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28982912
$(IMAP_SEND_LDFLAGS) $(LIBS)
28992913

2900-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2914+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29012915
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29022916
$(CURL_LIBCURL) $(LIBS)
2903-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2917+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29042918
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29052919
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29062920

@@ -2910,7 +2924,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
29102924
ln -s $< $@ 2>/dev/null || \
29112925
cp $< $@
29122926

2913-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2927+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29142928
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29152929
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29162930

0 commit comments

Comments
 (0)