Skip to content

Commit 8238a5b

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 1690260 + 246c049 commit 8238a5b

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
@@ -467,6 +467,11 @@ include shared.mak
467467
#
468468
# CURL_LDFLAGS=-lcurl
469469
#
470+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
471+
# if Multiple libcurl versions exist (with different file names) that link to
472+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
473+
# such a scenario.
474+
#
470475
# === Optional library: libpcre2 ===
471476
#
472477
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1617,10 +1622,23 @@ else
16171622
CURL_LIBCURL =
16181623
endif
16191624

1620-
ifndef CURL_LDFLAGS
1621-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1625+
ifdef LAZYLOAD_LIBCURL
1626+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1627+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1628+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1629+
# declared as DLL imports
1630+
CURL_CFLAGS = -DCURL_STATICLIB
1631+
ifneq ($(uname_S),MINGW)
1632+
ifneq ($(uname_S),Windows)
1633+
CURL_LIBCURL = -ldl
1634+
endif
1635+
endif
1636+
else
1637+
ifndef CURL_LDFLAGS
1638+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1639+
endif
1640+
CURL_LIBCURL += $(CURL_LDFLAGS)
16221641
endif
1623-
CURL_LIBCURL += $(CURL_LDFLAGS)
16241642

16251643
ifndef CURL_CFLAGS
16261644
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1641,7 +1659,7 @@ else
16411659
endif
16421660
ifdef USE_CURL_FOR_IMAP_SEND
16431661
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1644-
IMAP_SEND_BUILDDEPS = http.o
1662+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16451663
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16461664
endif
16471665
ifndef NO_EXPAT
@@ -2869,10 +2887,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28692887
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28702888
$(IMAP_SEND_LDFLAGS) $(LIBS)
28712889

2872-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2890+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28732891
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28742892
$(CURL_LIBCURL) $(LIBS)
2875-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2893+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28762894
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28772895
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28782896

@@ -2882,7 +2900,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28822900
ln -s $< $@ 2>/dev/null || \
28832901
cp $< $@
28842902

2885-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2903+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28862904
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28872905
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28882906

0 commit comments

Comments
 (0)