Skip to content

Commit a1719f2

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 264a758 + 0441b29 commit a1719f2

File tree

3 files changed

+444
-7
lines changed

3 files changed

+444
-7
lines changed

Makefile

+25-7
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,11 @@ include shared.mak
472472
#
473473
# CURL_LDFLAGS=-lcurl
474474
#
475+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
476+
# if Multiple libcurl versions exist (with different file names) that link to
477+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
478+
# such a scenario.
479+
#
475480
# === Optional library: libpcre2 ===
476481
#
477482
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1666,10 +1671,23 @@ else
16661671
CURL_LIBCURL =
16671672
endif
16681673

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

16741692
ifndef CURL_CFLAGS
16751693
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1690,7 +1708,7 @@ else
16901708
endif
16911709
ifdef USE_CURL_FOR_IMAP_SEND
16921710
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1693-
IMAP_SEND_BUILDDEPS = http.o
1711+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16941712
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16951713
endif
16961714
ifndef NO_EXPAT
@@ -2937,10 +2955,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
29372955
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29382956
$(IMAP_SEND_LDFLAGS) $(LIBS)
29392957

2940-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2958+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29412959
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29422960
$(CURL_LIBCURL) $(LIBS)
2943-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2961+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29442962
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29452963
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29462964

@@ -2950,7 +2968,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
29502968
ln -s $< $@ 2>/dev/null || \
29512969
cp $< $@
29522970

2953-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2971+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29542972
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29552973
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29562974

0 commit comments

Comments
 (0)