Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid Windows linker errors with GHC 9.4.5+ #6

Merged
merged 1 commit into from
May 11, 2023
Merged

Avoid Windows linker errors with GHC 9.4.5+ #6

merged 1 commit into from
May 11, 2023

Commits on May 11, 2023

  1. Avoid Windows linker errors with GHC 9.4.5+

    Previously, `text-ansi` declared a direct `foreign import` on the `isatty`
    function. This is subtly incorrect on Windows, which provides an `_isatty`
    function rather than `isatty`. (See
    https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/posix-isatty?view=msvc-170)
    
    This happened to work on pre-9.4.5 versions of GHC due to them linking against
    the `msvcrt` C runtime (which still provided `isatty`), but GHC 9.4.5 and later
    link against `ucrt`, which does not provide `isatty` at all. This manifests in
    linker errors when using `text-ansi` in GHCi or Template Haskell on Windows, as
    seen in https://gitlab.haskell.org/ghc/ghc/-/issues/23378 and in this `hledger`
    build:
    https://github.com/simonmichael/hledger/actions/runs/4931242306/jobs/8815809083
    
    The solution is to instead declare a foreign import on `_isatty`. The
    `c_isatty` function from `System.Posix.Internals` in `base` already does this,
    in fact, so I have removed the hand-written `c_isatty` functions in `text-ansi`
    in favor of the one in `System.Posix.Internals`. (Despite that module's name,
    `System.Posix.Internals` is cross-platform and does in fact work on Windows.)
    RyanGlScott committed May 11, 2023
    Configuration menu
    Copy the full SHA
    1976fb5 View commit details
    Browse the repository at this point in the history