Skip to content

Commit 0ef0ace

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 ddb63a6 + b93f7a0 commit 0ef0ace

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
@@ -1636,10 +1641,23 @@ else
16361641
CURL_LIBCURL =
16371642
endif
16381643

1639-
ifndef CURL_LDFLAGS
1640-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1644+
ifdef LAZYLOAD_LIBCURL
1645+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1646+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1647+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1648+
# declared as DLL imports
1649+
CURL_CFLAGS = -DCURL_STATICLIB
1650+
ifneq ($(uname_S),MINGW)
1651+
ifneq ($(uname_S),Windows)
1652+
CURL_LIBCURL = -ldl
1653+
endif
1654+
endif
1655+
else
1656+
ifndef CURL_LDFLAGS
1657+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1658+
endif
1659+
CURL_LIBCURL += $(CURL_LDFLAGS)
16411660
endif
1642-
CURL_LIBCURL += $(CURL_LDFLAGS)
16431661

16441662
ifndef CURL_CFLAGS
16451663
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1660,7 +1678,7 @@ else
16601678
endif
16611679
ifdef USE_CURL_FOR_IMAP_SEND
16621680
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1663-
IMAP_SEND_BUILDDEPS = http.o
1681+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16641682
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16651683
endif
16661684
ifndef NO_EXPAT
@@ -2872,10 +2890,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28722890
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28732891
$(IMAP_SEND_LDFLAGS) $(LIBS)
28742892

2875-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2893+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28762894
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28772895
$(CURL_LIBCURL) $(LIBS)
2878-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2896+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28792897
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28802898
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28812899

@@ -2885,7 +2903,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28852903
ln -s $< $@ 2>/dev/null || \
28862904
cp $< $@
28872905

2888-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2906+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28892907
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28902908
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28912909

0 commit comments

Comments
 (0)