Re: Using GHC API with multiple targets

2023-02-06 Thread Matthew Pickering
Can you put the whole example into a github repo and then I will look
at what is wrong?

Matt

On Mon, Feb 6, 2023 at 1:34 PM Eternal Recursion via ghc-devs
 wrote:
>
> Thanks, Andreas!
>
> I will check out the hint package and also play with verbosity and 
> workingDirectory.
>
> I considered using the Cabal library to derive the inputs from the project's 
> cabal file, but it does help first to know what the needful inputs are, and 
> where to stash them in the DynFlags session settings.
>
> It's got to be one of those "One Weird Trick (tm)" gotcha settings that make 
> it suddenly work. It seems obvious what some of the settings mean, but I 
> suppose with more familiarity will come appreciation of nuances that make the 
> apparently obvious meaning seem obviously wrong.
>
> Sincerely,
>
> Bob
>
> Sent with Proton Mail secure email.
>
> --- Original Message ---
> On Monday, February 6th, 2023 at 7:53 AM, Andreas Klebinger 
>  wrote:
>
> I think this is an ok forum for this kind of question. You could also try the 
> haskell mailing list but I'm not sure if you will get more
> help tehre.
>
> I recently played around with the ghc api and I found the `hint` package to 
> be quite helpful as an example on how to do various
> things when using the ghc api to implement your own interpreter.
>
> Have you tried setting verbose? Perhaps the include dir is relative to the 
> working directory. In that case setting:
>
> , workingDirectory = Just targetDir
> , importPaths = [targetDir] ++ importPaths dynflags
>
> would mean ghc will search in targetDir/targetDir for Lib/Lib2. Should be 
> easy to say for sure by enabling verbosity and looking at the output.
>
> Am 06/02/2023 um 13:42 schrieb Eternal Recursion via ghc-devs:
>
> If this is the wrong forum for this question (which as I think about it, I 
> suppose it is) then redirection to a more appropriate mailing list or forum 
> (or any advice, really) would be appreciated. I just figured this would be 
> the forum with the best understanding of how the GHC API works (and has 
> changed over time), and my longer term goal is indeed to contribute to it 
> after I get past my learning curve.
>
> Sincerely,
>
> Bob
>
> Sent with Proton Mail secure email.
>
> --- Original Message ---
> On Saturday, February 4th, 2023 at 4:04 PM, Eternal Recursion via ghc-devs 
>  wrote:
>
> Hi Everyone!
>
> I'm new here, trying to learn the GHC API. using 944 with cabal 3.8.1.0.
>
> How do I correctly set a GHC Session's DynFlags (and/or other properties) to 
> ensure local libraries imported by the main target are resolved properly at 
> compile time?
>
> What flags need to be set so that GHC is able to load/analyze/compile all 
> relevant Libraries in a package?
>
> This is my current code:
>
> withPath :: FilePath -> IO ()
> withPath target = do
> let targetDir = takeDirectory target
> let targetFile = takeFileName target
> listing <- listDirectory targetDir
> let imports = filter (\f -> takeExtension f == ".hs") listing
> print imports
> let moduleName = mkModuleName targetFile
> g <- defaultErrorHandler defaultFatalMessager defaultFlushOut
> $ runGhc (Just libdir) $ do
> initGhcMonad (Just libdir)
> dynflags <- getSessionDynFlags
> setSessionDynFlags $ dynflags { ghcLink = LinkInMemory
> , ghcMode = CompManager
> , backend = Interpreter
> , mainModuleNameIs = moduleName
> , workingDirectory = Just targetDir
> , importPaths = [targetDir] ++ importPaths dynflags
> }
> targets <- mapM (\t -> guessTarget t Nothing Nothing) imports
> setTargets targets
> setContext [ IIDecl $ simpleImportDecl (mkModuleName "Prelude") ]
> load LoadAllTargets
> liftIO . print . ppr =<< getTargets
> getModuleGraph
> putStrLn "Here we go!"
> print $ ppr $ mgModSummaries g
> putStrLn "☝️ "
>
> However, when I run it (passing to example/app/Main.hs, in which directory 
> are Lib.hs and Lib2.hs, the latter being imported into Main), I get:
>
> $ cabal run cli -- example/app/Main.hs
> Up to date
> ["Main.hs","Lib.hs","Lib2.hs"]
> [main:Main.hs, main:Lib.hs, main:Lib2.hs]
> Here we go!
> [ModSummary {
> ms_hs_hash = 23f9c4415bad851a1e36db9d813f34be
> ms_mod = Lib,
> unit = main
> ms_textual_imps = [(, Prelude)]
> ms_srcimps = []
> },
> ModSummary {
> ms_hs_hash = e1eccc23af49f3498a5a9566e63abefd
> ms_mod = Lib2,
> unit = main
> ms_textual_imps = [(, Prelude)]
> ms_srcimps = []
> },
> ModSummary {
> ms_hs_hash = 5f6751d7f0d5547a1bdf39af84f8c07f
> ms_mod = Main,
> unit = main
> ms_textual_imps = [(, Prelude), (, Lib2)]
> ms_srcimps = []
> }]
> ☝
>
> example/app/Main.hs:4:1: error:
> Could not find module ‘Lib2’
> Use -v (or `:set -v` in ghci) to see a list of the files searched for.
> |
> 4 | import qualified Lib2 as L2
> | ^^^
> cli: example/app/Main.hs:4:1: error:
> Could not find module `Lib2'
> Use -v (or `:set -v` in ghci) to see a list of the files searched for.
>
> What do I need to do differently to make this work?
>
> I have a local Cabal file I could use, but 

Re: Using GHC API with multiple targets

2023-02-06 Thread Eternal Recursion via ghc-devs
Thanks, Andreas!

I will check out the hint​ package and also play with verbosity and 
workingDirectory.

I considered using the Cabal library to derive the inputs from the project's 
cabal file, but it does help first to know what the needful inputs are, and 
where to stash them in the DynFlags session settings.

It's got to be one of those "One Weird Trick (tm)" gotcha settings that make it 
suddenly work. It seems obvious what some of the settings mean, but I suppose 
with more familiarity will come appreciation of nuances that make the 
apparently obvious meaning seem obviously wrong.

Sincerely,

Bob

Sent with [Proton Mail](https://proton.me/) secure email.

--- Original Message ---
On Monday, February 6th, 2023 at 7:53 AM, Andreas Klebinger 
 wrote:

> I think this is an ok forum for this kind of question. You could also try the 
> haskell mailing list but I'm not sure if you will get more
> help tehre.
>
> I recently played around with the ghc api and I found the `hint` package to 
> be quite helpful as an example on how to do various
> things when using the ghc api to implement your own interpreter.
>
> Have you tried setting verbose? Perhaps the include dir is relative to the 
> working directory. In that case setting:
>
> , workingDirectory = Just targetDir
> , importPaths = [targetDir] ++ importPaths dynflags
>
> would mean ghc will search in targetDir/targetDir for Lib/Lib2. Should be 
> easy to say for sure by enabling verbosity and looking at the output.
>
> Am 06/02/2023 um 13:42 schrieb Eternal Recursion via ghc-devs:
>
>> If this is the wrong forum for this question (which as I think about it, I 
>> suppose it is) then redirection to a more appropriate mailing list or forum 
>> (or any advice, really) would be appreciated. I just figured this would be 
>> the forum with the best understanding of how the GHC API works (and has 
>> changed over time), and my longer term goal is indeed to contribute to it 
>> after I get past my learning curve.
>>
>> Sincerely,
>>
>> Bob
>>
>> Sent with [Proton Mail](https://proton.me/) secure email.
>>
>> --- Original Message ---
>> On Saturday, February 4th, 2023 at 4:04 PM, Eternal Recursion via ghc-devs 
>> [](mailto:ghc-devs@haskell.org) wrote:
>>
>>> Hi Everyone!
>>>
>>> I'm new here, trying to learn the GHC API. using 944 with cabal 3.8.1.0.
>>>
>>> How do I correctly set a GHC Session's DynFlags (and/or other properties) 
>>> to ensure local libraries imported by the main target are resolved properly 
>>> at compile time?
>>>
>>> What flags need to be set so that GHC is able to load/analyze/compile all 
>>> relevant Libraries in a package?
>>>
>>> This is my current code:
>>>
>>> withPath :: FilePath -> IO ()
>>> withPath target = do
>>> let targetDir = takeDirectory target
>>> let targetFile = takeFileName target
>>> listing <- listDirectory targetDir
>>> let imports = filter (\f -> takeExtension f == ".hs") listing
>>> print imports
>>> let moduleName = mkModuleName targetFile
>>> g <- defaultErrorHandler defaultFatalMessager defaultFlushOut
>>> $ runGhc (Just libdir) $ do
>>> initGhcMonad (Just libdir)
>>> dynflags <- getSessionDynFlags
>>> setSessionDynFlags $ dynflags { ghcLink = LinkInMemory
>>> , ghcMode = CompManager
>>> , backend = Interpreter
>>> , mainModuleNameIs = moduleName
>>> , workingDirectory = Just targetDir
>>> , importPaths = [targetDir] ++ importPaths dynflags
>>> }
>>>
>>> targets <- mapM (\t -> guessTarget t Nothing Nothing) imports
>>> setTargets targets
>>> setContext [ IIDecl $ simpleImportDecl (mkModuleName "Prelude") ]
>>> load LoadAllTargets
>>> liftIO . print . ppr =<< getTargets
>>> getModuleGraph
>>> putStrLn "Here we go!"
>>> print $ ppr $ mgModSummaries g  putStrLn "☝️ "
>>>
>>> However, when I run it (passing to example/app/Main.hs, in which directory 
>>> are Lib.hs and Lib2.hs, the latter being imported into Main), I get:
>>>
>>> $ cabal run cli -- example/app/Main.hs
>>> Up to date
>>> ["Main.hs","Lib.hs","Lib2.hs"]
>>> [main:Main.hs, main:Lib.hs, main:Lib2.hs]
>>> Here we go!
>>> [ModSummary {
>>> ms_hs_hash = 23f9c4415bad851a1e36db9d813f34be
>>> ms_mod = Lib,
>>> unit = main
>>> ms_textual_imps = [(, Prelude)]
>>> ms_srcimps = []
>>> },
>>> ModSummary {
>>> ms_hs_hash = e1eccc23af49f3498a5a9566e63abefd
>>> ms_mod = Lib2,
>>> unit = main
>>> ms_textual_imps = [(, Prelude)]
>>> ms_srcimps = []
>>> },
>>> ModSummary {
>>> ms_hs_hash = 5f6751d7f0d5547a1bdf39af84f8c07f
>>> ms_mod = Main,
>>> unit = main
>>> ms_textual_imps = [(, Prelude), (, Lib2)]
>>> ms_srcimps = []
>>> }]
>>> ☝
>>>
>>> example/app/Main.hs:4:1: error:
>>> Could not find module ‘Lib2’
>>> Use -v (or `:set -v` in ghci) to see a list of the files searched for.
>>> |
>>> 4 |import qualified Lib2 as L2
>>> | ^^^
>>> cli: example/app/Main.hs:4:1: error:
>>> Could not find module `Lib2'
>>> Use -v (or `:set -v` in ghci) to see a list of the files searched for.
>>>
>>> ​What do I need to do differently to make 

Re: Using GHC API with multiple targets

2023-02-06 Thread Eternal Recursion via ghc-devs
Tbh, the current code is a bit of a Frankenstein cobbled together from the dead 
limbs of online GHC API tutorials past. I think that line was the swollen 
appendix of something. :)

But I can confirm that commenting out that line does not help. I get exactly 
the same module graph output and error message.

I will add enhanced verbosity as Andreas suggests and see under what rocks it's 
looking for Lib2. I can't believe it can't find it. I mean, it's right there.

Looking at the module graph, I gather I should want to see the local modules 
Lib and Lib2 in the ms_srcimps list. The ms_textual_imps list appears to be 
just a list of what modules are listed in the imports statements.

I also note parenthetically that the Lib import line is commented out in 
Main.hs. When I add it, it seems to be resolving to the wrong Lib module 
(libiserve or something like that IIRC) and then complains the function I'm 
trying to call isn't exported by it.

Any background about DynFlags for context is appreciated. It seems a rather 
large construct that has seen some mission creep and redesign efforts over the 
years...

Sincerely,

Bob


Sent with Proton Mail secure email.

--- Original Message ---
On Monday, February 6th, 2023 at 7:59 AM, Matthew Pickering 
 wrote:


> Looks like it would work to me if you remove
> 
> `setContext [ IIDecl $ simpleImportDecl (mkModuleName "Prelude") ]`
> 
> Why do you have this line?
> 
> Matt
> 
> On Mon, Feb 6, 2023 at 12:54 PM Andreas Klebinger
> klebinger.andr...@gmx.at wrote:
> 
> > I think this is an ok forum for this kind of question. You could also try 
> > the haskell mailing list but I'm not sure if you will get more
> > help tehre.
> > 
> > I recently played around with the ghc api and I found the `hint` package to 
> > be quite helpful as an example on how to do various
> > things when using the ghc api to implement your own interpreter.
> > 
> > Have you tried setting verbose? Perhaps the include dir is relative to the 
> > working directory. In that case setting:
> > 
> > , workingDirectory = Just targetDir
> > , importPaths = [targetDir] ++ importPaths dynflags
> > 
> > would mean ghc will search in targetDir/targetDir for Lib/Lib2. Should be 
> > easy to say for sure by enabling verbosity and looking at the output.
> > 
> > Am 06/02/2023 um 13:42 schrieb Eternal Recursion via ghc-devs:
> > 
> > If this is the wrong forum for this question (which as I think about it, I 
> > suppose it is) then redirection to a more appropriate mailing list or forum 
> > (or any advice, really) would be appreciated. I just figured this would be 
> > the forum with the best understanding of how the GHC API works (and has 
> > changed over time), and my longer term goal is indeed to contribute to it 
> > after I get past my learning curve.
> > 
> > Sincerely,
> > 
> > Bob
> > 
> > Sent with Proton Mail secure email.
> > 
> > --- Original Message ---
> > On Saturday, February 4th, 2023 at 4:04 PM, Eternal Recursion via ghc-devs 
> > ghc-devs@haskell.org wrote:
> > 
> > Hi Everyone!
> > 
> > I'm new here, trying to learn the GHC API. using 944 with cabal 3.8.1.0.
> > 
> > How do I correctly set a GHC Session's DynFlags (and/or other properties) 
> > to ensure local libraries imported by the main target are resolved properly 
> > at compile time?
> > 
> > What flags need to be set so that GHC is able to load/analyze/compile all 
> > relevant Libraries in a package?
> > 
> > This is my current code:
> > 
> > withPath :: FilePath -> IO ()
> > withPath target = do
> > let targetDir = takeDirectory target
> > let targetFile = takeFileName target
> > listing <- listDirectory targetDir
> > let imports = filter (\f -> takeExtension f == ".hs") listing
> > print imports
> > let moduleName = mkModuleName targetFile
> > g <- defaultErrorHandler defaultFatalMessager defaultFlushOut
> > $ runGhc (Just libdir) $ do
> > initGhcMonad (Just libdir)
> > dynflags <- getSessionDynFlags
> > setSessionDynFlags $ dynflags { ghcLink = LinkInMemory
> > , ghcMode = CompManager
> > , backend = Interpreter
> > , mainModuleNameIs = moduleName
> > , workingDirectory = Just targetDir
> > , importPaths = [targetDir] ++ importPaths dynflags
> > }
> > 
> > targets <- mapM (\t -> guessTarget t Nothing Nothing) imports
> > setTargets targets
> > setContext [ IIDecl $ simpleImportDecl (mkModuleName "Prelude") ]
> > load LoadAllTargets
> > liftIO . print . ppr =<< getTargets
> > getModuleGraph
> > putStrLn "Here we go!"
> > print $ ppr $ mgModSummaries g
> > putStrLn "☝️ "
> > 
> > However, when I run it (passing to example/app/Main.hs, in which directory 
> > are Lib.hs and Lib2.hs, the latter being imported into Main), I get:
> > 
> > $ cabal run cli -- example/app/Main.hs
> > Up to date
> > ["Main.hs","Lib.hs","Lib2.hs"]
> > [main:Main.hs, main:Lib.hs, main:Lib2.hs]
> > Here we go!
> > [ModSummary {
> > ms_hs_hash = 23f9c4415bad851a1e36db9d813f34be
> > ms_mod = Lib,
> > unit = main
> > ms_textual_imps = [(, 

Re: Using GHC API with multiple targets

2023-02-06 Thread Matthew Pickering
Looks like it would work to me if you remove

```
setContext [ IIDecl $ simpleImportDecl (mkModuleName "Prelude") ]
```

Why do you have this line?

Matt

On Mon, Feb 6, 2023 at 12:54 PM Andreas Klebinger
 wrote:
>
> I think this is an ok forum for this kind of question. You could also try the 
> haskell mailing list but I'm not sure if you will get more
> help tehre.
>
> I recently played around with the ghc api and I found the `hint` package to 
> be quite helpful as an example on how to do various
> things when using the ghc api to implement your own interpreter.
>
> Have you tried setting verbose? Perhaps the include dir is relative to the 
> working directory. In that case setting:
>
>   , workingDirectory = Just targetDir
>   , importPaths  = [targetDir] ++ 
> importPaths dynflags
>
> would mean ghc will search in targetDir/targetDir for Lib/Lib2. Should be 
> easy to say for sure by enabling verbosity and looking at the output.
>
> Am 06/02/2023 um 13:42 schrieb Eternal Recursion via ghc-devs:
>
> If this is the wrong forum for this question (which as I think about it, I 
> suppose it is) then redirection to a more appropriate mailing list or forum 
> (or any advice, really) would be appreciated. I just figured this would be 
> the forum with the best understanding of how the GHC API works (and has 
> changed over time), and my longer term goal is indeed to contribute to it 
> after I get past my learning curve.
>
> Sincerely,
>
> Bob
>
> Sent with Proton Mail secure email.
>
> --- Original Message ---
> On Saturday, February 4th, 2023 at 4:04 PM, Eternal Recursion via ghc-devs 
>  wrote:
>
> Hi Everyone!
>
> I'm new here, trying to learn the GHC API. using 944 with cabal 3.8.1.0.
>
> How do I correctly set a GHC Session's DynFlags (and/or other properties) to 
> ensure local libraries imported by the main target are resolved properly at 
> compile time?
>
> What flags need to be set so that GHC is able to load/analyze/compile all 
> relevant Libraries in a package?
>
> This is my current code:
>
> withPath :: FilePath -> IO ()
> withPath target = do
>   let targetDir = takeDirectory target
>   let targetFile = takeFileName target
>   listing <- listDirectory targetDir
>   let imports = filter (\f -> takeExtension f == ".hs") listing
>   print imports
>   let moduleName = mkModuleName targetFile
>   g <- defaultErrorHandler defaultFatalMessager defaultFlushOut
> $ runGhc (Just libdir) $ do
> initGhcMonad (Just libdir)
> dynflags <- getSessionDynFlags
> setSessionDynFlags $ dynflags { ghcLink  = LinkInMemory
>   , ghcMode  = CompManager
>   , backend  = Interpreter
>   , mainModuleNameIs = moduleName
>   , workingDirectory = Just targetDir
>   , importPaths  = [targetDir] ++ 
> importPaths dynflags
>   }
>
> targets <- mapM (\t -> guessTarget t Nothing Nothing) imports
> setTargets targets
> setContext [ IIDecl $ simpleImportDecl (mkModuleName "Prelude") ]
> load LoadAllTargets
> liftIO . print . ppr =<< getTargets
> getModuleGraph
>   putStrLn "Here we go!"
>   print $ ppr $ mgModSummaries g
>   putStrLn "☝️ "
>
> However, when I run it (passing to example/app/Main.hs, in which directory 
> are Lib.hs and Lib2.hs, the latter being imported into Main), I get:
>
> $ cabal run cli -- example/app/Main.hs
> Up to date
> ["Main.hs","Lib.hs","Lib2.hs"]
> [main:Main.hs, main:Lib.hs, main:Lib2.hs]
> Here we go!
> [ModSummary {
>ms_hs_hash = 23f9c4415bad851a1e36db9d813f34be
>ms_mod = Lib,
>unit = main
>ms_textual_imps = [(, Prelude)]
>ms_srcimps = []
> },
> ModSummary {
>ms_hs_hash = e1eccc23af49f3498a5a9566e63abefd
>ms_mod = Lib2,
>unit = main
>ms_textual_imps = [(, Prelude)]
>ms_srcimps = []
> },
> ModSummary {
>ms_hs_hash = 5f6751d7f0d5547a1bdf39af84f8c07f
>ms_mod = Main,
>unit = main
>ms_textual_imps = [(, Prelude), (, Lib2)]
>ms_srcimps = []
> }]
> ☝
>
> example/app/Main.hs:4:1: error:
>Could not find module ‘Lib2’
>Use -v (or `:set -v` in ghci) to see a list of the files searched for.
>  |
> 4 | import qualified Lib2 as L2
>  | ^^^
> cli: example/app/Main.hs:4:1: error:
>Could not find module `Lib2'
>Use -v (or `:set -v` in ghci) to see a list of the files searched for.
>
> What do I need to do differently to make this work?
>
> I have a local Cabal file I could use, but to know what I need out of it, I 
> need to understand the minimum required info to get this to work. TIA!
>
> Sincerely,
>
> Bob
>
> Sent with Proton Mail secure email.
>
>
>
> ___
> ghc-devs mailing list
> ghc-devs@haskell.org
> 

Re: Using GHC API with multiple targets

2023-02-06 Thread Andreas Klebinger

I think this is an ok forum for this kind of question. You could also
try the haskell mailing list but I'm not sure if you will get more
help tehre.

I recently played around with the ghc api and I found the `hint` package
to be quite helpful as an example on how to do various
things when using the ghc api to implement your own interpreter.

Have you tried setting verbose? Perhaps the include dir is relative to
the working directory. In that case setting:

                  , workingDirectory = Just targetDir
                  , importPaths      = [targetDir] ++ importPaths dynflags

would mean ghc will search in targetDir/targetDir for Lib/Lib2. Should
be easy to say for sure by enabling verbosity and looking at the output.

Am 06/02/2023 um 13:42 schrieb Eternal Recursion via ghc-devs:

If this is the wrong forum for this question (which as I think about
it, I suppose it is) then redirection to a more appropriate mailing
list or forum (or any advice, really) would be appreciated. I just
figured this would be the forum with the best understanding of how the
GHC API works (and has changed over time), and my longer term goal is
indeed to contribute to it after I get past my learning curve.

Sincerely,

Bob

Sent with Proton Mail  secure email.

--- Original Message ---
On Saturday, February 4th, 2023 at 4:04 PM, Eternal Recursion via
ghc-devs  wrote:


Hi Everyone!

I'm new here, trying to learn the GHC API. using 944 with cabal 3.8.1.0.

How do I correctly set a GHC Session's DynFlags (and/or other
properties) to ensure local libraries imported by the main target are
resolved properly at compile time?

What flags need to be set so that GHC is able to load/analyze/compile
all relevant Libraries in a package?

This is my current code:

withPath :: FilePath -> IO ()
withPath target = do
let targetDir = takeDirectory target
  let targetFile = takeFileName target
listing <- listDirectory targetDir
  let imports = filter (\f -> takeExtension f == ".hs") listing
  print imports
  let moduleName = mkModuleName targetFile
  g <- defaultErrorHandler defaultFatalMessager defaultFlushOut
    $ runGhc (Just libdir) $ do
initGhcMonad (Just libdir)
dynflags <- getSessionDynFlags
setSessionDynFlags $ dynflags { ghcLink          = LinkInMemory
                          , ghcMode          = CompManager
                          , backend          = Interpreter
                          , mainModuleNameIs = moduleName
                          , workingDirectory = Just targetDir
                          , importPaths      = [targetDir] ++
importPaths dynflags
                          }
targets <- mapM (\t -> guessTarget t Nothing Nothing) imports
setTargets targets
setContext [ IIDecl $ simpleImportDecl (mkModuleName "Prelude") ]
load LoadAllTargets
liftIO . print . ppr =<< getTargets
getModuleGraph
putStrLn "Here we go!"
  print $ ppr $ mgModSummaries g
putStrLn "☝️ "

However, when I run it (passing to example/app/Main.hs, in which
directory are Lib.hs and Lib2.hs, the latter being imported into
Main), I get:

$cabal run cli -- example/app/Main.hs
Up to date
["Main.hs","Lib.hs","Lib2.hs"]
[main:Main.hs, main:Lib.hs, main:Lib2.hs]
Here we go!
[ModSummary {
   ms_hs_hash = 23f9c4415bad851a1e36db9d813f34be
   ms_mod = Lib,
   unit = main
   ms_textual_imps = [(, Prelude)]
   ms_srcimps = []
},
ModSummary {
   ms_hs_hash = e1eccc23af49f3498a5a9566e63abefd
   ms_mod = Lib2,
   unit = main
   ms_textual_imps = [(, Prelude)]
   ms_srcimps = []
},
ModSummary {
   ms_hs_hash = 5f6751d7f0d5547a1bdf39af84f8c07f
   ms_mod = Main,
   unit = main
   ms_textual_imps = [(, Prelude), (, Lib2)]
   ms_srcimps = []
}]
☝

example/app/Main.hs:4:1: error:
   Could not find module ‘Lib2’
   Use -v (or `:set -v` in ghci) to see a list of the files searched for.
 |
4 |import qualified Lib2 as L2
 |^^^
cli: example/app/Main.hs:4:1: error:
   Could not find module `Lib2'
   Use -v (or `:set -v` in ghci) to see a list of the files searched
for.

​What do I need to do differently to make this work?

I have a local Cabal file I could use, but to know what I need out of
it, I need to understand the minimum required info to get this to
work. TIA!

Sincerely,

Bob

Sent with Proton Mail  secure email.



___
ghc-devs mailing list
ghc-devs@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
___
ghc-devs mailing list
ghc-devs@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs


Re: Using GHC API with multiple targets

2023-02-06 Thread Eternal Recursion via ghc-devs
If this is the wrong forum for this question (which as I think about it, I 
suppose it is) then redirection to a more appropriate mailing list or forum (or 
any advice, really) would be appreciated. I just figured this would be the 
forum with the best understanding of how the GHC API works (and has changed 
over time), and my longer term goal is indeed to contribute to it after I get 
past my learning curve.

Sincerely,

Bob

Sent with [Proton Mail](https://proton.me/) secure email.

--- Original Message ---
On Saturday, February 4th, 2023 at 4:04 PM, Eternal Recursion via ghc-devs 
 wrote:

> Hi Everyone!
>
> I'm new here, trying to learn the GHC API. using 944 with cabal 3.8.1.0.
>
> How do I correctly set a GHC Session's DynFlags (and/or other properties) to 
> ensure local libraries imported by the main target are resolved properly at 
> compile time?
>
> What flags need to be set so that GHC is able to load/analyze/compile all 
> relevant Libraries in a package?
>
> This is my current code:
>
> withPath :: FilePath -> IO ()
> withPath target = do
> let targetDir = takeDirectory target
> let targetFile = takeFileName target
> listing <- listDirectory targetDir
> let imports = filter (\f -> takeExtension f == ".hs") listing
> print imports
> let moduleName = mkModuleName targetFile
> g <- defaultErrorHandler defaultFatalMessager defaultFlushOut
> $ runGhc (Just libdir) $ do
> initGhcMonad (Just libdir)
> dynflags <- getSessionDynFlags
> setSessionDynFlags $ dynflags { ghcLink = LinkInMemory
> , ghcMode = CompManager
> , backend = Interpreter
> , mainModuleNameIs = moduleName
> , workingDirectory = Just targetDir
> , importPaths = [targetDir] ++ importPaths dynflags
> }
>
> targets <- mapM (\t -> guessTarget t Nothing Nothing) imports
> setTargets targets
> setContext [ IIDecl $ simpleImportDecl (mkModuleName "Prelude") ]
> load LoadAllTargets
> liftIO . print . ppr =<< getTargets
> getModuleGraph
> putStrLn "Here we go!"
> print $ ppr $ mgModSummaries g putStrLn "☝️ "
>
> However, when I run it (passing to example/app/Main.hs, in which directory 
> are Lib.hs and Lib2.hs, the latter being imported into Main), I get:
>
> $ cabal run cli -- example/app/Main.hs
> Up to date
> ["Main.hs","Lib.hs","Lib2.hs"]
> [main:Main.hs, main:Lib.hs, main:Lib2.hs]
> Here we go!
> [ModSummary {
> ms_hs_hash = 23f9c4415bad851a1e36db9d813f34be
> ms_mod = Lib,
> unit = main
> ms_textual_imps = [(, Prelude)]
> ms_srcimps = []
> },
> ModSummary {
> ms_hs_hash = e1eccc23af49f3498a5a9566e63abefd
> ms_mod = Lib2,
> unit = main
> ms_textual_imps = [(, Prelude)]
> ms_srcimps = []
> },
> ModSummary {
> ms_hs_hash = 5f6751d7f0d5547a1bdf39af84f8c07f
> ms_mod = Main,
> unit = main
> ms_textual_imps = [(, Prelude), (, Lib2)]
> ms_srcimps = []
> }]
> ☝
>
> example/app/Main.hs:4:1: error:
> Could not find module ‘Lib2’
> Use -v (or `:set -v` in ghci) to see a list of the files searched for.
> |
> 4 |import qualified Lib2 as L2
> | ^^^
> cli: example/app/Main.hs:4:1: error:
> Could not find module `Lib2'
> Use -v (or `:set -v` in ghci) to see a list of the files searched for.
>
> ​What do I need to do differently to make this work?
>
> I have a local Cabal file I could use, but to know what I need out of it, I 
> need to understand the minimum required info to get this to work. TIA!
>
> Sincerely,
>
> Bob
>
> Sent with [Proton Mail](https://proton.me/) secure email.___
ghc-devs mailing list
ghc-devs@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs


Re: Registering account in gitlab.haskell.org

2023-02-06 Thread ccycle
Now I can successfully log in. Thank you for approving!
On Feb 6, 2023 19:48 +0900, Bryan Richter , wrote:
> My fault. I chose the wrong "confirmation" option in the admin panel. It is 
> the one that manually confirms your email address.
>
> Now I've also approved your account!
>
> > On Mon, 6 Feb 2023 at 12:40, ccycle  wrote:
> > > Thank you, but now I got same error and cannot log in. Will I able to log 
> > > in after a while?
> > > On Feb 6, 2023 16:42 +0900, Bryan Richter , 
> > > wrote:
> > > > You've been approved! Sorry for the hiccup, there was a spam problem on 
> > > > the server for a while.
> > > >
> > > > > On Mon, 6 Feb 2023 at 08:41, ccycle  wrote:
> > > > > > Hi, I'm new to ghc-devs@haskell.org and would like to report a bug 
> > > > > > in GHC that I have encountered. I tried to log in with an account 
> > > > > > registered in gitlab.haskell.org to create an issue and then I got 
> > > > > > the following error:
> > > > > >
> > > > > > > Your account is pending approval from your GitLab administrator 
> > > > > > > and hence blocked. Please contact your GitLab administrator if 
> > > > > > > you think this is an error.
> > > > > >
> > > > > > Could someone approve my account? My account pending approval is:
> > > > > >
> > > > > > Username: ccycle
> > > > > > Email: ccycle...@gmail.com
> > > > > >
> > > > > >
> > > > > > ___
> > > > > > ghc-devs mailing list
> > > > > > ghc-devs@haskell.org
> > > > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
___
ghc-devs mailing list
ghc-devs@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs


Re: Registering account in gitlab.haskell.org

2023-02-06 Thread Bryan Richter via ghc-devs
My fault. I chose the wrong "confirmation" option in the admin panel. It is
the one that manually confirms your email address.

Now I've also approved your account!

On Mon, 6 Feb 2023 at 12:40, ccycle  wrote:

> Thank you, but now I got same error and cannot log in. Will I able to log
> in after a while?
> On Feb 6, 2023 16:42 +0900, Bryan Richter ,
> wrote:
>
> You've been approved! Sorry for the hiccup, there was a spam problem on
> the server for a while.
>
> On Mon, 6 Feb 2023 at 08:41, ccycle  wrote:
>
>> Hi, I'm new to ghc-devs@haskell.org  and
>> would like to report a bug in GHC that I have encountered. I tried to log
>> in with an account registered in gitlab.haskell.org to create an issue
>> and then I got the following error:
>>
>> > Your account is pending approval from your GitLab administrator and
>> hence blocked. Please contact your GitLab administrator if you think this
>> is an error.
>>
>> Could someone approve my account? My account pending approval is:
>>
>> Username: ccycle
>> Email: ccycle...@gmail.com
>>
>>
>> ___
>> ghc-devs mailing list
>> ghc-devs@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
>>
>
___
ghc-devs mailing list
ghc-devs@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs


Re: Registering account in gitlab.haskell.org

2023-02-06 Thread ccycle
Thank you, but now I got same error and cannot log in. Will I able to log in 
after a while?
On Feb 6, 2023 16:42 +0900, Bryan Richter , wrote:
> You've been approved! Sorry for the hiccup, there was a spam problem on the 
> server for a while.
>
> > On Mon, 6 Feb 2023 at 08:41, ccycle  wrote:
> > > Hi, I'm new to ghc-devs@haskell.org and would like to report a bug in GHC 
> > > that I have encountered. I tried to log in with an account registered in 
> > > gitlab.haskell.org to create an issue and then I got the following error:
> > >
> > > > Your account is pending approval from your GitLab administrator and 
> > > > hence blocked. Please contact your GitLab administrator if you think 
> > > > this is an error.
> > >
> > > Could someone approve my account? My account pending approval is:
> > >
> > > Username: ccycle
> > > Email: ccycle...@gmail.com
> > >
> > >
> > > ___
> > > ghc-devs mailing list
> > > ghc-devs@haskell.org
> > > http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
___
ghc-devs mailing list
ghc-devs@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs