Skip to content

Commit f4fe902

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
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 8cf90a9 + de3442b commit f4fe902

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
@@ -475,6 +475,11 @@ include shared.mak
475475
#
476476
# CURL_LDFLAGS=-lcurl
477477
#
478+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
479+
# if Multiple libcurl versions exist (with different file names) that link to
480+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
481+
# such a scenario.
482+
#
478483
# === Optional library: libpcre2 ===
479484
#
480485
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1662,10 +1667,23 @@ else
16621667
CURL_LIBCURL =
16631668
endif
16641669

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

16701688
ifndef CURL_CFLAGS
16711689
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1686,7 +1704,7 @@ else
16861704
endif
16871705
ifdef USE_CURL_FOR_IMAP_SEND
16881706
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1689-
IMAP_SEND_BUILDDEPS = http.o
1707+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16901708
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16911709
endif
16921710
ifndef NO_EXPAT
@@ -2925,10 +2943,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
29252943
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29262944
$(IMAP_SEND_LDFLAGS) $(LIBS)
29272945

2928-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2946+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29292947
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29302948
$(CURL_LIBCURL) $(LIBS)
2931-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2949+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29322950
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29332951
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29342952

@@ -2938,7 +2956,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
29382956
ln -s $< $@ 2>/dev/null || \
29392957
cp $< $@
29402958

2941-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2959+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29422960
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29432961
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29442962

0 commit comments

Comments
 (0)