Skip to content

Commit 846f9b1

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 cb4a62b + 366ce07 commit 846f9b1

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
@@ -472,6 +472,11 @@ include shared.mak
472472
#
473473
# CURL_LDFLAGS=-lcurl
474474
#
475+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
476+
# if Multiple libcurl versions exist (with different file names) that link to
477+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
478+
# such a scenario.
479+
#
475480
# === Optional library: libpcre2 ===
476481
#
477482
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1667,10 +1672,23 @@ else
16671672
CURL_LIBCURL =
16681673
endif
16691674

1670-
ifndef CURL_LDFLAGS
1671-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1675+
ifdef LAZYLOAD_LIBCURL
1676+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1677+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1678+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1679+
# declared as DLL imports
1680+
CURL_CFLAGS = -DCURL_STATICLIB
1681+
ifneq ($(uname_S),MINGW)
1682+
ifneq ($(uname_S),Windows)
1683+
CURL_LIBCURL = -ldl
1684+
endif
1685+
endif
1686+
else
1687+
ifndef CURL_LDFLAGS
1688+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1689+
endif
1690+
CURL_LIBCURL += $(CURL_LDFLAGS)
16721691
endif
1673-
CURL_LIBCURL += $(CURL_LDFLAGS)
16741692

16751693
ifndef CURL_CFLAGS
16761694
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1691,7 +1709,7 @@ else
16911709
endif
16921710
ifdef USE_CURL_FOR_IMAP_SEND
16931711
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1694-
IMAP_SEND_BUILDDEPS = http.o
1712+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16951713
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16961714
endif
16971715
ifndef NO_EXPAT
@@ -2938,10 +2956,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
29382956
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29392957
$(IMAP_SEND_LDFLAGS) $(LIBS)
29402958

2941-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2959+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29422960
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29432961
$(CURL_LIBCURL) $(LIBS)
2944-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2962+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29452963
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29462964
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29472965

@@ -2951,7 +2969,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
29512969
ln -s $< $@ 2>/dev/null || \
29522970
cp $< $@
29532971

2954-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2972+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29552973
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29562974
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29572975

0 commit comments

Comments
 (0)