Skip to content

Commit fc632bc

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 a5a3edb + 126c854 commit fc632bc

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
@@ -1637,10 +1642,23 @@ else
16371642
CURL_LIBCURL =
16381643
endif
16391644

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

16451663
ifndef CURL_CFLAGS
16461664
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1661,7 +1679,7 @@ else
16611679
endif
16621680
ifdef USE_CURL_FOR_IMAP_SEND
16631681
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1664-
IMAP_SEND_BUILDDEPS = http.o
1682+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16651683
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16661684
endif
16671685
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)