clash-lang / clash-compiler

Haskell to VHDL/Verilog/SystemVerilog compiler
https://clash-lang.org/
Other
1.44k stars 154 forks source link

clash-lib doctest errors with GHC 9.4 on Debian #2609

Open swt2c opened 11 months ago

swt2c commented 11 months ago

I'm trying to build clash-lib 1.8.1 on Debian with GHC 9.4.7. The build phase completes successfully, but when running the doctests test suite, I'm running into the below errors. There are lots more of them, all related to MIN_VERSION_ghc. Any ideas what might be going wrong?

Running 2 test suites...
Test suite doctests: RUNNING...

/<<PKGBUILDDIR>>/src/Clash/Backend.hs:24:0: error:
     error: missing binary operator before token "("
       24 | #if MIN_VERSION_ghc(9,0,0)
          | 
   |
24 | #if MIN_VERSION_ghc(9,0,0)
   | ^

/<<PKGBUILDDIR>>/src/Clash/Core/EqSolver.hs:21:0: error:
     error: missing binary operator before token "("
       21 | #if MIN_VERSION_ghc(9,0,0)
          | 
   |
21 | #if MIN_VERSION_ghc(9,0,0)
christiaanb commented 11 months ago

I can replicate by:

cabal get clash-lib-1.8.1
cd clash-lib-1.8.1
cabal test

using:

> cabal --version
cabal-install version 3.8.1.0
compiled using version 3.8.1.0 of the Cabal library 
> ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.4.7
> uname -a
Linux glanerbrug 6.6.1-1-default #1 SMP PREEMPT_DYNAMIC Thu Nov  9 05:27:56 UTC 2023 (1fcc265) x86_64 x86_64 x86_64 GNU/Linux
christiaanb commented 11 months ago

As a work-around we have to do:

cabal get clash-lib-1.8.1
cd clash-lib-1.8.1
cabal build --enable-tests --write-ghc-environment-files=always
cabal test

So the problem is that the created doctest binary depends on the existence of a .ghc.environment.xyz file to get a package database. Perhaps we can find a way to "hardcode" a package database into the generated test binary? @martijnbastiaan any ideas on that?

martijnbastiaan commented 11 months ago

This is https://github.com/martijnbastiaan/doctest-parallel/issues/22.

I don't know of a way to get it from TemplateHaskell. I'm more inclined to look at Cabal's new code-generators feature (see this comment too).

swt2c commented 11 months ago

As a work-around we have to do:

cabal get clash-lib-1.8.1
cd clash-lib-1.8.1
cabal build --enable-tests --write-ghc-environment-files=always
cabal test

There isn't a way to use this workaround when doing a Setup.hs build, is there?

Vekhir commented 11 months ago

I got the same issue on GHC 9.2. @swt2c In case you are still searching for a workaround, the Arch package manually creates that file like this: https://gitlab.archlinux.org/archlinux/packaging/packages/haskell-doctest-parallel/-/blob/main/PKGBUILD?ref_type=heads#L38-44 Note that you have to manually adjust the GHC version (it's 9.0.2 on Arch) and potentially need to install expac (or replace that call with the version manually).

We are also reliant on a Setup.hs build.