Avoid Windows linker errors with GHC 9.4.5+ #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously,
text-ansi
declared a directforeign import
on theisatty
function. This is subtly incorrect on Windows, which provides an_isatty
function rather thanisatty
. (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 providedisatty
), but GHC 9.4.5 and later link againstucrt
, which does not provideisatty
at all. This manifests in linker errors when usingtext-ansi
in GHCi or Template Haskell on Windows, as seen in https://gitlab.haskell.org/ghc/ghc/-/issues/23378 and in thishledger
build: https://github.com/simonmichael/hledger/actions/runs/4931242306/jobs/8815809083The solution is to instead declare a foreign import on
_isatty
. Thec_isatty
function fromSystem.Posix.Internals
inbase
already does this, in fact, so I have removed the hand-writtenc_isatty
functions intext-ansi
in favor of the one inSystem.Posix.Internals
. (Despite that module's name,System.Posix.Internals
is cross-platform and does in fact work on Windows.)