Avoid Windows linker errors with GHC 9.4.5+#6
Merged
mitchellwrosen merged 1 commit intoawkward-squad:mainfrom May 11, 2023
RyanGlScott:windows-ucrt-fix
Merged
Avoid Windows linker errors with GHC 9.4.5+#6mitchellwrosen merged 1 commit intoawkward-squad:mainfrom RyanGlScott:windows-ucrt-fix
mitchellwrosen merged 1 commit intoawkward-squad:mainfrom
RyanGlScott:windows-ucrt-fix
Conversation
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.)
Member
|
Excellent, thank you! |
mitchellwrosen
approved these changes
May 11, 2023
Member
Author
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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-ansideclared a directforeign importon theisattyfunction. This is subtly incorrect on Windows, which provides an_isattyfunction 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
msvcrtC runtime (which still providedisatty), but GHC 9.4.5 and later link againstucrt, which does not provideisattyat all. This manifests in linker errors when usingtext-ansiin GHCi or Template Haskell on Windows, as seen in https://gitlab.haskell.org/ghc/ghc/-/issues/23378 and in thishledgerbuild: https://github.com/simonmichael/hledger/actions/runs/4931242306/jobs/8815809083The solution is to instead declare a foreign import on
_isatty. Thec_isattyfunction fromSystem.Posix.Internalsinbasealready does this, in fact, so I have removed the hand-writtenc_isattyfunctions intext-ansiin favor of the one inSystem.Posix.Internals. (Despite that module's name,System.Posix.Internalsis cross-platform and does in fact work on Windows.)