Skip to content

Commit e7b5e52

Browse files
dschoGit for Windows Build Agent
authored andcommitted
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 1868cd0 + 8988880 commit e7b5e52

File tree

3 files changed

+434
-7
lines changed

3 files changed

+434
-7
lines changed

Makefile

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,11 @@ include shared.mak
464464
#
465465
# CURL_LDFLAGS=-lcurl
466466
#
467+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
468+
# if Multiple libcurl versions exist (with different file names) that link to
469+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
470+
# such a scenario.
471+
#
467472
# === Optional library: libpcre2 ===
468473
#
469474
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1602,10 +1607,23 @@ else
16021607
CURL_LIBCURL =
16031608
endif
16041609

1605-
ifndef CURL_LDFLAGS
1606-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1610+
ifdef LAZYLOAD_LIBCURL
1611+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1612+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1613+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1614+
# declared as DLL imports
1615+
CURL_CFLAGS = -DCURL_STATICLIB
1616+
ifneq ($(uname_S),MINGW)
1617+
ifneq ($(uname_S),Windows)
1618+
CURL_LIBCURL = -ldl
1619+
endif
1620+
endif
1621+
else
1622+
ifndef CURL_LDFLAGS
1623+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1624+
endif
1625+
CURL_LIBCURL += $(CURL_LDFLAGS)
16071626
endif
1608-
CURL_LIBCURL += $(CURL_LDFLAGS)
16091627

16101628
ifndef CURL_CFLAGS
16111629
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1626,7 +1644,7 @@ else
16261644
endif
16271645
ifdef USE_CURL_FOR_IMAP_SEND
16281646
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1629-
IMAP_SEND_BUILDDEPS = http.o
1647+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16301648
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16311649
endif
16321650
ifndef NO_EXPAT
@@ -2832,10 +2850,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28322850
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28332851
$(IMAP_SEND_LDFLAGS) $(LIBS)
28342852

2835-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2853+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28362854
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28372855
$(CURL_LIBCURL) $(LIBS)
2838-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2856+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28392857
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28402858
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28412859

@@ -2845,7 +2863,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28452863
ln -s $< $@ 2>/dev/null || \
28462864
cp $< $@
28472865

2848-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2866+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28492867
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28502868
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28512869

0 commit comments

Comments
 (0)