Skip to content

Commit d207526

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 f34a864 + 9f3317b commit d207526

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
@@ -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
@@ -1665,10 +1670,23 @@ else
16651670
CURL_LIBCURL =
16661671
endif
16671672

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

16731691
ifndef CURL_CFLAGS
16741692
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1689,7 +1707,7 @@ else
16891707
endif
16901708
ifdef USE_CURL_FOR_IMAP_SEND
16911709
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1692-
IMAP_SEND_BUILDDEPS = http.o
1710+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16931711
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16941712
endif
16951713
ifndef NO_EXPAT
@@ -2936,10 +2954,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
29362954
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29372955
$(IMAP_SEND_LDFLAGS) $(LIBS)
29382956

2939-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2957+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29402958
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29412959
$(CURL_LIBCURL) $(LIBS)
2942-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2960+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29432961
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29442962
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29452963

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

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

0 commit comments

Comments
 (0)