Skip to content

Commit

Permalink
Lazy load libcurl, allowing for an SSL/TLS backend-specific libcurl (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
dscho committed Jan 7, 2025
2 parents 94fb910 + 8b11498 commit 95e1b1b
Show file tree
Hide file tree
Showing 3 changed files with 444 additions and 7 deletions.
32 changes: 25 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@ include shared.mak
#
# CURL_LDFLAGS=-lcurl
#
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
# if Multiple libcurl versions exist (with different file names) that link to
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
# such a scenario.
#
# === Optional library: libpcre2 ===
#
# Define USE_LIBPCRE if you have and want to use libpcre. Various
Expand Down Expand Up @@ -1644,10 +1649,23 @@ else
CURL_LIBCURL =
endif

ifndef CURL_LDFLAGS
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
ifdef LAZYLOAD_LIBCURL
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
# declared as DLL imports
CURL_CFLAGS = -DCURL_STATICLIB
ifneq ($(uname_S),MINGW)
ifneq ($(uname_S),Windows)
CURL_LIBCURL = -ldl
endif
endif
else
ifndef CURL_LDFLAGS
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
endif
CURL_LIBCURL += $(CURL_LDFLAGS)
endif
CURL_LIBCURL += $(CURL_LDFLAGS)

ifndef CURL_CFLAGS
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
Expand All @@ -1668,7 +1686,7 @@ else
endif
ifdef USE_CURL_FOR_IMAP_SEND
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
IMAP_SEND_BUILDDEPS = http.o
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
endif
ifndef NO_EXPAT
Expand Down Expand Up @@ -2885,10 +2903,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(IMAP_SEND_LDFLAGS) $(LIBS)

git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(CURL_LIBCURL) $(LIBS)
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)

Expand All @@ -2898,7 +2916,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
ln -s $< $@ 2>/dev/null || \
cp $< $@

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

Expand Down
Loading

0 comments on commit 95e1b1b

Please sign in to comment.