Skip to content

Commit 595c63a

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 35637c7 + b53313c commit 595c63a

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
@@ -470,6 +470,11 @@ include shared.mak
470470
#
471471
# CURL_LDFLAGS=-lcurl
472472
#
473+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
474+
# if Multiple libcurl versions exist (with different file names) that link to
475+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
476+
# such a scenario.
477+
#
473478
# === Optional library: libpcre2 ===
474479
#
475480
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1664,10 +1669,23 @@ else
16641669
CURL_LIBCURL =
16651670
endif
16661671

1667-
ifndef CURL_LDFLAGS
1668-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1672+
ifdef LAZYLOAD_LIBCURL
1673+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1674+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1675+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1676+
# declared as DLL imports
1677+
CURL_CFLAGS = -DCURL_STATICLIB
1678+
ifneq ($(uname_S),MINGW)
1679+
ifneq ($(uname_S),Windows)
1680+
CURL_LIBCURL = -ldl
1681+
endif
1682+
endif
1683+
else
1684+
ifndef CURL_LDFLAGS
1685+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1686+
endif
1687+
CURL_LIBCURL += $(CURL_LDFLAGS)
16691688
endif
1670-
CURL_LIBCURL += $(CURL_LDFLAGS)
16711689

16721690
ifndef CURL_CFLAGS
16731691
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1688,7 +1706,7 @@ else
16881706
endif
16891707
ifdef USE_CURL_FOR_IMAP_SEND
16901708
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1691-
IMAP_SEND_BUILDDEPS = http.o
1709+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16921710
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16931711
endif
16941712
ifndef NO_EXPAT
@@ -2934,10 +2952,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
29342952
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29352953
$(IMAP_SEND_LDFLAGS) $(LIBS)
29362954

2937-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2955+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29382956
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29392957
$(CURL_LIBCURL) $(LIBS)
2940-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2958+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29412959
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29422960
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29432961

@@ -2947,7 +2965,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
29472965
ln -s $< $@ 2>/dev/null || \
29482966
cp $< $@
29492967

2950-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2968+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29512969
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29522970
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29532971

0 commit comments

Comments
 (0)