Skip to content

Commit 1bdf694

Browse files
committed
Lazy load libcurl, allowing for an SSL/TLS backend-specific libcurl (#4410)
As per #4350 (comment), the major block for upgrading Git for Windows' OpenSSL from v1.1 to v3 is the tricky part where such an upgrade would break `git fetch`/`git clone` and `git push` because the libcurl depends on the OpenSSL DLL, and the major version bump will _change_ the file name of said DLL. To overcome that, the plan is to build libcurl flavors for each supported SSL/TLS backend, aligning with the way MSYS2 builds libcurl, then switch Git for Windows' SDK to the Secure Channel-flavored libcurl, and teach Git to look for the specific flavor of libcurl corresponding to the `http.sslBackend` setting (if that was configured). Here is the PR to teach Git that trick.
2 parents ebb4d3f + 2718450 commit 1bdf694

File tree

3 files changed

+444
-7
lines changed

3 files changed

+444
-7
lines changed

Makefile

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,11 @@ include shared.mak
471471
#
472472
# CURL_LDFLAGS=-lcurl
473473
#
474+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
475+
# if Multiple libcurl versions exist (with different file names) that link to
476+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
477+
# such a scenario.
478+
#
474479
# === Optional library: libpcre2 ===
475480
#
476481
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1641,10 +1646,23 @@ else
16411646
CURL_LIBCURL =
16421647
endif
16431648

1644-
ifndef CURL_LDFLAGS
1645-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1649+
ifdef LAZYLOAD_LIBCURL
1650+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1651+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1652+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1653+
# declared as DLL imports
1654+
CURL_CFLAGS = -DCURL_STATICLIB
1655+
ifneq ($(uname_S),MINGW)
1656+
ifneq ($(uname_S),Windows)
1657+
CURL_LIBCURL = -ldl
1658+
endif
1659+
endif
1660+
else
1661+
ifndef CURL_LDFLAGS
1662+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1663+
endif
1664+
CURL_LIBCURL += $(CURL_LDFLAGS)
16461665
endif
1647-
CURL_LIBCURL += $(CURL_LDFLAGS)
16481666

16491667
ifndef CURL_CFLAGS
16501668
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1665,7 +1683,7 @@ else
16651683
endif
16661684
ifdef USE_CURL_FOR_IMAP_SEND
16671685
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1668-
IMAP_SEND_BUILDDEPS = http.o
1686+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16691687
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16701688
endif
16711689
ifndef NO_EXPAT
@@ -2910,10 +2928,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
29102928
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29112929
$(IMAP_SEND_LDFLAGS) $(LIBS)
29122930

2913-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2931+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29142932
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29152933
$(CURL_LIBCURL) $(LIBS)
2916-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2934+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29172935
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29182936
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29192937

@@ -2923,7 +2941,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
29232941
ln -s $< $@ 2>/dev/null || \
29242942
cp $< $@
29252943

2926-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2944+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29272945
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29282946
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29292947

0 commit comments

Comments
 (0)