]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
configure.ac: determine if the Vista APIs can be linked statically
authorSteve Lhomme <robux4@ycbcr.xyz>
Wed, 27 May 2020 21:13:43 +0000 (21:13 +0000)
committerDmitry Baryshkov <dbaryshkov@gmail.com>
Wed, 27 May 2020 21:13:43 +0000 (21:13 +0000)
If _WIN32_WINNT is higher or equal to 0x0600, Vista API's are allowed during
the build. We can assume that the minimum platform the code will run on is
Vista [1]

In that case there's no need to call API's (ncrypt) dynamically when it can be
done statically.

[1] https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt

Signed-off-by: Steve Lhomme <robux4@ycbcr.xyz>
.gitlab-ci.yml
configure.ac
lib/gnutls.pc.in
lib/system/keys-win.c

index ccc4eddfa19928dee7a1f3cba47220d36df68c16..5ce88f2662e3e1a95b775d8da5a69e52fe0963c9 100644 (file)
@@ -390,6 +390,42 @@ MinGW64.DLLs:
       - win64-build/
   retry: 1
 
+MinGW64.Vista+:
+  stage: stage1-testing
+  image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$MINGW_BUILD
+  script:
+  - ./bootstrap
+  - export CC="ccache x86_64-w64-mingw32-gcc"
+ # Target Vista instead of XP, currently the default in mingw
+  - export CPPFLAGS="-D_WIN32_WINT=0x600"
+  - export WINEPATH=/usr/x86_64-w64-mingw32/sys-root/mingw/bin
+  - mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc
+  - echo ':DOSWin:M::MZ::/usr/bin/wine64:' > /proc/sys/fs/binfmt_misc/register
+  - mkdir -p build
+  - cd build
+  - dash ../configure --disable-gcc-warnings --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --cache-file ../cache/config.cache --with-included-libtasn1 --disable-guile --disable-nls --with-included-unistring --enable-local-libopts --disable-full-test-suite --disable-non-suiteb-curves --disable-doc
+  # generate the certtool autogen file to check whether later compilation will modify it
+  - mingw64-make -j$BUILDJOBS -C src certtool-args.c.bak
+  - mingw64-make -j$BUILDJOBS
+  - mingw64-make -j$CHECKJOBS -C tests check
+  - cd ..
+  # since we use --enable-local-libopts the generated files must equal the .bak
+  - cmp build/src/certtool-args.c build/src/certtool-args.c.bak || false
+  tags:
+  - shared
+  - docker
+  - linux
+  except:
+  - tags
+  artifacts:
+    expire_in: 1 week
+    when: on_failure
+    paths:
+      - build/*.log
+      - build/tests/*.log
+      - build/tests/*/*.log
+  retry: 1
+
 MinGW64:
   stage: stage1-testing
   image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$MINGW_BUILD
index 3413a3dc99561124888fb8c620f869f8cd5433c2..9ea53b734462b033ffd9f94b97526e16d22d9c4f 100644 (file)
@@ -111,6 +111,7 @@ AM_CONDITIONAL(ENABLE_CXX, test "$use_cxx" != "no")
 
 dnl Detect windows build
 use_accel=yes
+have_vista_dynamic=yes
 case "$host" in
   *android*)
     have_android=yes
@@ -121,6 +122,22 @@ case "$host" in
     AC_DEFINE([_UNICODE], [1], [Defined to 1 for Unicode (wide chars) APIs])
     LIB_CRYPT32="-lcrypt32"
     AC_SUBST([LIB_CRYPT32])
+    AC_PREPROC_IFELSE([AC_LANG_PROGRAM(
+      [[#include <windows.h>
+       #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600
+       # error Vista APIs allowed statically
+       #endif
+      ]],[[;]])],[have_vista_dynamic=yes],[have_vista_dynamic=no])
+    AC_ARG_ENABLE(dyn_ncrypt,
+      AS_HELP_STRING([--enable-dyn-ncrypt], [use ncrypt dynamically]),
+      enable_dyn_ncrypt=$enableval, enable_dyn_ncrypt=$have_vista_dynamic
+    )
+    if test "x$enable_dyn_ncrypt" = "xyes"; then
+      AC_DEFINE([DYN_NCRYPT], 1, [Dynamic use of ncrypt API (win32)])
+    else
+      LIBNCRYPT="-lncrypt"
+    fi
+    AC_SUBST([LIBNCRYPT])
   ;;
   *darwin*)
     have_macosx=yes
index 46a1eb5d859af0ad955a54d66e6f06d63397f908..15d3ab057cc1c20ae025658f7151359e8eb4cce8 100644 (file)
@@ -19,6 +19,6 @@ Description: Transport Security Layer implementation for the GNU system
 URL: https://www.gnutls.org/
 Version: @VERSION@
 Libs: -L${libdir} -lgnutls
-Libs.private: @LIBINTL@ @LIBSOCKET@ @INET_PTON_LIB@ @LIBPTHREAD@ @LIB_SELECT@ @TSS_LIBS@ @GMP_LIBS@ @LIBUNISTRING@ @LIBATOMIC_LIBS@ @LIB_CRYPT32@
+Libs.private: @LIBINTL@ @LIBSOCKET@ @INET_PTON_LIB@ @LIBPTHREAD@ @LIB_SELECT@ @TSS_LIBS@ @GMP_LIBS@ @LIBUNISTRING@ @LIBATOMIC_LIBS@ @LIB_CRYPT32@ @LIBNCRYPT@
 @GNUTLS_REQUIRES_PRIVATE@
 Cflags: -I${includedir}
index 678a668e498c3ed8ec07a4589b92bae021ea4264..767e377040f4cd99f0cab0b271d8a577d9c99f95 100644 (file)
@@ -26,6 +26,7 @@
 #define _WIN32_WINNT 0x600
 #endif
 
+#include <config.h>
 #include "gnutls_int.h"
 #include "errors.h"
 #include <gnutls/gnutls.h>
@@ -45,8 +46,6 @@
 #include <winbase.h>
 #include <winapifamily.h>
 
-#define DYN_NCRYPT
-
 #ifdef __MINGW32__
 # include <_mingw.h>
 # ifdef __MINGW64_VERSION_MAJOR
@@ -1487,13 +1486,16 @@ int _gnutls_system_key_init(void)
                ret = GNUTLS_E_CRYPTO_INIT_FAILED;
                goto fail;
        }
-#endif
        ncrypt_init = 1;
 
        return 0;
  fail:
        FreeLibrary(ncrypt_lib);
        return ret;
+#else
+    ncrypt_init = 1;
+    return 0;
+#endif
 }
 
 void _gnutls_system_key_deinit(void)