Skip to content

Commit 6bb7644

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 df6c88e + b756a0f commit 6bb7644

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
@@ -475,6 +475,11 @@ include shared.mak
475475
#
476476
# CURL_LDFLAGS=-lcurl
477477
#
478+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
479+
# if Multiple libcurl versions exist (with different file names) that link to
480+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
481+
# such a scenario.
482+
#
478483
# === Optional library: libpcre2 ===
479484
#
480485
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1668,10 +1673,23 @@ else
16681673
CURL_LIBCURL =
16691674
endif
16701675

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

16761694
ifndef CURL_CFLAGS
16771695
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1692,7 +1710,7 @@ else
16921710
endif
16931711
ifdef USE_CURL_FOR_IMAP_SEND
16941712
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1695-
IMAP_SEND_BUILDDEPS = http.o
1713+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16961714
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16971715
endif
16981716
ifndef NO_EXPAT
@@ -2944,10 +2962,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
29442962
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29452963
$(IMAP_SEND_LDFLAGS) $(LIBS)
29462964

2947-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2965+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29482966
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29492967
$(CURL_LIBCURL) $(LIBS)
2950-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2968+
git-http-push$X: http.o http-push.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

@@ -2957,7 +2975,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
29572975
ln -s $< $@ 2>/dev/null || \
29582976
cp $< $@
29592977

2960-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2978+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29612979
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29622980
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29632981

0 commit comments

Comments
 (0)