commercialhaskell / stack

The Haskell Tool Stack
http://haskellstack.org
BSD 3-Clause "New" or "Revised" License
3.98k stars 842 forks source link

“Unable to load package `regex-posix` … unknown symbol ‘regerror’” #5404

Open bradrn opened 4 years ago

bradrn commented 4 years ago

(Cross-posted from Stack Overflow on the advice of @sjakobi.)

General summary/comments (optional)

For a new project, I have been trying to build the threepenny-gui package, something which I have done many times in the past without any trouble. This time however, I ran into an unusual error message:

> stack build
threepenny-gui     > configure
threepenny-gui     > Configuring threepenny-gui-0.9.0.0...
threepenny-gui     > build
threepenny-gui     > Preprocessing library for threepenny-gui-0.9.0.0..
threepenny-gui     > Building library for threepenny-gui-0.9.0.0..
threepenny-gui     > [ 1 of 29] Compiling Foreign.JavaScript.Include
threepenny-gui     > [ 2 of 29] Compiling Foreign.JavaScript.Resources
threepenny-gui     > ghc.exe: unable to load package `regex-posix-0.96.0.0'
threepenny-gui     > ghc.exe:  | C:\sr\snapshots\14724cfd\lib\x86_64-windows-ghc-8.8.4\regex-posix-0.96.0.0-11M5Q2Uki3ACYikP2WXOuq\HSregex-posix-0.96.0.0-11M5Q2Uki3ACYikP2WXOuq.o: unknown symbol `regerror'

--  While building package threepenny-gui-0.9.0.0 using:
      C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_3.0.1.0_ghc-8.8.4.exe --builddir=.stack-work\dist\29cc6475 build --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1
Progress 1/2

Now, a quick Google shows that this error message has been seen before — in 2010, after which it was fixed with a GHC update. I tried changing GHC versions (that output above was with GHC 8.8.4), but it didn’t work with 8.8.3 or 8.8.2 either. I also tried deleting regex-posix¹ and reinstalling it again, but that didn’t work either. At this point, I must confess that this error has completely stumped me; does anyone else have any idea what might be causing it, and if so, how can I fix it?

¹ Specifically, I removed C:\sr\snapshots\14724cfd\lib\x86_64-windows-ghc-8.8.4\regex-posix-0.96.0.0-11M5Q2Uki3ACYikP2WXOuq and C:\sr\snapshots\14724cfd\pkgdb\regex-posix-0.96.0.0-11M5Q2Uki3ACYikP2WXOuq.conf, and did ghc-pkg unregister regex-posix.

Steps to reproduce

  1. Run stack build threepenny-gui --resolver lts-16.15. (Trying to build a project depending on threepenny-gui will also trigger this issue.)

Expected

threepenny-gui builds successfully.

Actual

The error message shown above is printed.

Stack version

$ > stack --version
Version 2.3.1, Git revision de2a7b694f07de7e6cf17f8c92338c16286b2878 (8103 commits) x86_64 hpack-0.33.0

Method of installation

Official binary, downloaded from stackage.org or fpcomplete's package repository. (I believe; I don’t remember exactly how I installed it.)

HeinrichApfelmus commented 3 years ago

For me, performing the stack build […] command yields the expected result. However, I am on macOS 10.15, whereas @bradrn is on Windows.

I suspect the problem occurs when the Foreign.JavaScript.Resources module invokes Template Haskell and the compiler tries to load the regex-posix package. This package assumes POSIX compatibility, which can sometimes lead to problems on Windows, and the package will pull in a shared C library, which may cause problems if builds are run in parallel.

The threepenny-gui package does not directly depend on regex-posix, but indirectly via snap-core. Maybe installing snap-core first and then threepenny-gui could avoid issues with parallel builds, if there are any. But I have no idea, either.

I suspect that a minimal example to reproduce this issue is a package that depends on regex-posix and uses Template Haskell in a way similar to Foreign.JavaScript.Include and Foreign.JavaScript.Resources.

bradrn commented 3 years ago

Maybe installing snap-core first and then threepenny-gui could avoid issues with parallel builds, if there are any. But I have no idea, either.

Nope, no luck:

> stack build snap-core-1.0.4.1

[…lots of output…]

snap-core           > copy/register
snap-core           > Installing library in C:\sr\snapshots\d3d2d456\lib\x86_64-windows-ghc-8.8.4\snap-core-1.0.4.1-J2hIdUZJ69cDfDyjQvGZuM
snap-core           > Registering library for snap-core-1.0.4.1..
Completed 28 action(s).

> stack build
threepenny-gui     > configure
threepenny-gui     > Configuring threepenny-gui-0.9.0.0...
threepenny-gui     > build
threepenny-gui     > Preprocessing library for threepenny-gui-0.9.0.0..
threepenny-gui     > Building library for threepenny-gui-0.9.0.0..
threepenny-gui     > [ 1 of 29] Compiling Foreign.JavaScript.Include
threepenny-gui     > [ 2 of 29] Compiling Foreign.JavaScript.Resources
threepenny-gui     > ghc.exe: unable to load package `regex-posix-0.96.0.0'
threepenny-gui     > ghc.exe:  | C:\sr\snapshots\14724cfd\lib\x86_64-windows-ghc-8.8.4\regex-posix-0.96.0.0-11M5Q2Uki3ACYikP2WXOuq\HSregex-posix-0.96.0.0-11M5Q2Uki3ACYikP2WXOuq.o: unknown symbol `regerror'

--  While building package threepenny-gui-0.9.0.0 using:
      C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_3.0.1.0_ghc-8.8.4.exe --builddir=.stack-work\dist\29cc6475 build --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1
Progress 1/2

I suspect that a minimal example to reproduce this issue is a package that depends on regex-posix and uses Template Haskell in a way similar to Foreign.JavaScript.Include and Foreign.JavaScript.Resources.

Possibly… maybe I’ll try doing that and see what happens. (Though I’m not quite sure how Foreign.JavaScript.Include is using regex-posix — there seems to be no connection as far as I can tell.)

HeinrichApfelmus commented 3 years ago

(Though I’m not quite sure how Foreign.JavaScript.Include is using regex-posix — there seems to be no connection as far as I can tell.)

No direct connection, yes. However, I suspect that the problem occurs when Template Haskell wants to load regex-posix, which links a shared C library, which causes trouble.

bradrn commented 3 years ago

Curiouser and curiouser… global stack build threpenny-gui still doesn’t work, but when I build the same commit locally, it works just fine:

C:\Users\bradn\Documents\Haskell\threepenny-gui>git checkout e9467ea90504b335cbd618d198fa0ebbef09fc29
Note: switching to 'e9467ea90504b335cbd618d198fa0ebbef09fc29'.

[…]

HEAD is now at e9467ea Prepare release 0.9.0.0 (#242)

C:\Users\bradn\Documents\Haskell\threepenny-gui>stack build threepenny-gui
threepenny-gui-0.9.0.0: unregistering (local file changes: threepenny-gui.cabal)
threepenny-gui> configure (lib + exe)
Configuring threepenny-gui-0.9.0.0...
threepenny-gui> build (lib + exe)
Preprocessing library for threepenny-gui-0.9.0.0..
Building library for threepenny-gui-0.9.0.0..
Preprocessing executable 'threepenny-examples-svg' for threepenny-gui-0.9.0.0..
Building executable 'threepenny-examples-svg' for threepenny-gui-0.9.0.0..
Preprocessing executable 'threepenny-examples-currencyconverter' for threepenny-gui-0.9.0.0..
Building executable 'threepenny-examples-currencyconverter' for threepenny-gui-0.9.0.0..
[…lots more of this…]
Preprocessing executable 'threepenny-examples-buttons' for threepenny-gui-0.9.0.0..
Building executable 'threepenny-examples-buttons' for threepenny-gui-0.9.0.0..
threepenny-gui> copy/register
Installing library in C:\Users\bradn\Documents\Haskell\threepenny-gui\.stack-work\install\fe785b19\lib\x86_64-windows-ghc-8.2.2\threepenny-gui-0.9.0.0-3BZEtFIZYW7ElM7ZZr4seE
Installing executable threepenny-examples-svg in C:\Users\bradn\Documents\Haskell\threepenny-gui\.stack-work\install\fe785b19\bin
Installing executable threepenny-examples-currencyconverter in C:\Users\bradn\Documents\Haskell\threepenny-gui\.stack-work\install\fe785b19\bin
[…lots more of this…]
Installing executable threepenny-examples-buttons in C:\Users\bradn\Documents\Haskell\threepenny-gui\.stack-work\install\fe785b19\bin
Registering library for threepenny-gui-0.9.0.0..
bradrn commented 3 years ago

A further development: stack build threepenny-gui works with LTS 14.27, but not LTS 15.0. I note that this is a change from GHC 8.6.5 to 8.8.2, as well as an update from regex-posix-0.95.2 to regex-posix-0.96.0.0; perhaps one of those is causing this issue.

bradrn commented 3 years ago

Just noticed https://github.com/haskell-hvr/regex-posix/issues/7. I suspect that that’s causing this issue.

Also, I must correct my previous comment that a local build of threepenny-gui works without issue. When I update the resolver to lts-15.0 as per my previous comment, I can reproduce the error locally. At this point it’s looking like this is an issue best fixed in regex-posix (or possibly threepenny-gui) rather than Stack, though I’ll leave this open in case this does turn out to be a problem in Stack.

bradrn commented 3 years ago

I finally managed to fix this! First, I recompiled regex-posix with the relevant flag (adding regex-posix-clib-2.7 as an extra-dep):

> stack exec -- ghc-pkg unregister regex-posix-0.96.0.0 --force
> stack build regex-posix-0.96.0.0 --flag regex-posix:_regex-posix-clib

After which a local stack build threepenny-gui worked correctly.

EDIT: Just double-checked the examples; those still seem to work correctly after this change.

EDIT2: Aargh, I just tested a global stack build threepenny-gui and it still gives the same error. Back to the drawing board again, I suppose… (I’m hoping I just need to do another round of ghc-pkg unregister regex-posix, but I don’t have time to test that just right now.)

EDIT3: Yep, my previous parenthetical was correct. I managed to build threepenny-gui successfully using the following commands:

> stack --resolver lts-16.23 exec -- ghc-pkg unregister regex-posix-0.96.0.0 --force
> stack build regex-posix-0.96.0.0 --flag regex-posix:_regex-posix-clib --resolver lts-16.23
> stack build threepenny-gui --resolver lts-16.23

For whatever reason, it seems necessary to explicitly specify the resolver in all commands to avoid this error.

andreasabel commented 3 years ago

(See https://github.com/haskell-hvr/regex-posix/issues/7#issuecomment-783131496.)

@bradrn wrote:

First, I recompiled regex-posix with the relevant flag ...

...
stack build regex-posix-0.96.0.0 --flag regex-posix:_regex-posix-clib

On windows, this flag should be activated automatically by the constraint solver, because there is a constraint "if flag off and under Windows then require base<0 (absurdity)" in the regex-posix.cabal file. So this maybe be a bug in the stack constraint solver. Is this bug reported already?