Skip to content

GHA/windows: make MSVC jobs use MSYS2 libraries: psl, OpenSSL, H2, libssh2 - #17561

Closed
vszakats wants to merge 40 commits into
curl:masterfrom
vszakats:gha-vs-test
Closed

vszakats wants to merge 40 commits into
curl:masterfrom
vszakats:gha-vs-test

Conversation

@vszakats

@vszakats vszakats commented Jun 9, 2025 •

Copy link
Copy Markdown
Member

Extend MSVC jobs with the option to use MSYS2 binary package as DLL
dependencies. Allow to use them alone (without vcpkg) or combined with
vcpkg packages. This saves the trouble of building these packages from
source and cache them manually.

This solution requires two tricks:

  • workaround for zlib which installs a target-specific zconf.h that's
    not portable between platforms and C compilers.
  • manual dependency configuration in CMake to ensure linking against
    the MSYS2 DLLs (and not it static libs). Static libs aren't portable
    to MSVC due to missing symbols __chkstk_ms, _stack_chk_fail,
    _memcpy_chk, _stack_chk_guard, and potentially other issues. CMake
    in MSVC mode, linker.exe and pkg-config pick the static libs by
    default. To pick .dll.a in favour of .a, these tools would have
    to be taught about this convention. An alternative is deleting static
    libs and see if .dll.a are picked-up automatically.

Using MSYS2 packages adds an install step taking 15-45 seconds per job.

It allowed to:

  • re-enable libpsl for all MSVC jobs.
  • convert the Intel 64-bit job to use MSYS2 without vcpkg, enabling
    brotli, zstd, OpenSSL 3.5.0, libssh2 (with OpenSSL cryprography) and
    nghttp2.

Using the same technique it's possible to re-enable more features
in MSVC builds, e.g. GnuTLS (also with H3), LibreSSL, mbedTLS, nghttp3,
ngtcp2, libssh, c-ares, gsasl, and replace vcpkg zlib, for faster runs.
What's missing compared to vcpkg is BoringSSL and wolfSSL
(the MSYS2-supplied build doesn't fit curl's requirements IIRC). These
could be built and cached manually.

Also:

  • add workaround for zlib (classic) which uses a generated zconf.h,
    rendering the MSYS2 zlib header incompatible with MSVC.
  • set the correct msystem for arm64.
  • allow using MSVC without vcpkg.

Follow-up to cd0ec47 #17089


Using the same technique it should work in theory to re-enable more
features in MSVC builds, e.g. GnuTLS (also with H3), LibreSSL, OpenSSL,
mbedTLS, nghttp2, nghttp2, ngtcp2, libssh2 (with OpenSSL), libssh, zstd,
brotli, c-ares, gsasl, and replace vcpkg zlib, for faster runs. What's missing
is boringssl and wolfssl (the MSYS2-supplied version doesn't fit curl's
requirements IIRC), and these could be built and cached manually.

update 1: In practice, some mingw-generated code refers to __chkstk_ms,
_stack_chk_fail, _memcpy_chk, _stack_chk_guard, which is
then missing at link time. E.g. with brotli, zstd. (static libs picked up)
This is fixed by forcing to link against DLLs.

update 2: Next practical issue: zconf.h is a dynamically generated
header that's different for vcpkg and MSYS2. When MSYS2 installs
it directly or via dependent, it will be picked first, and fail to compile.
zlib is a dependency of libssh2 for example, complicating its use.

update 3: It looks like zlib is the blocker to use MSYS2 packages
with MSVC. Till zlib fixes this, the only way to work it around is to
have a zlib specifically built for MSVC and put its header path
before MSYS2's. This is difficult, if possible at all with CMake.

update 4: patching zconf.h seems to work as a workaround.

TODO:

  • try auto-detecting libpsl via pkg-config. Dropped the idea, pkgconf was confusing the detection of vcpkg packages, resulting in a cmake error.
  • try CMake find_* detection via -DCMAKE_INCLUDE_PATH="${mingwroot}/include" -DCMAKE_LIBRARY_PATH="${mingwroot}/lib". Detection worked, but the build picked up the static libraries, which broke at link time due to missing symbols: __chkstk_ms, _stack_chk_fail, _memcpy_chk, _stack_chk_guard. What works is manually configuring these dependencies and pointing to the implib.
  • add more MSYS2 packages
  • drop vcpkg packages to save time? [DONE, made it an option, one job uses this build path]

@vszakats vszakats added Windows Windows-specific CI Continuous Integration labels Jun 9, 2025
@vszakats
vszakats marked this pull request as draft June 9, 2025 14:07
@vszakats vszakats changed the title GHA/windows: try msystem arm64 for the arm runner GHA/windows: make MSVC jobs use MSYS2 libpsl package Jun 9, 2025
@vszakats
vszakats marked this pull request as ready for review June 9, 2025 17:19
@vszakats vszakats changed the title GHA/windows: make MSVC jobs use MSYS2 libpsl package GHA/windows: make MSVC jobs use MSYS2 libpsl Jun 9, 2025
@vszakats
vszakats force-pushed the gha-vs-test branch 3 times, most recently from 2fa3899 to cba09da Compare June 10, 2025 12:20
@vszakats vszakats changed the title GHA/windows: make MSVC jobs use MSYS2 libpsl GHA/windows: make MSVC jobs use MSYS2 libraries (libpsl, H3, H2, libssh2) Jun 10, 2025
@vszakats vszakats changed the title GHA/windows: make MSVC jobs use MSYS2 libraries (libpsl, H3, H2, libssh2) GHA/windows: make MSVC jobs use MSYS2 libraries: psl, H3, H2, libssh2 Jun 10, 2025
@vszakats vszakats changed the title GHA/windows: make MSVC jobs use MSYS2 libraries: psl, H3, H2, libssh2 GHA/windows: make MSVC jobs use MSYS2 libraries: psl, OpenSSL, H3, H2, libssh2 Jun 10, 2025
vszakats added a commit that referenced this pull request Jun 10, 2025
vszakats added a commit that referenced this pull request Jun 10, 2025
vszakats added 14 commits June 10, 2025 16:32
debug 1

debug 2

debug 3

debug 4

debug 5
brotli detected, but then:
```
libbrotlidec.a(decode.c.obj) : error LNK2019: unresolved external symbol ___chkstk_ms referenced in function BrotliDecoderDecompress [C:\a\curl\curl\bld\src\curl.vcxproj]
libbrotlidec.a(decode.c.obj) : error LNK2019: unresolved external symbol __stack_chk_fail referenced in function SafeDecodeLiteralBlockSwitch [C:\a\curl\curl\bld\src\curl.vcxproj]
libbrotlidec.a(huffman.c.obj) : error LNK2001: unresolved external symbol __stack_chk_fail [C:\a\curl\curl\bld\src\curl.vcxproj]
libbrotlidec.a(decode.c.obj) : error LNK2019: unresolved external symbol __memcpy_chk referenced in function SkipMetadataBlock [C:\a\curl\curl\bld\src\curl.vcxproj]
libbrotlidec.a(decode.c.obj) : error LNK2001: unresolved external symbol __stack_chk_guard [C:\a\curl\curl\bld\src\curl.vcxproj]
libbrotlidec.a(huffman.c.obj) : error LNK2001: unresolved external symbol __stack_chk_guard [C:\a\curl\curl\bld\src\curl.vcxproj]
C:\a\curl\curl\bld\src\Debug\curl.exe : fatal error LNK1120: 4 unresolved externals [C:\a\curl\curl\bld\src\curl.vcxproj]
```
https://github.com/curl/curl/actions/runs/15545116957/job/43764842374?pr=17561#step:9:48
vszakats added 10 commits June 10, 2025 16:32
This reverts commit 376a9db.

Still doesn't work because zlib's zconf.h is target-dependent
and MSYS2's copy is incompatible with MSVC.

zlib being the dependency of everything, means it's a blocker
for combining / reusing packages between compiler. What an
unnecessary issue... Public headers should never be target
dependent.

```
C:\msys64\ucrt64\include\zconf.h(484,14): error C1083: Cannot open include file: 'unistd.h': No such file or directory
```

zconf.h:
```
 #if 1    /* was set to #if 1 by ./configure */
 #  define Z_HAVE_UNISTD_H
 #endif

 #if 1    /* was set to #if 1 by ./configure */
 #  define Z_HAVE_STDARG_H
 #endif
```
@vszakats

vszakats commented Jun 10, 2025 •

Copy link
Copy Markdown
Member Author

Requires this week's windows runner (20250602.1), which installs ngtcp2 1.13.0.
In unlucky cases the old runner installs 1.12.0 which lacks the necessary ngtcp2
crypto header for ossl:

C:\a\curl\curl\lib\vquic\curl_ngtcp2.c(36,10): error C1083: Cannot open include file: 'ngtcp2/ngtcp2_crypto_ossl.h': No such file or directory [C:\a\curl\curl\bld\lib\libcurl_object.vcxproj]
  (compiling source file 'CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c')

good: https://github.com/curl/curl/actions/runs/15561267632/job/43814310575
bad: https://github.com/curl/curl/actions/runs/15562544157/job/43818363234?pr=17561

In the meantime can be committed without H3, and commit the rest next week
when the old runner is gone.

@vszakats vszakats changed the title GHA/windows: make MSVC jobs use MSYS2 libraries: psl, OpenSSL, H3, H2, libssh2 GHA/windows: make MSVC jobs use MSYS2 libraries: psl, OpenSSL, H2, libssh2 Jun 10, 2025
@vszakats vszakats closed this in c129d0b Jun 10, 2025
@vszakats
vszakats deleted the gha-vs-test branch June 10, 2025 22:51
vszakats added a commit to vszakats/curl that referenced this pull request Jun 10, 2025
vszakats added a commit that referenced this pull request Jun 14, 2025
Requires windows-runner 20250602.1 for ngtcp2 1.13.0.

Follow-up to c129d0b #17561
Ref: #17561 (comment)

Closes #17577
denandz pushed a commit to denandz/curl that referenced this pull request Jun 21, 2025
denandz pushed a commit to denandz/curl that referenced this pull request Jun 21, 2025
denandz pushed a commit to denandz/curl that referenced this pull request Jun 21, 2025
…bssh2

Extend MSVC jobs with the option to use MSYS2 binary package as DLL
dependencies. Allow to use them alone (without vcpkg) or combined with
vcpkg packages. This saves the trouble of building these packages from
source and cache them manually.

This solution requires two tricks:
- workaround for zlib which installs a target-specific `zconf.h` that's
  not portable between platforms and C compilers.
- manual dependency configuration in CMake to ensure linking against
  the MSYS2 DLLs (and not it static libs). Static libs aren't portable
  to MSVC due to missing symbols `__chkstk_ms`, `_stack_chk_fail`,
  `_memcpy_chk`, `_stack_chk_guard`, and potentially other issues. CMake
  in MSVC mode, `linker.exe` and `pkg-config` pick the static libs by
  default. To pick `.dll.a` in favour of `.a`, these tools would have
  to be taught about this convention. An alternative is deleting static
  libs and see if `.dll.a` are picked-up automatically.

Using MSYS2 packages adds an install step taking 15-45 seconds per job.

It allowed to:
- re-enable libpsl for all MSVC jobs.
- convert the Intel 64-bit job to use MSYS2 without vcpkg, enabling
  brotli, zstd, OpenSSL 3.5.0, libssh2 (with OpenSSL cryprography) and
  nghttp2.

Using the same technique it's possible to re-enable more features
in MSVC builds, e.g. GnuTLS (also with H3), LibreSSL, mbedTLS, nghttp3,
ngtcp2, libssh, c-ares, gsasl, and replace vcpkg zlib, for faster runs.
What's missing compared to vcpkg is BoringSSL and wolfSSL
(the MSYS2-supplied build doesn't fit curl's requirements IIRC). These
could be built and cached manually.

Also:
- add workaround for zlib (classic) which uses a generated `zconf.h`,
  rendering the MSYS2 zlib header incompatible with MSVC.
- set the correct `msystem` for arm64.
- allow using MSVC without vcpkg.

Follow-up to cd0ec47 curl#17089

Closes curl#17561
denandz pushed a commit to denandz/curl that referenced this pull request Jun 21, 2025
Requires windows-runner 20250602.1 for ngtcp2 1.13.0.

Follow-up to c129d0b curl#17561
Ref: curl#17561 (comment)

Closes curl#17577
vszakats added a commit that referenced this pull request Nov 18, 2026
…ader

zlib 1.3.1.2+ built with cmake sets `HAVE_UNISTD_H` to `1` in its public
header when the zlib build environment detected `unistd.h`. This breaks
dependents that rely on this macro, when the zlib-build-time value differs
from the actual target build environment, as in curl CI, which uses the
mingw-built package in an MSVC build.

The issue surfaced when the MSYS2 package switched to using cmake
while bumping from 1.3.2 to 1.4, and this propagated into the Windows
runner, causing:
```
curl/lib/dict.c(58): fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory
```
Ref: https://github.com/curl/curl/actions/runs/44311921832/job/134828014535?pr=24037#step:11:35

Refs:
madler/zlib@3d6dc3c#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20aR39-R41
msys2/MINGW-packages@5cbcc05
msys2/MINGW-packages#33269

Bug: #24036 (comment)
Follow-up to c129d0b #17561

Closes #24037
vszakats added a commit that referenced this pull request Nov 19, 2026
Drop zlib from the MSVC CI job as this is fragile, potentially unsafe,
and requires hacks to make it build:

- zlib includes or wants to include `unistd.h` from its public headers,
  also on Windows. (it's available in mingw-w64, not in MSVC)
- defines non-zlib namespaced, commonly-used `HAVE_UNISTD_H` in its
  public headers.
- above only happens if zlib was built with cmake (in 1.3.1.2+).
- hardcodes build-time environment properties into its public header,
  meaning its headers cannot be safely used in a cross-build or in a
  different target env.
- `HAVE_UNISTD_H` became unused in 1.4, but still set. It may
  break dependent 1st-party code that uses this symbol to communicate
  `unistd.h` presence.
- the `z_off_t` type is not fixed-size, and depends on non-standard type
  `off_t`, that depends e.g. on `unistd.h`.
- due to `z_off_t` depending on the above logic, the ABI may break in an
  affected API e.g. `gzseek*()`, `gztell*()`, `gzoffset*()`, when some
  of the consume-time logic differs from the build-time one. (curl not
  using these functions, but there may be more.)
  E.g. using an MSYS2/mingw UCRT x64-built zlib.dll in an equivalent
  MSVC build.
- zlib-ng also includes `unistd.h`, and depends on `off_t`. It does not
  define `HAVE_UNISTD_H` though.

Follow-up to 9584627 #24037
Follow-up to c129d0b #17561

Closes #24040
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Continuous Integration Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

1 participant