Skip to content

Commit 3e918b9

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 82d5902 + 2b8e751 commit 3e918b9

File tree

3 files changed

+444
-7
lines changed

3 files changed

+444
-7
lines changed

Makefile

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,11 @@ include shared.mak
471471
#
472472
# CURL_LDFLAGS=-lcurl
473473
#
474+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
475+
# if Multiple libcurl versions exist (with different file names) that link to
476+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
477+
# such a scenario.
478+
#
474479
# === Optional library: libpcre2 ===
475480
#
476481
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1643,10 +1648,23 @@ else
16431648
CURL_LIBCURL =
16441649
endif
16451650

1646-
ifndef CURL_LDFLAGS
1647-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1651+
ifdef LAZYLOAD_LIBCURL
1652+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1653+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1654+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1655+
# declared as DLL imports
1656+
CURL_CFLAGS = -DCURL_STATICLIB
1657+
ifneq ($(uname_S),MINGW)
1658+
ifneq ($(uname_S),Windows)
1659+
CURL_LIBCURL = -ldl
1660+
endif
1661+
endif
1662+
else
1663+
ifndef CURL_LDFLAGS
1664+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1665+
endif
1666+
CURL_LIBCURL += $(CURL_LDFLAGS)
16481667
endif
1649-
CURL_LIBCURL += $(CURL_LDFLAGS)
16501668

16511669
ifndef CURL_CFLAGS
16521670
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1667,7 +1685,7 @@ else
16671685
endif
16681686
ifdef USE_CURL_FOR_IMAP_SEND
16691687
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1670-
IMAP_SEND_BUILDDEPS = http.o
1688+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16711689
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16721690
endif
16731691
ifndef NO_EXPAT
@@ -2914,10 +2932,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
29142932
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29152933
$(IMAP_SEND_LDFLAGS) $(LIBS)
29162934

2917-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2935+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29182936
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29192937
$(CURL_LIBCURL) $(LIBS)
2920-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2938+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29212939
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29222940
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29232941

@@ -2927,7 +2945,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
29272945
ln -s $< $@ 2>/dev/null || \
29282946
cp $< $@
29292947

2930-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2948+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29312949
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29322950
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29332951

0 commit comments

Comments
 (0)