New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal libraries does not work if there's no main library #3787

Closed
deyaaeldeen opened this Issue Jan 17, 2018 · 12 comments

Comments

Projects
None yet
6 participants
@deyaaeldeen

deyaaeldeen commented Jan 17, 2018

General summary/comments (optional)

Internal libraries does not work.

Steps to reproduce

$ cat foo.cabal
-- Initial foo.cabal generated by cabal init.  For further documentation,
-- see http://haskell.org/cabal/users-guide/

name:                foo
version:             0.1.0.0
-- synopsis:
-- description:
license:             BSD3
license-file:        LICENSE
author:              Deyaa
maintainer:          diaa6510@gmail.com
-- copyright:
-- category:
build-type:          Simple
extra-source-files:  ChangeLog.md
cabal-version:       >=1.10

library internal-foo
  build-depends:       base >=4.10 && <4.11
  default-language:    Haskell2010

$ cat stack.yaml
flags: {}
packages:
- '.'
extra-deps:
resolver: lts-10.3

Expected

it to build fine.

Actual

$ stack build --verbose
2018-01-17 13:18:07.100419: [debug] Checking for project config at: /Users/dalmahal-admin/Downloads/foo/stack.yaml
@(Stack/Config.hs:842:9)
2018-01-17 13:18:07.101739: [debug] Loading project config file stack.yaml
@(Stack/Config.hs:868:13)
2018-01-17 13:18:07.104077: [debug] Decoding build plan from: /Users/dalmahal-admin/.stack/build-plan/lts-10.3.yaml
@(Stack/Snapshot.hs:150:5)
2018-01-17 13:18:07.104190: [debug] Trying to decode /Users/dalmahal-admin/.stack/build-plan-cache/lts-10.3.cache
@(Data/Store/VersionTagged.hs:66:5)
2018-01-17 13:18:07.110259: [debug] Success decoding /Users/dalmahal-admin/.stack/build-plan-cache/lts-10.3.cache
@(Data/Store/VersionTagged.hs:70:13)
2018-01-17 13:18:07.110931: [debug] Using standard GHC build
@(Stack/Setup.hs:617:9)
2018-01-17 13:18:07.111229: [debug] Getting global package database location
@(Stack/GhcPkg.hs:46:5)
2018-01-17 13:18:07.111444: [debug] Asking GHC for its version
@(Stack/Setup/Installed.hs:98:13)
2018-01-17 13:18:07.111709: [debug] Run process: /Users/dalmahal-admin/.stack/programs/x86_64-osx/ghc-8.2.2/bin/ghc --numeric-version
@(System/Process/Log.hs:37:3)
2018-01-17 13:18:07.113626: [debug] Getting Cabal package version
@(Stack/GhcPkg.hs:185:5)
2018-01-17 13:18:07.113941: [debug] Run process: /Users/dalmahal-admin/.stack/programs/x86_64-osx/ghc-8.2.2/bin/ghc-pkg --no-user-package-db list --global
@(System/Process/Log.hs:37:3)
2018-01-17 13:18:07.114039: [debug] Run process: /Users/dalmahal-admin/.stack/programs/x86_64-osx/ghc-8.2.2/bin/ghc-pkg --no-user-package-db field --simple-output Cabal version
@(System/Process/Log.hs:37:3)
2018-01-17 13:18:07.176911: [debug] Process finished in 62ms: /Users/dalmahal-admin/.stack/programs/x86_64-osx/ghc-8.2.2/bin/ghc-pkg --no-user-package-db list --global
@(System/Process/Log.hs:44:3)
2018-01-17 13:18:07.177389: [debug] Process finished in 57ms: /Users/dalmahal-admin/.stack/programs/x86_64-osx/ghc-8.2.2/bin/ghc-pkg --no-user-package-db field --simple-output Cabal version
@(System/Process/Log.hs:44:3)
2018-01-17 13:18:07.200553: [debug] Process finished in 88ms: /Users/dalmahal-admin/.stack/programs/x86_64-osx/ghc-8.2.2/bin/ghc --numeric-version
@(System/Process/Log.hs:44:3)
2018-01-17 13:18:07.200766: [debug] GHC version is: ghc-8.2.2
@(Stack/Setup/Installed.hs:102:13)
2018-01-17 13:18:07.200895: [debug] Resolving package entries
@(Stack/Setup.hs:250:5)
2018-01-17 13:18:07.201035: [debug] Trying to decode /Users/dalmahal-admin/.stack/loaded-snapshot-cache/x86_64-osx/ghc-8.2.2/lts-10.3.cache
@(Data/Store/VersionTagged.hs:66:5)
2018-01-17 13:18:07.248768: [debug] Success decoding /Users/dalmahal-admin/.stack/loaded-snapshot-cache/x86_64-osx/ghc-8.2.2/lts-10.3.cache
@(Data/Store/VersionTagged.hs:70:13)
2018-01-17 13:18:07.249178: [debug] Starting to execute command inside EnvConfig
@(Stack/Runners.hs:170:18)
2018-01-17 13:18:07.249475: [debug] Parsing the targets
@(Stack/Build/Target.hs:460:3)
2018-01-17 13:18:07.283784: [debug] Exception ignored when attempting to load /Users/dalmahal-admin/Downloads/foo/.stack-work/dist/x86_64-osx/Cabal-2.0.1.0/stack-build-cache: /Users/dalmahal-admin/Downloads/foo/.stack-work/dist/x86_64-osx/Cabal-2.0.1.0/stack-build-cache: openBinaryFile: does not exist (No such file or directory)
@(Data/Store/VersionTagged.hs:84:9)
Package has buildable sublibraries but no buildable libraries, I'm giving up
CallStack (from HasCallStack):
  error, called at src/Stack/Package.hs:281:30 in stack-1.6.3-J1I753MGXoT93WwgNHFXcA:Stack.Package

Stack version

$ stack --version
Version 1.6.3 x86_64 hpack-0.20.0

$ cabal --version
cabal-install version 2.0.0.0
compiled using version 2.0.0.2 of the Cabal library

$ sw_vers                                                                                                                                                                                               
ProductName:    Mac OS X
ProductVersion: 10.12.6
BuildVersion:   16G1114
@mgsloan

This comment has been minimized.

Collaborator

mgsloan commented Jan 18, 2018

I am very surprised that this would be valid. What's the point of a sublibrary if there are no executables or libraries depending on it? Does cabal-install build it?

Perhaps change the title of your issue to "internal libraries don't work if there's no main library"

@deyaaeldeen deyaaeldeen changed the title from Internal libraries does not work to Internal libraries does not work if there's no main library Jan 18, 2018

@deyaaeldeen

This comment has been minimized.

deyaaeldeen commented Jan 18, 2018

@mgsloan If I add the following executable section, I get the same error.

executable foo
  build-depends:       internal-foo
@deyaaeldeen

This comment has been minimized.

deyaaeldeen commented Jan 18, 2018

@mgsloan To answer your other question, cabal build worked fine and tried to build package both with and without the executable section.

@mgsloan

This comment has been minimized.

Collaborator

mgsloan commented Jan 20, 2018

Gotcha. Not sure when I'll have time to fix this. Seems like it should be a matter of finding that error message in the code and making it accept that condition. Might be tricky though, remains to be seen. Want to have a try at fixing it? PRs are appreciated!

@tinco

This comment has been minimized.

tinco commented Feb 3, 2018

Just a message to anyone running into this problem. This happens when you give your library a name. If your package only has one library, you should not give it a name, and it will automatically get the name from the cabal file. Giving it a name apparently makes it 'internal', which is something stack doesn't support yet apparently :)

@mgsloan

This comment has been minimized.

Collaborator

mgsloan commented Feb 10, 2018

Yeah, I think it's just a matter of removing the assumption that you'll have a main library if there are internal libraries. Not sure how to resolve this, it is not a usecase I currently care about.

I'm actually not sure why internal libraries are useful. It's for backpack, right?

@deyaaeldeen

This comment has been minimized.

deyaaeldeen commented Feb 10, 2018

@mgsloan my usecase is as follows: my package is an executable and should not export a library but I need my code to be a hidden library for my tests. I think this should be a common case.

@RyanGlScott I believe internal libraries without a main library worked for you in Stack, right? do you remember which Stack version did you use?

@RyanGlScott

This comment has been minimized.

Contributor

RyanGlScott commented Feb 10, 2018

@RyanGlScott I believe internal libraries without a main library worked for you in Stack, right? do you remember which Stack version did you use?

I only tested with cabal-install-2.0.

@deyaaeldeen

This comment has been minimized.

deyaaeldeen commented Feb 10, 2018

I see, so apparently Stack does not support this scenario yet.

@mgsloan

This comment has been minimized.

Collaborator

mgsloan commented Feb 10, 2018

Currently it doesn't. I encourage you to dig into the code and make it happen, though! I don't think it would be a substantial change.

@EarthCitizen

This comment has been minimized.

EarthCitizen commented May 10, 2018

This is the scenario I need to work as well. I need an internal library to share between the executable and the test-suite, but I don't want to export the internal "guts".

@mihaimaruseac

This comment has been minimized.

Contributor

mihaimaruseac commented Jun 21, 2018

I have a fix for this too, will send a PR in the coming days once I write the integration tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment