Skip to content

Commit 95e1b1b

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 94fb910 + 8b11498 commit 95e1b1b

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
@@ -1644,10 +1649,23 @@ else
16441649
CURL_LIBCURL =
16451650
endif
16461651

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

16521670
ifndef CURL_CFLAGS
16531671
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1668,7 +1686,7 @@ else
16681686
endif
16691687
ifdef USE_CURL_FOR_IMAP_SEND
16701688
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1671-
IMAP_SEND_BUILDDEPS = http.o
1689+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16721690
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16731691
endif
16741692
ifndef NO_EXPAT
@@ -2885,10 +2903,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28852903
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28862904
$(IMAP_SEND_LDFLAGS) $(LIBS)
28872905

2888-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2906+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28892907
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28902908
$(CURL_LIBCURL) $(LIBS)
2891-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2909+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28922910
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28932911
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28942912

@@ -2898,7 +2916,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28982916
ln -s $< $@ 2>/dev/null || \
28992917
cp $< $@
29002918

2901-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2919+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29022920
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29032921
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29042922

0 commit comments

Comments
 (0)