• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21# SPDX-License-Identifier: curl
22#
23#***************************************************************************
24
25AC_DEFUN([CURL_WITH_RUSTLS], [
26dnl ----------------------------------------------------
27dnl check for Rustls
28dnl ----------------------------------------------------
29
30if test "x$OPT_RUSTLS" != xno; then
31  ssl_msg=
32
33  dnl backup the pre-ssl variables
34  CLEANLDFLAGS="$LDFLAGS"
35  CLEANLDFLAGSPC="$LDFLAGSPC"
36  CLEANCPPFLAGS="$CPPFLAGS"
37
38  ## NEW CODE
39
40  dnl use pkg-config unless we have been given a path
41  dnl even then, try pkg-config first
42
43  case "$OPT_RUSTLS" in
44    yes)
45      dnl --with-rustls (without path) used
46      PKGTEST="yes"
47      PREFIX_RUSTLS=
48      ;;
49    *)
50      dnl check the provided --with-rustls path
51      PKGTEST="no"
52      PREFIX_RUSTLS=$OPT_RUSTLS
53
54      dnl Try pkg-config even when cross-compiling.  Since we
55      dnl specify PKG_CONFIG_LIBDIR we are only looking where
56      dnl the user told us to look
57
58      RUSTLS_PCDIR="$PREFIX_RUSTLS/lib/pkgconfig"
59      if test -f "$RUSTLS_PCDIR/rustls.pc"; then
60        AC_MSG_NOTICE([PKG_CONFIG_LIBDIR will be set to "$RUSTLS_PCDIR"])
61        PKGTEST="yes"
62      fi
63
64      if test "$PKGTEST" != "yes"; then
65        # try lib64 instead
66        RUSTLS_PCDIR="$PREFIX_RUSTLS/lib64/pkgconfig"
67        if test -f "$RUSTLS_PCDIR/rustls.pc"; then
68          AC_MSG_NOTICE([PKG_CONFIG_LIBDIR will be set to "$RUSTLS_PCDIR"])
69          PKGTEST="yes"
70        fi
71      fi
72
73      if test "$PKGTEST" != "yes"; then
74        dnl pkg-config came up empty, use what we got
75        dnl via --with-rustls
76
77        addld=-L$PREFIX_RUSTLS/lib$libsuff
78        addcflags=-I$PREFIX_RUSTLS/include
79
80        LDFLAGS="$LDFLAGS $addld"
81        LDFLAGSPC="$LDFLAGSPC $addld"
82        if test "$addcflags" != "-I/usr/include"; then
83            CPPFLAGS="$CPPFLAGS $addcflags"
84        fi
85
86        case $host in
87          *-apple-*)
88            RUSTLS_LDFLAGS="-framework Security -framework Foundation"
89            ;;
90          *)
91            RUSTLS_LDFLAGS="-lpthread -ldl -lm"
92            ;;
93        esac
94        AC_CHECK_LIB(rustls, rustls_connection_read,
95          [
96          AC_DEFINE(USE_RUSTLS, 1, [if Rustls is enabled])
97          RUSTLS_ENABLED=1
98          USE_RUSTLS="yes"
99          ssl_msg="rustls"
100          test rustls != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
101          ],
102          AC_MSG_ERROR([--with-rustls was specified but could not find Rustls.]),
103          $RUSTLS_LDFLAGS)
104
105        LIB_RUSTLS="$PREFIX_RUSTLS/lib$libsuff"
106        if test "$PREFIX_RUSTLS" != "/usr" ; then
107          SSL_LDFLAGS="-L$LIB_RUSTLS $RUSTLS_LDFLAGS"
108          SSL_CPPFLAGS="-I$PREFIX_RUSTLS/include"
109        fi
110      fi
111      ;;
112  esac
113
114  link_pkgconfig=''
115
116  if test "$PKGTEST" = "yes"; then
117
118    CURL_CHECK_PKGCONFIG(rustls, [$RUSTLS_PCDIR])
119
120    if test "$PKGCONFIG" != "no" ; then
121      SSL_LIBS=`CURL_EXPORT_PCDIR([$RUSTLS_PCDIR]) dnl
122        $PKGCONFIG --libs-only-l --libs-only-other rustls 2>/dev/null`
123
124      SSL_LDFLAGS=`CURL_EXPORT_PCDIR([$RUSTLS_PCDIR]) dnl
125        $PKGCONFIG --libs-only-L rustls 2>/dev/null`
126
127      SSL_CPPFLAGS=`CURL_EXPORT_PCDIR([$RUSTLS_PCDIR]) dnl
128        $PKGCONFIG --cflags-only-I rustls 2>/dev/null`
129
130      AC_MSG_NOTICE([pkg-config: SSL_LIBS: "$SSL_LIBS"])
131      AC_MSG_NOTICE([pkg-config: SSL_LDFLAGS: "$SSL_LDFLAGS"])
132      AC_MSG_NOTICE([pkg-config: SSL_CPPFLAGS: "$SSL_CPPFLAGS"])
133
134      LIB_RUSTLS=`echo $SSL_LDFLAGS | sed -e 's/^-L//'`
135
136      dnl use the values pkg-config reported.  This is here
137      dnl instead of below with CPPFLAGS and LDFLAGS because we only
138      dnl learn about this via pkg-config.  If we only have
139      dnl the argument to --with-rustls we don't know what
140      dnl additional libs may be necessary.  Hope that we
141      dnl don't need any.
142      LIBS="$SSL_LIBS $LIBS"
143      link_pkgconfig=1
144      ssl_msg="rustls"
145      AC_DEFINE(USE_RUSTLS, 1, [if Rustls is enabled])
146      USE_RUSTLS="yes"
147      RUSTLS_ENABLED=1
148      test rustls != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
149    else
150      AC_MSG_ERROR([pkg-config: Could not find Rustls])
151    fi
152
153  else
154    dnl we did not use pkg-config, so we need to add the
155    dnl Rustls lib to LIBS
156    LIBS="-lrustls -lpthread -ldl -lm $LIBS"
157  fi
158
159  dnl finally, set flags to use this TLS backend
160  CPPFLAGS="$CLEANCPPFLAGS $SSL_CPPFLAGS"
161  LDFLAGS="$CLEANLDFLAGS $SSL_LDFLAGS"
162  LDFLAGSPC="$CLEANLDFLAGSPC $SSL_LDFLAGS"
163
164  if test "x$USE_RUSTLS" = "xyes"; then
165    AC_MSG_NOTICE([detected Rustls])
166    check_for_ca_bundle=1
167
168    if test -n "$LIB_RUSTLS"; then
169      dnl when shared libs were found in a path that the run-time
170      dnl linker does not search through, we need to add it to
171      dnl CURL_LIBRARY_PATH so that further configure tests do not
172      dnl fail due to this
173      if test "x$cross_compiling" != "xyes"; then
174        CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$LIB_RUSTLS"
175        export CURL_LIBRARY_PATH
176        AC_MSG_NOTICE([Added $LIB_RUSTLS to CURL_LIBRARY_PATH])
177      fi
178    fi
179    if test -n "$link_pkgconfig"; then
180      LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE rustls"
181    fi
182  fi
183
184  test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg"
185
186  if test X"$OPT_RUSTLS" != Xno &&
187    test "$RUSTLS_ENABLED" != "1"; then
188    AC_MSG_NOTICE([OPT_RUSTLS: $OPT_RUSTLS])
189    AC_MSG_NOTICE([RUSTLS_ENABLED: $RUSTLS_ENABLED])
190    AC_MSG_ERROR([--with-rustls was given but Rustls could not be detected])
191  fi
192fi
193])
194
195RUSTLS_ENABLED
196