help needed configuring GHC API client

I'm writing client code against the GHC API in HEAD (version 9.3), using 9.0.1 as my bootstrap compiler. To make it possible to build this code, I've set up cabal using cabal v1-configure \ --package-db clear \ --package-db $STAGE0/lib/package.conf.d/ # stage0 libraries In my Haskell code I'm invoking `runGhc (Just thelibdir)` where thelibir = "/home/nr/asterius/ghc/_build/stage0/lib" which is my `$STAGE0/lib`. Unfortunuately, when I launch my app, `setSessionDynFlags` panics. The output, along with some diagnostic information about some dflags that seemed relevant, looks like this: libdir = /home/nr/asterius/ghc/_build/stage0/lib includePaths = IncludeSpecs {includePathsQuote = [], includePathsGlobal = [], includePathsQuoteImplicit = []} libraryPaths = [] packageDBFlags = [] packageEnv = Nothing panic! (the 'impossible' happened) GHC version 9.3.20210918: GHC couldn't find the RTS constants (#define HS_CONSTANTS ") in /home/nr/.ghcup/ghc/9.0.1/lib/ghc-9.0.1/include/DerivedConstants.h: the RTS package you are trying to use is perhaps for another GHC version(e.g. you are using the wrong package database) or the package database is broken. CallStack (from HasCallStack): error, called at _build/stage0/compiler/build/GHC/Platform/Constants.hs:143:20 in ghc:GHC.Platform.Constants Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug I'm a little suprprised that my app is hunting for 9.3 information in the tree that belongs to the bootstrap compiler. I could start tinkering with `packageEnv` or other dflags, but I'm on thin ice here, and I thought it made more sense to ask for advice. What is going on in my configuration, and how can I set up my app so it is using the library in my `libdir` rather than the library that belongs to the bootstrap compiler? Norman

Norman Ramsey
I'm writing client code against the GHC API in HEAD (version 9.3), using 9.0.1 as my bootstrap compiler. To make it possible to build this code, I've set up cabal using
cabal v1-configure \ --package-db clear \ --package-db $STAGE0/lib/package.conf.d/ # stage0 libraries
In my Haskell code I'm invoking `runGhc (Just thelibdir)` where
thelibir = "/home/nr/asterius/ghc/_build/stage0/lib"
which is my `$STAGE0/lib`.
Unfortunuately, when I launch my app, `setSessionDynFlags` panics. The output, along with some diagnostic information about some dflags that seemed relevant, looks like this:
libdir = /home/nr/asterius/ghc/_build/stage0/lib includePaths = IncludeSpecs {includePathsQuote = [], includePathsGlobal = [], includePathsQuoteImplicit = []} libraryPaths = [] packageDBFlags = [] packageEnv = Nothing panic! (the 'impossible' happened) GHC version 9.3.20210918: GHC couldn't find the RTS constants (#define HS_CONSTANTS ") in /home/nr/.ghcup/ghc/9.0.1/lib/ghc-9.0.1/include/DerivedConstants.h: the RTS package you are trying to use is perhaps for another GHC version(e.g. you are using the wrong package database) or the package database is broken.
CallStack (from HasCallStack): error, called at _build/stage0/compiler/build/GHC/Platform/Constants.hs:143:20 in ghc:GHC.Platform.Constants
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
I'm a little suprprised that my app is hunting for 9.3 information in the tree that belongs to the bootstrap compiler.
I suspect that the stages are getting mixed up here. Would it be possible to post a full reproducer? I'd be happy to investigate further, but without being able to reproduce locally it's a bit hard to say anything useful. My recollection is that we look for DerivedConstants.h in the usual include paths, so there are many ways in which things could go wrong. Cheers, - Ben

Hi Norman,
in addition to what Ben already said: is there any particular reason you
wanted to use the stage0 compiler? I have written a small program against
HEAD which used the GHC API fairly recently, and I have simply used the
`stage1` compiler. An excerpt from my little code snippet:
```
-- This is just the output of '_build/stage1/bin/ghc --print-libdir'
myGhcLibDir :: FilePath
myGhcLibDir = "./_build/stage1/lib"
playground :: FilePath -> IO ()
playground fn = do
res <- runGhc (Just myGhcLibDir) $ do
...
```
As you can see that's exactly what you are doing, modulo the fact I was
using the `stage1` (where _build is the default directory for Hadrian
builds).
Hope this helps in some way!
A.
On Fri, 24 Sept 2021 at 03:37, Ben Gamari
Norman Ramsey
writes: I'm writing client code against the GHC API in HEAD (version 9.3), using 9.0.1 as my bootstrap compiler. To make it possible to build this code, I've set up cabal using
cabal v1-configure \ --package-db clear \ --package-db $STAGE0/lib/package.conf.d/ # stage0 libraries
In my Haskell code I'm invoking `runGhc (Just thelibdir)` where
thelibir = "/home/nr/asterius/ghc/_build/stage0/lib"
which is my `$STAGE0/lib`.
Unfortunuately, when I launch my app, `setSessionDynFlags` panics. The output, along with some diagnostic information about some dflags that seemed relevant, looks like this:
libdir = /home/nr/asterius/ghc/_build/stage0/lib includePaths = IncludeSpecs {includePathsQuote = [], includePathsGlobal = [], includePathsQuoteImplicit = []} libraryPaths = [] packageDBFlags = [] packageEnv = Nothing panic! (the 'impossible' happened) GHC version 9.3.20210918: GHC couldn't find the RTS constants (#define HS_CONSTANTS ") in /home/nr/.ghcup/ghc/9.0.1/lib/ghc-9.0.1/include/DerivedConstants.h: the RTS package you are trying to use is perhaps for another GHC version(e.g. you are using the wrong package database) or the package database is broken.
CallStack (from HasCallStack): error, called at _build/stage0/compiler/build/GHC/Platform/Constants.hs:143:20 in ghc:GHC.Platform.Constants
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
I'm a little suprprised that my app is hunting for 9.3 information in the tree that belongs to the bootstrap compiler.
I suspect that the stages are getting mixed up here. Would it be possible to post a full reproducer? I'd be happy to investigate further, but without being able to reproduce locally it's a bit hard to say anything useful. My recollection is that we look for DerivedConstants.h in the usual include paths, so there are many ways in which things could go wrong.
Cheers,
- Ben _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

in addition to what Ben already said: is there any particular reason you wanted to use the stage0 compiler?
Yes! I want to use the Haskell Language Server with my code. I am given to understand that HLS does not work with GHC HEAD, so if I want to use HLS with my own code, it needs to be compiled with the bootstrap compiler, which *does* support HLS. Therefore I am using stage0 so that my own code and the GHC library are compiled with the same compiler. I will, however, repeat my experiment using stage1. It would be good to confirm your experience. Norman

Alfredo, I've confirmed that I can use the stage1 compiler and it doesn't panic. It occurs to me that I might be able to *compile* my code with the stage1 compiler while using the bootstrap compiler and Haskell Language Server. I'll give that a shot. Norman
Hi Norman,
in addition to what Ben already said: is there any particular reason you wanted to use the stage0 compiler? I have written a small program against HEAD which used the GHC API fairly recently, and I have simply used the `stage1` compiler. An excerpt from my little code snippet:
``` -- This is just the output of '_build/stage1/bin/ghc --print-libdir' myGhcLibDir :: FilePath myGhcLibDir = "./_build/stage1/lib"
playground :: FilePath -> IO () playground fn = do res <- runGhc (Just myGhcLibDir) $ do ... ```
As you can see that's exactly what you are doing, modulo the fact I was using the `stage1` (where _build is the default directory for Hadrian builds).
Hope this helps in some way!
A.
On Fri, 24 Sept 2021 at 03:37, Ben Gamari
wrote: Norman Ramsey
writes: I'm writing client code against the GHC API in HEAD (version 9.3), using 9.0.1 as my bootstrap compiler. To make it possible to build this code, I've set up cabal using
cabal v1-configure \ --package-db clear \ --package-db $STAGE0/lib/package.conf.d/ # stage0 libraries
In my Haskell code I'm invoking `runGhc (Just thelibdir)` where
thelibir = "/home/nr/asterius/ghc/_build/stage0/lib"
which is my `$STAGE0/lib`.
Unfortunuately, when I launch my app, `setSessionDynFlags` panics. The output, along with some diagnostic information about some dflags that seemed relevant, looks like this:
libdir = /home/nr/asterius/ghc/_build/stage0/lib includePaths = IncludeSpecs {includePathsQuote = [], includePathsGlobal = [], includePathsQuoteImplicit = []} libraryPaths = [] packageDBFlags = [] packageEnv = Nothing panic! (the 'impossible' happened) GHC version 9.3.20210918: GHC couldn't find the RTS constants (#define HS_CONSTANTS ") in /home/nr/.ghcup/ghc/9.0.1/lib/ghc-9.0.1/include/DerivedConstants.h: the RTS package you are trying to use is perhaps for another GHC version(e.g. you are using the wrong package database) or the package database is broken.
CallStack (from HasCallStack): error, called at _build/stage0/compiler/build/GHC/Platform/Constants.hs:143:20 in ghc:GHC.Platform.Constants
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
I'm a little suprprised that my app is hunting for 9.3 information in the tree that belongs to the bootstrap compiler.
I suspect that the stages are getting mixed up here. Would it be possible to post a full reproducer? I'd be happy to investigate further, but without being able to reproduce locally it's a bit hard to say anything useful. My recollection is that we look for DerivedConstants.h in the usual include paths, so there are many ways in which things could go wrong.
Cheers,
- Ben _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

Hi Norman,
I think you are overcomplicating things quite a bit.
1. Build a HEAD (9.3) compiler
2. Setup a normal cabal project to depend on the `ghc` library
3. Use the cabal -w option to point to your HEAD compiler to build the
project (`cabal build -w /path/to/head`)
That will work reliably rather than messing around with package databases.
Matt
On Thu, Sep 23, 2021 at 7:31 PM Norman Ramsey
I'm writing client code against the GHC API in HEAD (version 9.3), using 9.0.1 as my bootstrap compiler. To make it possible to build this code, I've set up cabal using
cabal v1-configure \ --package-db clear \ --package-db $STAGE0/lib/package.conf.d/ # stage0 libraries
In my Haskell code I'm invoking `runGhc (Just thelibdir)` where
thelibir = "/home/nr/asterius/ghc/_build/stage0/lib"
which is my `$STAGE0/lib`.
Unfortunuately, when I launch my app, `setSessionDynFlags` panics. The output, along with some diagnostic information about some dflags that seemed relevant, looks like this:
libdir = /home/nr/asterius/ghc/_build/stage0/lib includePaths = IncludeSpecs {includePathsQuote = [], includePathsGlobal = [], includePathsQuoteImplicit = []} libraryPaths = [] packageDBFlags = [] packageEnv = Nothing panic! (the 'impossible' happened) GHC version 9.3.20210918: GHC couldn't find the RTS constants (#define HS_CONSTANTS ") in /home/nr/.ghcup/ghc/9.0.1/lib/ghc-9.0.1/include/DerivedConstants.h: the RTS package you are trying to use is perhaps for another GHC version(e.g. you are using the wrong package database) or the package database is broken.
CallStack (from HasCallStack): error, called at _build/stage0/compiler/build/GHC/Platform/Constants.hs:143:20 in ghc:GHC.Platform.Constants
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
I'm a little suprprised that my app is hunting for 9.3 information in the tree that belongs to the bootstrap compiler.
I could start tinkering with `packageEnv` or other dflags, but I'm on thin ice here, and I thought it made more sense to ask for advice.
What is going on in my configuration, and how can I set up my app so it is using the library in my `libdir` rather than the library that belongs to the bootstrap compiler?
Norman _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

Hi Norman,
I think you are overcomplicating things quite a bit.
1. Build a HEAD (9.3) compiler 2. Setup a normal cabal project to depend on the `ghc` library 3. Use the cabal -w option to point to your HEAD compiler to build the project (`cabal build -w /path/to/head`)
That will work reliably rather than messing around with package databases.
My understanding is that if I do things this way, I give up the Haskell Language Server. I am in the middle of learning a large, unfamiliar API, and the HLS is a lifeline to the documentation. Am I wrong? Is there another fast path to the documentation? Norman
participants (4)
-
Alfredo Di Napoli
-
Ben Gamari
-
Matthew Pickering
-
Norman Ramsey