Stack build fails due to mintty [duplicate] - haskell

I'm getting an error when attempting to compile Haskell tests using test-framework on Windows.
Steps to reproduce
Create a new library using Stack:
$ stack new repro simple-library
Then navigate into the repro directory and edit the repro.cabal file by adding test-framework to build-depends:
library
hs-source-dirs: src
exposed-modules: Lib
build-depends: base >= 4.7 && < 5,
test-framework
default-language: Haskell2010
Now attempt to compile the library:
$ stack build
Expected outcome
The code compiles
Actual outcome
Compilation fails with this error message:
$ stack build
WARNING: Ignoring mintty's bounds on Win32 (>=2.13.1); using Win32-2.6.2.1.
Reason: trusting snapshot over cabal file dependency information.
mintty > configure
mintty > Configuring mintty-0.1.3...
mintty > build
mintty > Preprocessing library for mintty-0.1.3..
mintty > Building library for mintty-0.1.3..
mintty > [1 of 1] Compiling System.Console.MinTTY
mintty >
mintty > src\System\Console\MinTTY.hs:31:1: error:
mintty > Could not find module `System.Console.MinTTY.Win32'
mintty > Use -v (or `:set -v` in ghci) to see a list of the files searched for.
mintty > |
mintty > 31 | import qualified System.Console.MinTTY.Win32 as Win32 (isMinTTY, isMinTTYHandle)
mintty > | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mintty >
Progress 1/5
-- While building package mintty-0.1.3 (scroll up to its section to see the error) using:
C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_3.2.1.0_ghc-8.10.7.exe --builddir=.stack-work\dist\274b403a build --ghc-options " -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
How do I resolve this error?
Environment
$ stack --version
Version 2.7.3, Git revision 7927a3aec32e2b2e5e4fb5be76d0d50eddcc197f x86_64 hpack-0.34.4
Windows
Edition Windows 10 Pro
Version 21H1
Installed on ‎14.‎09.‎2020
OS build 19043.1348
Experience Windows Feature Experience Pack 120.2212.3920.0

I assume, given when you posted this question, you are using LTS 18.17. Looking at that LTS, it uses mintty 0.1.3. Looking in mintty 0.1.3's cabal file shows a special flag that is enabled by default that means that System.Console.MinTTY.Win32 is not included. The comments in that cabal file say that that flag should be used when using Win32 2.13.1.0 or newer.
However, when I look at LTS 18's configuration in Stackage, I can see that it is using Win32 2.6.2.1, so that flag ought to be set to false for this package to work.
So let's check that in the Stackage build constraints. I see that another flag is being set, and it seems to be an old flag that is no longer used (looks like it was used in an older 0.1.2 version). This must be the problem.
The solution: manually set the flag in your stack.yaml:
flags:
mintty:
Win32-2-13-1: false

Related

Cannot build project with z3-haskell on windows 10

I want to build the haskell bindings for z3 in a Cabal project, the following is the minimum (faulty) example:
Using a project initialized by cabal init:
test/
- Main.hs
- Setup.hs
- CHANGELOG.md
- test.cabal
With modified test.cabal:
cabal-version: 3.0
name: z3-test
version: 0.1.0.0
extra-source-files: CHANGELOG.md
executable test
main-is: Main.hs
build-depends: base >=4.14 && <4.15
, z3 ^>=408.2
default-language: Haskell2010
Z3 binaries are located at C:\z3-4.8.5-x86-win.
Z3-bindings are installed:
cabal v1-install z3 --extra-lib-dirs=C:/z3-4.8.5-x64-win/bin --extra-include-dirs=C:/z3-4.8.5-x64-win/include -v3
All the requested packages are already installed:
z3-408.2
Use --reinstall if you want to reinstall anyway.
Now building the project using:
cabal v2-build --extra-lib-dirs=C:/z3-4.8.5-x64-win/bin --extra-include-dirs=C:/z3-4.8.5-x64-win/include -v3
Results in the error:
Build profile: -w ghc-8.10.2 -O1
In order, the following will be built (use -v for more details):
- z3-408.2 (lib) (requires build)
- z3-test-0.1.0.0 (exe:test) (first run)
Starting z3-408.2 (lib)
Failed to build z3-408.2. The failure occurred during the configure step.
Build log (
C:\cabal\logs\ghc-8.10.2\z3-408.2-1722a25655334afbca91ac935f14ff0d20ccf8c4.log
):
Configuring library for z3-408.2..
cabal.exe: Missing dependency on a foreign library:
* Missing (or bad) header file: z3.h
* Missing (or bad) C library: z3
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.If the
library file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.
If the header file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.
cabal.exe: Failed to build z3-408.2 (which is required by exe:test from
z3-test-0.1.0.0). See the build log above for details.
How can I build a project with the z3 bindings?
Note that:
GHC version = 8.10.2
Cabal version = 3.2.0.0
I can only use cabal
Using cabal install ... or cabal v2-install ... results in Cannot build .. z3 because none of the components are available to build:

Error building package regex-posix-0.96.0.0 with Stack

I'm trying to compile a new Haskell project with Stack, but I'm getting this error message:
$ stack build
WARNING: Ignoring regex-posix's bounds on base (<0 && >=4.3 && <4.16); using base-4.14.1.0.
Reason: trusting snapshot over cabal file dependency information.
regex-posix > configure
regex-posix > Configuring regex-posix-0.96.0.0...
regex-posix > build
regex-posix > Preprocessing library for regex-posix-0.96.0.0..
regex-posix > compiling .stack-work\dist\274b403a\build\Text\Regex\Posix\Wrap_hsc_make.c failed (exit code 1)
regex-posix > rsp file was: ".stack-work\\dist\\274b403a\\build\\Text\\Regex\\Posix\\hsc5BFC.rsp"
regex-posix > command was: C:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.4\lib\../mingw/bin\gcc.exe -c .stack-work\dist\274b403a\build\Text\Regex\Posix\Wrap_hsc_make.c -o .stack-work\dist\274b403a\build\Text\Regex\Posix\Wrap_hsc_make.o -D__GLASGOW_HASKELL__=810 -Dmingw32_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Dmingw32_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -Icbits -IC:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\include -I.stack-work\dist\274b403a\build\cbits -IC:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\include -I.stack-work\dist\274b403a\build\autogen -I.stack-work\dist\274b403a\build\global-autogen -include .stack-work\dist\274b403a\build\autogen\cabal_macros.h -IC:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\include -IC:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.4\lib\bytestring-0.10.12.0\include -IC:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.4\lib\base-4.14.1.0\include -IC:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.4\lib\integer-gmp-1.0.3.0\include -IC:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.4\lib/include -IC:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.4/lib/include/
regex-posix > error: Wrap.hsc:96:10: fatal error: regex.h: No such file or directory
regex-posix > compilation terminated.
regex-posix >
Progress 1/2
-- While building package regex-posix-0.96.0.0 (scroll up to its section to see the error) using:
C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_3.2.1.0_ghc-8.10.4.exe --builddir=.stack-work\dist\274b403a build --ghc-options " -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
I don't understand the initial warning. When looking at the regex-posix package's dependencies, it does list base (>=4.3 && <4.16) as a dependency, but where does the <0 come from?
I've set the resolver to LTS 18.0 in stack.yaml:
resolver: lts-18.0
According to the documentation of LTS 18.0, it uses base-4.14.1.0. If the versioning is lexicographic, I'd think that 4.14.1.0 fits the range that regex-posix requires (if we, for a moment, ignore the strange <0 constraint).
Here are the relevant parts of my package.yaml:
dependencies:
- base >= 4.7 && < 5
- regex-posix >= 0.96
library:
source-dirs: src
ghc-options:
- -Wall
My stack version:
$ stack --version
Version 2.7.1, Git revision 8afe0c2932716b0441cf4440d6942c59568b6b19 x86_64 hpack-0.34.4
I'm on Windows 10.
FWIW, it's not that I care much about regex-posix in itself. In reality, I'm trying to set up a test project, and test-framework depends on regex-posix.
How can I resolve this issue so that I can compile my code?
The error is not about the version, that is just a warning. The real error is about a missing "regex.h" header for the underlying C library. That header is almost always present on posix platforms (like linux), but not on Windows. See https://github.com/haskell-hvr/regex-posix/issues/4
Particularly this comment by Paul Johnson:
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
In that thread there is also a comment about the <0 version: https://github.com/haskell-hvr/regex-posix/issues/4#issuecomment-699786233

flycheck-haskell and doctest don't work on Cabal 3.0 v2-build project

I tried to create a Nix-style local build (v2-build) project on Cabal 3.0.
But several development tools (flycheck-haskell and doctest) don't work.
They worked on new-build project on Cabal 2.4.
Error message says they cannot find dependencies, as far as I read.
$ cabal v2-clean
$ cabal v2-build
$ cabal v2-test
Build profile: -w ghc-8.8.1 -O1
In order, the following will be built (use -v for more details):
- hstest9-0.1.0.0 (test:doctestd) (first run)
Configuring test suite 'doctestd' for hstest9-0.1.0.0..
Preprocessing test suite 'doctestd' for hstest9-0.1.0.0..
Building test suite 'doctestd' for hstest9-0.1.0.0..
[1 of 1] Compiling Main ( test/doctest-driver.hs, /Users/user/work/hstest9/dist-newstyle/build/x86_64-osx/ghc-8.8.1/hstest9-0.1.0.0/t/doctestd/build/doctestd/doctestd-tmp/Main.o )
Linking /Users/user/work/hstest9/dist-newstyle/build/x86_64-osx/ghc-8.8.1/hstest9-0.1.0.0/t/doctestd/build/doctestd/doctestd ...
Running 1 test suites...
Test suite doctestd: RUNNING...
/Users/user/work/hstest9/src/MyLib.hs:3:1: error:
Could not find module ‘Control.Effect’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
3 | import Control.Effect
| ^^^^^^^^^^^^^^^^^^^^^
Test suite doctestd: FAIL
Test suite logged to:
/Users/user/work/hstest9/dist-newstyle/build/x86_64-osx/ghc-8.8.1/hstest9-0.1.0.0/t/doctestd/test/hstest9-0.1.0.0-doctestd.log
0 of 1 test suites (0 of 1 test cases) passed.
cabal: Tests failed for test:doctestd from hstest9-0.1.0.0.
Your doctest doesn't find proper GHC_ENVIRONEMNT.
Since Cabal 3.0, cabal v2-build doesn't generate environment files by default.
Since Cabal 3.0, defaults to never. Before that, defaulted to creating them only when compiling with GHC 8.4.4 and older (GHC 8.4.4 is the first version that supports the -package-env - option that allows ignoring the package environment files).
https://www.haskell.org/cabal/users-guide/nix-local-build.html#cfg-field-write-ghc-environment-files
So you should set this option on v2-build.
$ cabal v2-build --write-ghc-environment-files=ghc8.4.4+
Or you can write this in $HOME/.cabal/config for default cabal behavior.
write-ghc-environment-files: ghc8.4.4+

Using Build-Tools (Alex) with Stack and GHCjs

I depend on a package that needs alex to build, i also need ghcjs.
When i try to run stack ghci:
language-java-0.2.8: configure (lib)
Error:
-- While building package language-java-0.2.8 using:
<long command>
Process exited with code: ExitFailure 1
Logs have been written to: /Users/LeanderK/Documents/Haskell/exemplator-java_parser/.stack-work/logs/language-java-0.2.8.log
Configuring language-java-0.2.8...
Cabal-simple_mPHDZzAJ_1.24.2.0_ghcjs-0.2.1.9007019_ghc-8.0.1: The program
'alex' version >=3.1.3 is required but it could not be found.
Warning: Build failed, but optimistically launching GHCi anyway
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Configuring GHCi with the following packages: exemplator-client
Using main module: 1. Package `exemplator-client' component exe:exemplator-client-exe with main-is file: ..../app/Main.hs
Progress: 1/2<command line>: cannot satisfy -package language-java-0.2.8
(use -v for more information)
I've tried: stack build alex (just returns, don't have any output. Might work), stack install alex (doesn't work).
Output of stack install alex
Couldn't find executable alex in directory .../.stack/snapshots/x86_64-osx/lts-7.19/ghcjs-0.2.1.9007019_ghc-8.0.1/bin/
For reference: This is the cabal file of the dependency, unfortunately only found on github. This is my stack and my cabal file. There is also a reddit discussion that didn't go anywhere.

Hidden package binary-0.7.5.0?

I get this error:
Could not find module ‘Data.Binary’
It is a member of the hidden package ‘binary-0.7.5.0#binar_IvYoLp9H6Xy3zEH13MmZwd’.
as I import Data.Binary in my stack project with GHCi version 7.10.2.
Strange things are that this does not appear if I execute the GHCi through stack exec ghci, and that I cannot install newer versions of binary package through stack, which looks:
D:\p>stack install binary
Setting codepage to UTF-8 (65001) to ensure correct output from GHC
NOTE: the install command is functionally equivalent to 'build --copy-bins'
D:\p>stack install binary-0.7.6.1
Setting codepage to UTF-8 (65001) to ensure correct output from GHC
NOTE: the install command is functionally equivalent to 'build --copy-bins'
Error parsing targets: Specified target version 0.7.6.1 for package binary does not match snapshot version 0.7.5.0
D:\p>stack install binary-0.7.5.0
Setting codepage to UTF-8 (65001) to ensure correct output from GHC
NOTE: the install command is functionally equivalent to 'build --copy-bins'
How would you get around this problem?
Add binary dependency to your cabal file.
build-depends: base >= 4.7 && < 5
, binary >= 0.7.5
When you use stack install you are installing certain library or executable but not as dependency (e.g. is a utility like yesod or some library you are using only inside ghci ...).

Resources