Skip to content

Commit 95007f9

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 f30c69f + 832608c commit 95007f9

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
@@ -1600,10 +1605,23 @@ else
16001605
CURL_LIBCURL =
16011606
endif
16021607

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

16081626
ifndef CURL_CFLAGS
16091627
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1624,7 +1642,7 @@ else
16241642
endif
16251643
ifdef USE_CURL_FOR_IMAP_SEND
16261644
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1627-
IMAP_SEND_BUILDDEPS = http.o
1645+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16281646
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16291647
endif
16301648
ifndef NO_EXPAT
@@ -2830,10 +2848,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28302848
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28312849
$(IMAP_SEND_LDFLAGS) $(LIBS)
28322850

2833-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2851+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28342852
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28352853
$(CURL_LIBCURL) $(LIBS)
2836-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2854+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28372855
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28382856
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28392857

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

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

0 commit comments

Comments
 (0)