haskell-hvr/regex-posix

Missing of regex.h on Windows

u2x1 opened this issue · 16 comments

u2x1 commented

Log

2020-02-17 20:55:41.773663: [info] regex-posix > build
2020-02-17 20:55:41.773663: [debug] Run process within C:\Users\nutr1\AppData\Local\Temp\stack7508\regex-posix-0.96.0.0\: C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_3.0.1.0_ghc-8.8.2.exe --builddir=.stack-work\dist\29cc6475 build --ghc-options " -fdiagnostics-color=always"
2020-02-17 20:55:42.100248: [info] regex-posix > Preprocessing library for regex-posix-0.96.0.0..
2020-02-17 20:55:42.374347: [warn] regex-posix > C:\Users\nutr1\AppData\Local\Temp\stack7508\regex-posix-0.96.0.0\Wrap.hsc:96:10: fatal error: regex.h: No such file or directory
2020-02-17 20:55:42.377341: [warn] regex-posix > compilation terminated.
2020-02-17 20:55:42.394314: [warn] regex-posix > compiling .stack-work\dist\29cc6475\build\Text\Regex\Posix\Wrap_hsc_make.c failed (exit code 1)
2020-02-17 20:55:42.489164: [warn] regex-posix > command was: C:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.2\lib\../mingw/bin\gcc.exe -c .stack-work\dist\29cc6475\build\Text\Regex\Posix\Wrap_hsc_make.c -o .stack-work\dist\29cc6475\build\Text\Regex\Posix\Wrap_hsc_make.o -D__GLASGOW_HASKELL__=808 -Dmingw32_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Dmingw32_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -Icbits -IC:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\msys2-20161025\mingw64\include -I.stack-work\dist\29cc6475\build\cbits -IC:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\msys2-20161025\mingw64\include -I.stack-work\dist\29cc6475\build\autogen -I.stack-work\dist\29cc6475\build\global-autogen -include .stack-work\dist\29cc6475\build\autogen\cabal_macros.h -IC:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\msys2-20161025\mingw64\include -IC:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.2\lib\bytestring-0.10.10.0\include -IC:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.2\lib\base-4.13.0.0\include -IC:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.2\lib\integer-gmp-1.0.2.0\include -IC:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.2\lib/include -IC:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.2/lib/include/
2020-02-17 20:55:42.540009: [error]
Error:
--  While building package regex-posix-0.96.0.0 using:
      C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_3.0.1.0_ghc-8.8.2.exe --builddir=.stack-work\dist\29cc6475 build --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1

Step to Reproduce

  1. stack install regex-posix -v

Environment

  • Windows 10 1909
  • stack 2.1.3
  • GHC 8.8.2
  • regex-posix 0.96.0.0

I can confirm the reproducibility of this issue on Windows.
Issue does not occur on MacOS Catalina 10.15.3 (same stack, ghc and regex-posix version)

Most likely related to the removal of the internal regex implementation in this commit I guess. 5075a87

I tried e.g. these steps to manually get regex.h for my system from this stackoverflow question but wasn't successful: https://stackoverflow.com/questions/8230905/regex-h-for-windows

I'm not sure where on the system the GHC FFI is looking for the header files which are to be included.

u2x1 commented

I'm not sure where on the system the GHC FFI is looking for the header files which are to be included.

The output of stack would tell us the directory where header files are included:

2020-02-17 20:55:42.489164: [warn] regex-posix > command was: C:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.2\lib\../mingw/bin\gcc.exe -c .stack-work\dist\29cc6475\build\Text\Regex\Posix\Wrap_hsc_make.c -o .stack-work\dist\29cc6475\build\Text\Regex\Posix\Wrap_hsc_make.o -D__GLASGOW_HASKELL__=808 -Dmingw32_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Dmingw32_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -Icbits -IC:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\msys2-20161025\mingw64\include -I.stack-work\dist\29cc6475\build\cbits -IC:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\msys2-20161025\mingw64\include -I.stack-work\dist\29cc6475\build\autogen -I.stack-work\dist\29cc6475\build\global-autogen -include .stack-work\dist\29cc6475\build\autogen\cabal_macros.h -IC:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\msys2-20161025\mingw64\include -IC:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.2\lib\bytestring-0.10.10.0\include -IC:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.2\lib\base-4.13.0.0\include -IC:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.2\lib\integer-gmp-1.0.2.0\include -IC:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.2\lib/include -IC:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.2/lib/include/

To me, it's C:\Users\nutr1\AppData\Local\Programs\stack\x86_64-windows\msys2-20161025\mingw64\include

I have also tried putting regex.h from regex-posix-clib into the path mentioned above. It did passed the GCC compile but when I tried to run GHCi the error turned to be undefined reference to 'regerror'.

I've got this too. There are two parts.

First, you need to have the libsystre package installed. This provides regex.h

pacman -S mingw-w64-x86_64-libsystre

Then you need to have gcc invoked with -IC:\msys64\mingw64\include on the command line (assuming you are compiling for 64-bit machines). That is probably going to require some incantation in the cabal file.

Oh, and there is probably going to have to be a similar link-time option too.

Not sure if this counts as a workaround or an actual solution, but here is what you need to do.

  1. Install MinGW.

  2. Within the MinGW shell install the libstre package. For 64-bit the incantation is pacman -S mingw-w64-x86_64-libsystre.

  3. Add to your project stack.yaml file:
    extra-include-dirs:
    - C:\msys64\mingw64\include

Correction to the above: you don't need mingw64. You just need to install with the _regex-posix-clib flag enabled (note the underscore).

With plain cabal: cabal install regex-posix -f _regex-posix-clib

In Stack, add the following to your stack.yaml:

extra-deps:
   - regex-posix-clib-2.7

flags:
   regex-posix:
      _regex-posix-clib: true

Correction to the above: you don't need mingw64. You just need to install with the _regex-posix-clib flag enabled (note the underscore).

With plain cabal: cabal install regex-posix -f _regex-posix-clib

In Stack, add the following to your stack.yaml:

extra-deps:
   - regex-posix-clib-2.7

flags:
   regex-posix:
      _regex-posix-clib: true

This solved it for me!
Will adding these to the stack.yaml cause any issues when building on Linux or MacOS?

Can this behavior be made automatic, so that we can use the same stack.yaml on all platforms?

pdcxs commented

I add these codes to stack.yaml, it says:
Error while parsing $.flags.regex-posix - key "manual" not present

I confirm @PaulJohnson's solution solves the problem on WIN10.

pdcxs commented

Sorry, I added the code into package.yaml but not the stack.yaml. Now it is solved. Thanks a lot.

Can this behavior be made automatic, so that we can use the same stack.yaml on all platforms?

That is the correct fix. Please reopen this ticket @Nutr1t07

u2x1 commented

It seems that this commit makes it unable to compile on WIndows. I can't figure out why.

  if flag(_regex-posix-clib)
    build-depends: regex-posix-clib == 2.7.*
  else
    -- use POSIX.2 regex implementation from @libc@
    -- However, Windows/msys2 doesn't provide a POSIX.2 regex impl in its @libc@
    if os(windows)
      build-depends: base<0

Hey there. stack comes with its own mingw installed and ready to use.

To get dependency installed into stack environment run

stack exec -- pacman -S mingw-w64-x86_64-libsystre

But yeah, it would be nice if stack installed it by itself. :)

oovz commented
stack exec -- pacman -S mingw-w64-x86_64-libsystre

doesn't seem to work

error: mingw32: signature from "David Macek <david.macek.0@gmail.com>" is unknown trust
error: mingw64: signature from "David Macek <david.macek.0@gmail.com>" is unknown trust
error: msys: signature from "David Macek <david.macek.0@gmail.com>" is unknown trust
error: database 'mingw32' is not valid (invalid or corrupted database (PGP signature))
error: database 'mingw64' is not valid (invalid or corrupted database (PGP signature))
error: database 'msys' is not valid (invalid or corrupted database (PGP signature))

Signature errors are due to the age of the bundled msys2 package. commercialhaskell/stack#5567 (comment)

Workaround: stack exec -- pacman -Sy msys2-keyring

See #7 (comment): Stack installation should be straight-forward with regex 0.96.0.1 even under Windows. (Letting mingw/msys issues aside.)