Andreas Voellmy | 25 Mar 14:46 2013
Picon

cabal executable using local hsc modules

Hi, 

I have a library that has some modules written as .hsc files and I want to include some executables that use those modules. Cabal doesn't seem to find the modules when it is building the executable. It complains that the module used by the executable is in a hidden package (of the same name as the package being built). Adding the package as a dependency in the executable section doesn't work since it references a library defined in the same package.  Is this a bug?   I've attached three files illustrating the problem. A.hsc is a tiny module in the library, B.hs is the executable that uses A, foo.cabal defines both the library and the executable. I am using 

$ cabal --version
cabal-install version 1.16.0.2
using version 1.16.0.3 of the Cabal library 

and when I run "cabal install -v" I get

$ cabal install --disable-library-profiling 
Resolving dependencies...
Configuring foo-1.0...
Building foo-1.0...
Preprocessing library foo-1.0...
[1 of 1] Compiling A                ( dist/build/A.hs, dist/build/A.o )
In-place registering foo-1.0...
Preprocessing executable 'B' for foo-1.0...

B.hs:3:8:
    Could not find module `A'
    It is a member of the hidden package `foo-1.0'.
    Perhaps you need to add `foo' to the build-depends in your .cabal file.
    Use -v to see a list of the files searched for.
Failed to install foo-1.0
cabal: Error: some packages failed to install:
foo-1.0 failed during the building phase. The exception was:
ExitFailure 1
Attachment (foo.cabal): application/octet-stream, 263 bytes
Attachment (B.hs): application/octet-stream, 76 bytes
Attachment (A.hsc): application/octet-stream, 44 bytes
_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Henning Thielemann | 25 Mar 15:05 2013
Picon

Re: cabal executable using local hsc modules


On Mon, 25 Mar 2013, Andreas Voellmy wrote:

> Hi, 
> I have a library that has some modules written as .hsc files and I want to include some executables that use
> those modules. Cabal doesn't seem to find the modules when it is building the executable. It complains that
> the module used by the executable is in a hidden package (of the same name as the package being built).
> Adding the package as a dependency in the executable section doesn't work since it references a library
> defined in the same package.

This should work since Cabal-1.14. Can you show, how exactly you added the 
dependency to the executable?

If it does not work, you may add Hs-Source-Dirs of the library to the 
executable. However this means that GHC will recompile the library 
modules, yielding more compile time and more disk space consumption.
_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Andreas Voellmy | 25 Mar 17:38 2013
Picon

Re: cabal executable using local hsc modules




On Mon, Mar 25, 2013 at 10:05 AM, Henning Thielemann <lemming <at> henning-thielemann.de> wrote:

On Mon, 25 Mar 2013, Andreas Voellmy wrote:

Hi, 
I have a library that has some modules written as .hsc files and I want to include some executables that use
those modules. Cabal doesn't seem to find the modules when it is building the executable. It complains that
the module used by the executable is in a hidden package (of the same name as the package being built).
Adding the package as a dependency in the executable section doesn't work since it references a library
defined in the same package.

This should work since Cabal-1.14. Can you show, how exactly you added the dependency to the executable?

I included the two source files, A.hsc and B.hs, and the cabal file in my last email. That shows how I add the dependency in the executable section. I have those three files in a single directory.
_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Henning Thielemann | 25 Mar 18:01 2013
Picon

Re: cabal executable using local hsc modules


On Mon, 25 Mar 2013, Andreas Voellmy wrote:

> > This should work since Cabal-1.14. Can you show, how exactly you added 
> > the dependency to the executable?
> 
> I included the two source files, A.hsc and B.hs, and the cabal file in my last email. That shows how I add
> the dependency in the executable section. I have those three files in a single directory.

Your Cabal file does not contain a dependency in the library for the 
executable. It would look like this:

executable B
  main-is: B.hs
  build-depends: foo
Andreas Voellmy | 25 Mar 18:11 2013
Picon

Re: cabal executable using local hsc modules

Sure, I can do that, but then I get:

$ cabal install --disable-library-profiling 
Resolving dependencies...
Configuring foo-1.0...
cabal: The field 'build-depends: foo' refers to a library which is defined
within the same package. To use this feature the package must specify at least
'cabal-version: >= 1.8'.
Failed to install foo-1.0
cabal: Error: some packages failed to install:
foo-1.0 failed during the configure step. The exception was:
ExitFailure 1

Maybe I could try with cabal-version >= 1.8, but this doesn't seem like it should be necessary. I wouldn't need this build-depends: foo if A were just A.hs, right? So it seems odd (from a user's standpoint) that I need it when it is A.hsc.


On Mon, Mar 25, 2013 at 1:01 PM, Henning Thielemann <lemming <at> henning-thielemann.de> wrote:

On Mon, 25 Mar 2013, Andreas Voellmy wrote:

> This should work since Cabal-1.14. Can you show, how exactly you added > the dependency to the executable?

I included the two source files, A.hsc and B.hs, and the cabal file in my last email. That shows how I add
the dependency in the executable section. I have those three files in a single directory.

Your Cabal file does not contain a dependency in the library for the executable. It would look like this:


executable B
 main-is: B.hs
 build-depends: foo


_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Henning Thielemann | 25 Mar 18:14 2013
Picon

Re: cabal executable using local hsc modules


On Mon, 25 Mar 2013, Andreas Voellmy wrote:

> Sure, I can do that, but then I get:
> $ cabal install --disable-library-profiling 
> Resolving dependencies...
> Configuring foo-1.0...
> cabal: The field 'build-depends: foo' refers to a library which is defined
> within the same package. To use this feature the package must specify at least
> 'cabal-version: >= 1.8'.
> Failed to install foo-1.0
> cabal: Error: some packages failed to install:
> foo-1.0 failed during the configure step. The exception was:
> ExitFailure 1
> 
> Maybe I could try with cabal-version >= 1.8, but this doesn't seem like it should be necessary. I wouldn't
> need this build-depends: foo if A were just A.hs, right? So it seems odd (from a user's standpoint) that I
> need it when it is A.hsc.

I don't think that this depends on the HSC preprocessing. With A.hs it 
would be the same problem. Have you tried it?
_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Andreas Voellmy | 25 Mar 18:17 2013
Picon

Re: cabal executable using local hsc modules

Yes, If I rename A.hsc to A.hs, it works fine (without the "build-depends: foo" in the cabal file).


On Mon, Mar 25, 2013 at 1:14 PM, Henning Thielemann <lemming <at> henning-thielemann.de> wrote:

On Mon, 25 Mar 2013, Andreas Voellmy wrote:

Sure, I can do that, but then I get:
$ cabal install --disable-library-profiling 
Resolving dependencies...
Configuring foo-1.0...
cabal: The field 'build-depends: foo' refers to a library which is defined
within the same package. To use this feature the package must specify at least
'cabal-version: >= 1.8'.
Failed to install foo-1.0
cabal: Error: some packages failed to install:
foo-1.0 failed during the configure step. The exception was:
ExitFailure 1

Maybe I could try with cabal-version >= 1.8, but this doesn't seem like it should be necessary. I wouldn't
need this build-depends: foo if A were just A.hs, right? So it seems odd (from a user's standpoint) that I
need it when it is A.hsc.


I don't think that this depends on the HSC preprocessing. With A.hs it would be the same problem. Have you tried it?

_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Henning Thielemann | 25 Mar 18:22 2013
Picon

Re: cabal executable using local hsc modules


On Mon, 25 Mar 2013, Andreas Voellmy wrote:

> Yes, If I rename A.hsc to A.hs, it works fine (without the "build-depends: foo" in the cabal file).

Then it may work by accident, since GHC finds the module A in the same 
directory as B. Am I right that GHC recompiles A when it compiles B? This 
should not happen, since GHC should only use the modules the are 
explicitly listed in a section (library or executable). However Cabal 
calls 'ghc --make' and this fetches modules automatically even if Cabal 
does not tell it to do so.

If library and executable would use different directories 
(Hs-source-dirs), it might not work, as expected.
Andreas Voellmy | 25 Mar 18:46 2013
Picon

Re: cabal executable using local hsc modules

OK, I just realized that the correct way of handling this is to use the "other-modules" field of the executable section. In this instance, just adding "other-modules: A" in the executable section allows the .hsc file to be found and compiled properly. 

Henning: thanks very much for your replies!


On Mon, Mar 25, 2013 at 1:22 PM, Henning Thielemann <lemming <at> henning-thielemann.de> wrote:

On Mon, 25 Mar 2013, Andreas Voellmy wrote:

Yes, If I rename A.hsc to A.hs, it works fine (without the "build-depends: foo" in the cabal file).

Then it may work by accident, since GHC finds the module A in the same directory as B. Am I right that GHC recompiles A when it compiles B? This should not happen, since GHC should only use the modules the are explicitly listed in a section (library or executable). However Cabal calls 'ghc --make' and this fetches modules automatically even if Cabal does not tell it to do so.

If library and executable would use different directories (Hs-source-dirs), it might not work, as expected.

_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Henning Thielemann | 25 Mar 18:54 2013
Picon

Re: cabal executable using local hsc modules


On Mon, 25 Mar 2013, Andreas Voellmy wrote:

> OK, I just realized that the correct way of handling this is to use the "other-modules" field of the
> executable section. In this instance, just adding "other-modules: A" in the executable section allows the
> .hsc file to be found and compiled properly. 

As I said, this can be done and up to Cabal-1.14 this was the only 
possible way. Since Cabal-1.10 importing the library to the executable 
worked somehow, but Haddock failed. Today the proper way is to import the 
library by Build-Depends which saves disk space and compilation time, but 
requires the field Cabal-Version >= 1.8.
_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Andreas Voellmy | 25 Mar 19:00 2013
Picon

Re: cabal executable using local hsc modules

OK, I will use build-depends. It works well. Thanks!


On Mon, Mar 25, 2013 at 1:54 PM, Henning Thielemann <lemming <at> henning-thielemann.de> wrote:

On Mon, 25 Mar 2013, Andreas Voellmy wrote:

OK, I just realized that the correct way of handling this is to use the "other-modules" field of the
executable section. In this instance, just adding "other-modules: A" in the executable section allows the
.hsc file to be found and compiled properly. 

As I said, this can be done and up to Cabal-1.14 this was the only possible way. Since Cabal-1.10 importing the library to the executable worked somehow, but Haddock failed. Today the proper way is to import the library by Build-Depends which saves disk space and compilation time, but requires the field Cabal-Version >= 1.8.

_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries

Gmane