Skip to content

Commit 5294500

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 11facf5 + 6f97fbb commit 5294500

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
@@ -1636,10 +1641,23 @@ else
16361641
CURL_LIBCURL =
16371642
endif
16381643

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

16441662
ifndef CURL_CFLAGS
16451663
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1660,7 +1678,7 @@ else
16601678
endif
16611679
ifdef USE_CURL_FOR_IMAP_SEND
16621680
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1663-
IMAP_SEND_BUILDDEPS = http.o
1681+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16641682
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16651683
endif
16661684
ifndef NO_EXPAT
@@ -2883,10 +2901,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28832901
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28842902
$(IMAP_SEND_LDFLAGS) $(LIBS)
28852903

2886-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2904+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28872905
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28882906
$(CURL_LIBCURL) $(LIBS)
2889-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2907+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28902908
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28912909
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28922910

@@ -2896,7 +2914,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28962914
ln -s $< $@ 2>/dev/null || \
28972915
cp $< $@
28982916

2899-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2917+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29002918
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29012919
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29022920

0 commit comments

Comments
 (0)