Skip to content

Commit 3478624

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 cd43d7e + 377d1a7 commit 3478624

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
@@ -1719,10 +1724,23 @@ else
17191724
CURL_LIBCURL =
17201725
endif
17211726

1722-
ifndef CURL_LDFLAGS
1723-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1727+
ifdef LAZYLOAD_LIBCURL
1728+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1729+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1730+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1731+
# declared as DLL imports
1732+
CURL_CFLAGS = -DCURL_STATICLIB
1733+
ifneq ($(uname_S),MINGW)
1734+
ifneq ($(uname_S),Windows)
1735+
CURL_LIBCURL = -ldl
1736+
endif
1737+
endif
1738+
else
1739+
ifndef CURL_LDFLAGS
1740+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1741+
endif
1742+
CURL_LIBCURL += $(CURL_LDFLAGS)
17241743
endif
1725-
CURL_LIBCURL += $(CURL_LDFLAGS)
17261744

17271745
ifndef CURL_CFLAGS
17281746
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1743,7 +1761,7 @@ else
17431761
endif
17441762
ifdef USE_CURL_FOR_IMAP_SEND
17451763
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1746-
IMAP_SEND_BUILDDEPS = http.o
1764+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
17471765
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
17481766
endif
17491767
ifndef NO_EXPAT
@@ -2964,10 +2982,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
29642982
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29652983
$(IMAP_SEND_LDFLAGS) $(LIBS)
29662984

2967-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2985+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29682986
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29692987
$(CURL_LIBCURL) $(LIBS)
2970-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2988+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29712989
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29722990
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29732991

@@ -2977,7 +2995,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
29772995
ln -s $< $@ 2>/dev/null || \
29782996
cp $< $@
29792997

2980-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2998+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29812999
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29823000
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29833001

0 commit comments

Comments
 (0)