Skip to content

Commit 1f7adf3

Browse files
dschoGit for Windows Build Agent
authored andcommitted
Lazy load libcurl, allowing for an SSL/TLS backend-specific libcurl (git-for-windows#4410)
As per git-for-windows#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 a9278fd + 9797449 commit 1f7adf3

3 files changed

Lines changed: 454 additions & 7 deletions

File tree

Makefile

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@ include shared.mak
483483
#
484484
# CURL_LDFLAGS=-lcurl
485485
#
486+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
487+
# if Multiple libcurl versions exist (with different file names) that link to
488+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
489+
# such a scenario.
490+
#
486491
# === Optional library: libpcre2 ===
487492
#
488493
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1791,10 +1796,23 @@ else
17911796
CURL_LIBCURL =
17921797
endif
17931798

1794-
ifndef CURL_LDFLAGS
1795-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1799+
ifdef LAZYLOAD_LIBCURL
1800+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1801+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1802+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1803+
# declared as DLL imports
1804+
CURL_CFLAGS = -DCURL_STATICLIB
1805+
ifneq ($(uname_S),MINGW)
1806+
ifneq ($(uname_S),Windows)
1807+
CURL_LIBCURL = -ldl
1808+
endif
1809+
endif
1810+
else
1811+
ifndef CURL_LDFLAGS
1812+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1813+
endif
1814+
CURL_LIBCURL += $(CURL_LDFLAGS)
17961815
endif
1797-
CURL_LIBCURL += $(CURL_LDFLAGS)
17981816

17991817
ifndef CURL_CFLAGS
18001818
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1815,7 +1833,7 @@ else
18151833
endif
18161834
ifdef USE_CURL_FOR_IMAP_SEND
18171835
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1818-
IMAP_SEND_BUILDDEPS = http.o
1836+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
18191837
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
18201838
endif
18211839
ifndef NO_EXPAT
@@ -3050,10 +3068,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
30503068
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
30513069
$(IMAP_SEND_LDFLAGS) $(LIBS)
30523070

3053-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
3071+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
30543072
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
30553073
$(CURL_LIBCURL) $(LIBS)
3056-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
3074+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
30573075
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
30583076
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
30593077

@@ -3063,7 +3081,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
30633081
ln -s $< $@ 2>/dev/null || \
30643082
cp $< $@
30653083

3066-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
3084+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
30673085
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
30683086
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
30693087

0 commit comments

Comments
 (0)