Skip to content

Commit 2082f05

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 980a814 + 7a4bd14 commit 2082f05

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
@@ -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)
@@ -2818,14 +2836,14 @@ headless-git$X: headless-git.o git.res GIT-LDFLAGS
28182836
git-%$X: %.o GIT-LDFLAGS $(GITLIBS)
28192837
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
28202838

2821-
git-imap-send$X: imap-send.o http.o GIT-LDFLAGS $(GITLIBS)
2839+
git-imap-send$X: imap-send.o http.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28222840
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28232841
$(IMAP_SEND_LDFLAGS) $(LIBS)
28242842

2825-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2843+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28262844
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28272845
$(CURL_LIBCURL) $(LIBS)
2828-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2846+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28292847
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28302848
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28312849

@@ -2835,7 +2853,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28352853
ln -s $< $@ 2>/dev/null || \
28362854
cp $< $@
28372855

2838-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2856+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.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

0 commit comments

Comments
 (0)