Skip to content

Commit 94f2a8a

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 f64a772 + 23ecf09 commit 94f2a8a

File tree

3 files changed

+418
-7
lines changed

3 files changed

+418
-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
@@ -1599,10 +1604,23 @@ else
15991604
CURL_LIBCURL =
16001605
endif
16011606

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

16071625
ifndef CURL_CFLAGS
16081626
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1623,7 +1641,7 @@ else
16231641
endif
16241642
ifdef USE_CURL_FOR_IMAP_SEND
16251643
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1626-
IMAP_SEND_BUILDDEPS = http.o
1644+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16271645
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16281646
endif
16291647
ifndef NO_EXPAT
@@ -2829,10 +2847,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28292847
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28302848
$(IMAP_SEND_LDFLAGS) $(LIBS)
28312849

2832-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2850+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28332851
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28342852
$(CURL_LIBCURL) $(LIBS)
2835-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2853+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28362854
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28372855
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28382856

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

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

0 commit comments

Comments
 (0)