Skip to content

GHA/windows: add workaround for HAVE_UNISTD_H set by zlib public header - #24037

Closed
vszakats wants to merge 4 commits into
curl:masterfrom
vszakats:gha-zlib-fix
Closed

vszakats wants to merge 4 commits into
curl:masterfrom
vszakats:gha-zlib-fix

Conversation

@vszakats

@vszakats vszakats commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

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

@github-actions github-actions Bot added the DICT label Nov 18, 2026
@vszakats vszakats added build Windows Windows-specific labels Nov 18, 2026
@github-actions github-actions Bot added the CI Continuous Integration label Nov 18, 2026
@vszakats vszakats changed the title [TEST] GHA/windows: HAVE_UNISTD_H confusion [TEST] GHA/windows: add workaround for HAVE_UNISTD_H set by zlib public header Nov 18, 2026
@vszakats vszakats changed the title [TEST] GHA/windows: add workaround for HAVE_UNISTD_H set by zlib public header GHA/windows: add workaround for HAVE_UNISTD_H set by zlib public header Nov 18, 2026
@vszakats

Copy link
Copy Markdown
Member Author

Perhaps it'd make sense to switch to zlib-ng to avoid repeat issues like this.

@vszakats vszakats closed this in 9584627 Nov 18, 2026
@vszakats
vszakats deleted the gha-zlib-fix branch November 18, 2026 14:03
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

build CI Continuous Integration DICT Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

1 participant