Skip to content

Commit ffeaced

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 9d0fc72 + b7fddfa commit ffeaced

File tree

3 files changed

+418
-7
lines changed

3 files changed

+418
-7
lines changed

Makefile

+25-7
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
@@ -1598,10 +1603,23 @@ else
15981603
CURL_LIBCURL =
15991604
endif
16001605

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

16061624
ifndef CURL_CFLAGS
16071625
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1622,7 +1640,7 @@ else
16221640
endif
16231641
ifdef USE_CURL_FOR_IMAP_SEND
16241642
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1625-
IMAP_SEND_BUILDDEPS = http.o
1643+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16261644
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16271645
endif
16281646
ifndef NO_EXPAT
@@ -2828,10 +2846,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28282846
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28292847
$(IMAP_SEND_LDFLAGS) $(LIBS)
28302848

2831-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2849+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28322850
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28332851
$(CURL_LIBCURL) $(LIBS)
2834-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2852+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28352853
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28362854
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28372855

@@ -2841,7 +2859,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28412859
ln -s $< $@ 2>/dev/null || \
28422860
cp $< $@
28432861

2844-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2862+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28452863
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28462864
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28472865

0 commit comments

Comments
 (0)