From f4a4c05dc3bcd62ecaa1b0cac5997faefe16c83f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 26 Apr 2023 21:43:45 +0000 Subject: [PATCH] ci: add MSVC and UWP builds to GitHub Actions - add MSVC jobs to GitHub Actions. They are similar to the 'Build-only' jobs we have on AppVeyor CI, though only the ARM64 Windows one is identical. Major disadvantage is that we don't run tests here. Major advantage is they only take a few minutes to complete, compared to an hour on AppVeyor, so WinCNG build results now appear quicker. Docker tests might be possible, but my light attempts failed. Finding ZLIB also failed, so we still miss an MSVC test with it. Tool versions as of now: Server 2022, VS2022, OpenSSL 1.1.1 - add UWP builds for both ARM64 and x64. This hasn't been CI tested before. (We could probably enable UWP on AppVeyor CI as well. I haven't tried.) - fix two uncovered UWP issues in tests. - rename internal macro `LIBSSH2_WINDOWS_APP` to `LIBSSH2_WINDOWS_UWP`. Follow-up to 2addafb77b662e64248d156c71c69b91ba7b926e - fold long lines and quote truthy values in `.github/workflows/ci.yml`. Closes #1010 --- .github/workflows/ci.yml | 57 ++++++++++++++++++++++++++++++++++++---- src/agent.c | 8 +++--- src/agent_win.c | 4 +-- src/libssh2_priv.h | 2 +- tests/openssh_fixture.c | 16 +++++------ 5 files changed, 67 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fee66b19..00d2bd11 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,18 +26,18 @@ jobs: compiler: [gcc, clang] address_size: [64] crypto_backend: [OpenSSL, Libgcrypt, mbedTLS] - enable_zlib_compression: [OFF, ON] + enable_zlib_compression: ['OFF', 'ON'] b: [cmake] include: - compiler: gcc address_size: 64 crypto_backend: OpenSSL - enable_zlib_compression: OFF + enable_zlib_compression: 'OFF' b: configure - compiler: clang address_size: 64 crypto_backend: OpenSSL - enable_zlib_compression: OFF + enable_zlib_compression: 'OFF' b: configure env: CC: ${{ matrix.compiler }} @@ -57,7 +57,9 @@ jobs: MBEDTLSVER=mbedtls-3.4.0 curl -L https://github.com/Mbed-TLS/mbedtls/archive/$MBEDTLSVER.tar.gz | tar -xzf - cd mbedtls-$MBEDTLSVER - cmake $TOOLCHAIN_OPTION -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DCMAKE_INSTALL_PREFIX:PATH=../usr . + cmake $TOOLCHAIN_OPTION \ + -DUSE_SHARED_MBEDTLS_LIBRARY=ON \ + -DCMAKE_INSTALL_PREFIX:PATH=../usr . make -j3 install cd .. echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/usr/lib" >> $GITHUB_ENV @@ -75,7 +77,11 @@ jobs: run: | mkdir bin cd bin - cmake $TOOLCHAIN_OPTION -DENABLE_WERROR=ON -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=ON -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. + cmake $TOOLCHAIN_OPTION \ + -DENABLE_WERROR=ON \ + -DBUILD_SHARED_LIBS=ON \ + -DCRYPTO_BACKEND=$CRYPTO_BACKEND \ + -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. cmake --build . export OPENSSH_SERVER_IMAGE=ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:../tests/openssh_server) ctest -VV --output-on-failure @@ -109,3 +115,44 @@ jobs: ./configure --enable-debug --enable-static --disable-shared --with-crypto=openssl make -j3 make check VERBOSE=1 + + build_msvc: + name: msvc + runs-on: windows-latest + timeout-minutes: 30 + strategy: + matrix: + include: + - { arch: x64 , plat: windows, crypto: WinCNG , log: 'OFF', shared: 'OFF', zlib: 'OFF' } + - { arch: x64 , plat: windows, crypto: WinCNG , log: 'ON' , shared: 'ON' , zlib: 'OFF' } + - { arch: x64 , plat: windows, crypto: OpenSSL, log: 'OFF', shared: 'ON' , zlib: 'OFF' } + - { arch: x64 , plat: uwp , crypto: WinCNG , log: 'OFF', shared: 'ON' , zlib: 'OFF' } + - { arch: arm64, plat: windows, crypto: WinCNG , log: 'OFF', shared: 'ON' , zlib: 'OFF' } + - { arch: arm64, plat: uwp , crypto: WinCNG , log: 'OFF', shared: 'ON' , zlib: 'OFF' } + - { arch: x86 , plat: windows, crypto: WinCNG , log: 'OFF', shared: 'ON' , zlib: 'OFF' } + fail-fast: false + steps: + - uses: actions/checkout@v3 + - name: Configure with CMake + shell: bash + run: | + archgen=${{matrix.arch}}; [ "${archgen}" = 'x86' ] && archgen='Win32' + if [ "${{matrix.plat}}" = 'uwp' ]; then + system='WindowsStore' + options='-DCMAKE_SYSTEM_VERSION=10.0' + else + system='Windows' + fi + cmake . -B bld ${options} \ + -DCMAKE_SYSTEM_NAME=${system} \ + -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake \ + -DCMAKE_GENERATOR_PLATFORM=${archgen} \ + -DVCPKG_TARGET_TRIPLET=${{matrix.arch}}-${{matrix.plat}} \ + -DENABLE_WERROR=ON \ + -DENABLE_DEBUG_LOGGING=${{matrix.log}} \ + -DBUILD_SHARED_LIBS=${{matrix.shared}} \ + -DCRYPTO_BACKEND=${{matrix.crypto}} \ + -DENABLE_ZLIB_COMPRESSION=${{matrix.zlib}} + - name: Build with CMake + run: | + cmake --build bld --config Release --target package diff --git a/src/agent.c b/src/agent.c index 9b38d910..cb1fe20b 100644 --- a/src/agent.c +++ b/src/agent.c @@ -251,7 +251,7 @@ static struct agent_ops agent_ops_unix = { }; #endif /* PF_UNIX */ -#if defined(WIN32) && !defined(LIBSSH2_WINDOWS_APP) +#if defined(WIN32) && !defined(LIBSSH2_WINDOWS_UWP) /* Code to talk to Pageant was taken from PuTTY. * * Portions copyright Robert de Bath, Joris van Rantwijk, Delian @@ -354,16 +354,16 @@ static struct agent_ops agent_ops_pageant = { agent_transact_pageant, agent_disconnect_pageant }; -#endif /* defined(WIN32) && !defined(LIBSSH2_WINDOWS_APP) */ +#endif /* defined(WIN32) && !defined(LIBSSH2_WINDOWS_UWP) */ static struct { const char *name; struct agent_ops *ops; } supported_backends[] = { -#if defined(WIN32) && !defined(LIBSSH2_WINDOWS_APP) +#if defined(WIN32) && !defined(LIBSSH2_WINDOWS_UWP) {"Pageant", &agent_ops_pageant}, {"OpenSSH", &agent_ops_openssh}, -#endif +#endif /* defined(WIN32) && !defined(LIBSSH2_WINDOWS_UWP) */ #ifdef PF_UNIX {"Unix", &agent_ops_unix}, #endif /* PF_UNIX */ diff --git a/src/agent_win.c b/src/agent_win.c index 323ed6ba..4a93e1ca 100644 --- a/src/agent_win.c +++ b/src/agent_win.c @@ -41,7 +41,7 @@ #include "agent.h" #include -#if defined(WIN32) && !defined(LIBSSH2_WINDOWS_APP) +#if defined(WIN32) && !defined(LIBSSH2_WINDOWS_UWP) #include /* for getenv() */ @@ -347,4 +347,4 @@ struct agent_ops agent_ops_openssh = { agent_transact_openssh, agent_disconnect_openssh }; -#endif /* defined(WIN32) && !defined(LIBSSH2_WINDOWS_APP) */ +#endif /* defined(WIN32) && !defined(LIBSSH2_WINDOWS_UWP) */ diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 6cbb2532..857b1359 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -97,7 +97,7 @@ # include # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) -# define LIBSSH2_WINDOWS_APP +# define LIBSSH2_WINDOWS_UWP # endif # endif #endif diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 407cdcbf..cbe08d99 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -61,6 +61,14 @@ #define LIBSSH2_SOCKET_MASK "%d" #endif +#ifdef LIBSSH2_WINDOWS_UWP +#define popen(x, y) (NULL) +#define pclose(x) (-1) +#elif defined(WIN32) +#define popen _popen +#define pclose _pclose +#endif + static int have_docker = 0; int openssh_fixture_have_docker(void) @@ -102,11 +110,7 @@ static int run_command_varg(char **output, const char *command, va_list args) } fprintf(stdout, "Command: %s\n", command_buf); -#ifdef WIN32 - pipe = _popen(buf, "r"); -#else pipe = popen(buf, "r"); -#endif if(!pipe) { fprintf(stderr, "Unable to execute command '%s'\n", command); return -1; @@ -118,11 +122,7 @@ static int run_command_varg(char **output, const char *command, va_list args) buf_len = strlen(buf); } -#ifdef WIN32 - ret = _pclose(pipe); -#else ret = pclose(pipe); -#endif if(ret) { fprintf(stderr, "Error running command '%s' (exit %d): %s\n", command, ret, buf);