Skip to content

Commit 213112e

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 fa8ed1a + f079352 commit 213112e

File tree

3 files changed

+434
-7
lines changed

3 files changed

+434
-7
lines changed

Makefile

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,11 @@ include shared.mak
464464
#
465465
# CURL_LDFLAGS=-lcurl
466466
#
467+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
468+
# if Multiple libcurl versions exist (with different file names) that link to
469+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
470+
# such a scenario.
471+
#
467472
# === Optional library: libpcre2 ===
468473
#
469474
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1612,10 +1617,23 @@ else
16121617
CURL_LIBCURL =
16131618
endif
16141619

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

16201638
ifndef CURL_CFLAGS
16211639
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1636,7 +1654,7 @@ else
16361654
endif
16371655
ifdef USE_CURL_FOR_IMAP_SEND
16381656
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1639-
IMAP_SEND_BUILDDEPS = http.o
1657+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16401658
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16411659
endif
16421660
ifndef NO_EXPAT
@@ -2843,10 +2861,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28432861
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28442862
$(IMAP_SEND_LDFLAGS) $(LIBS)
28452863

2846-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2864+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28472865
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28482866
$(CURL_LIBCURL) $(LIBS)
2849-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2867+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28502868
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28512869
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28522870

@@ -2856,7 +2874,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28562874
ln -s $< $@ 2>/dev/null || \
28572875
cp $< $@
28582876

2859-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2877+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28602878
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28612879
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28622880

0 commit comments

Comments
 (0)