Skip to content

Commit 69ed455

Browse files
authored
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 a02883f + 2948d32 commit 69ed455

File tree

3 files changed

+418
-7
lines changed

3 files changed

+418
-7
lines changed

Makefile

+25-7
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,11 @@ include shared.mak
468468
#
469469
# CURL_LDFLAGS=-lcurl
470470
#
471+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
472+
# if Multiple libcurl versions exist (with different file names) that link to
473+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
474+
# such a scenario.
475+
#
471476
# === Optional library: libpcre2 ===
472477
#
473478
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1603,10 +1608,23 @@ else
16031608
CURL_LIBCURL =
16041609
endif
16051610

1606-
ifndef CURL_LDFLAGS
1607-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1611+
ifdef LAZYLOAD_LIBCURL
1612+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1613+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1614+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1615+
# declared as DLL imports
1616+
CURL_CFLAGS = -DCURL_STATICLIB
1617+
ifneq ($(uname_S),MINGW)
1618+
ifneq ($(uname_S),Windows)
1619+
CURL_LIBCURL = -ldl
1620+
endif
1621+
endif
1622+
else
1623+
ifndef CURL_LDFLAGS
1624+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1625+
endif
1626+
CURL_LIBCURL += $(CURL_LDFLAGS)
16081627
endif
1609-
CURL_LIBCURL += $(CURL_LDFLAGS)
16101628

16111629
ifndef CURL_CFLAGS
16121630
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1627,7 +1645,7 @@ else
16271645
endif
16281646
ifdef USE_CURL_FOR_IMAP_SEND
16291647
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1630-
IMAP_SEND_BUILDDEPS = http.o
1648+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16311649
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16321650
endif
16331651
ifndef NO_EXPAT
@@ -2833,10 +2851,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28332851
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28342852
$(IMAP_SEND_LDFLAGS) $(LIBS)
28352853

2836-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2854+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28372855
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28382856
$(CURL_LIBCURL) $(LIBS)
2839-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2857+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28402858
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28412859
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28422860

@@ -2846,7 +2864,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28462864
ln -s $< $@ 2>/dev/null || \
28472865
cp $< $@
28482866

2849-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2867+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.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

0 commit comments

Comments
 (0)