Skip to content

Commit 1d1d34c

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 7a3b0bf + 4733873 commit 1d1d34c

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
@@ -1648,10 +1653,23 @@ else
16481653
CURL_LIBCURL =
16491654
endif
16501655

1651-
ifndef CURL_LDFLAGS
1652-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1656+
ifdef LAZYLOAD_LIBCURL
1657+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1658+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1659+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1660+
# declared as DLL imports
1661+
CURL_CFLAGS = -DCURL_STATICLIB
1662+
ifneq ($(uname_S),MINGW)
1663+
ifneq ($(uname_S),Windows)
1664+
CURL_LIBCURL = -ldl
1665+
endif
1666+
endif
1667+
else
1668+
ifndef CURL_LDFLAGS
1669+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1670+
endif
1671+
CURL_LIBCURL += $(CURL_LDFLAGS)
16531672
endif
1654-
CURL_LIBCURL += $(CURL_LDFLAGS)
16551673

16561674
ifndef CURL_CFLAGS
16571675
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1672,7 +1690,7 @@ else
16721690
endif
16731691
ifdef USE_CURL_FOR_IMAP_SEND
16741692
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1675-
IMAP_SEND_BUILDDEPS = http.o
1693+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16761694
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16771695
endif
16781696
ifndef NO_EXPAT
@@ -2887,10 +2905,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28872905
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28882906
$(IMAP_SEND_LDFLAGS) $(LIBS)
28892907

2890-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2908+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28912909
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28922910
$(CURL_LIBCURL) $(LIBS)
2893-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2911+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28942912
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28952913
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28962914

@@ -2900,7 +2918,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
29002918
ln -s $< $@ 2>/dev/null || \
29012919
cp $< $@
29022920

2903-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2921+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29042922
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29052923
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29062924

0 commit comments

Comments
 (0)