Skip to content
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

Support cabal repl? #231

Closed
spl opened this issue Dec 30, 2016 · 4 comments
Closed

Support cabal repl? #231

spl opened this issue Dec 30, 2016 · 4 comments

Comments

@spl
Copy link
Contributor

spl commented Dec 30, 2016

I cloned the network repository to try something simple in GHCi. These are the steps I took:

$ git clone https://github.com/haskell/network.git
$ cd network
$ autoreconf
$ cabal sandbox init
$ cabal install --only-dependencies -j
$ cabal repl
Package has never been configured. Configuring with default flags. If this
fails, please run configure manually.
Resolving dependencies...
Configuring network-2.6.3.1...
...
configure: creating ./config.status
config.status: creating network.buildinfo
config.status: creating include/HsNetworkConfig.h
configure: WARNING: unrecognized options: --with-compiler
Preprocessing library network-2.6.3.1...
In file included from dist/build/Network/Socket_hsc_make.c:1:0:
Socket.hsc: In function ‘main’:
Socket.hsc:971:23: error: invalid application of ‘sizeof’ to incomplete type ‘struct ucred’
/opt/ghc/7.10.3/lib/ghc-7.10.3/template-hsc.h:35:10: note: in definition of macro ‘hsc_const’
     if ((x) < 0)                                      \
          ^
Socket.hsc:971:23: error: invalid application of ‘sizeof’ to incomplete type ‘struct ucred’
/opt/ghc/7.10.3/lib/ghc-7.10.3/template-hsc.h:36:41: note: in definition of macro ‘hsc_const’
         hsc_printf ("%lld", (long long)(x));          \
                                         ^
Socket.hsc:971:23: error: invalid application of ‘sizeof’ to incomplete type ‘struct ucred’
/opt/ghc/7.10.3/lib/ghc-7.10.3/template-hsc.h:38:50: note: in definition of macro ‘hsc_const’
         hsc_printf ("%llu", (unsigned long long)(x));
                                                  ^
In file included from /usr/include/rpc/netdb.h:42:0,
                 from /usr/include/netdb.h:32,
                 from include/HsNet.h:93,
                 from Socket.hsc:23:
Socket.hsc:976:22: error: invalid use of undefined type ‘struct ucred’
Socket.hsc:976:5: note: in expansion of macro ‘hsc_peek’
Socket.hsc:977:22: error: invalid use of undefined type ‘struct ucred’
Socket.hsc:977:5: note: in expansion of macro ‘hsc_peek’
Socket.hsc:978:22: error: invalid use of undefined type ‘struct ucred’
Socket.hsc:978:5: note: in expansion of macro ‘hsc_peek’
compiling dist/build/Network/Socket_hsc_make.c failed (exit code 1)
command was: /usr/bin/gcc -c dist/build/Network/Socket_hsc_make.c -o dist/build/Network/Socket_hsc_make.o -fno-stack-protector -fno-stack-protector -D__GLASGOW_HASKELL__=710 -Dlinux_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Dlinux_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -Iinclude -Idist/build/autogen -include dist/build/autogen/cabal_macros.h -I/opt/ghc/7.10.3/lib/ghc-7.10.3/unix_KZL8h98IqDM57kQSPo1mKx/include -I/opt/ghc/7.10.3/lib/ghc-7.10.3/time_FTheb6LSxyX1UABIbBXRfn/include -I/opt/ghc/7.10.3/lib/ghc-7.10.3/bytes_6VWy06pWzJq9evDvK2d4w6/include -I/opt/ghc/7.10.3/lib/ghc-7.10.3/base_HQfYBxpPvuw8OunzQu6JGM/include -I/opt/ghc/7.10.3/lib/ghc-7.10.3/integ_2aU3IZNMF9a7mQ0OzsZ0dS/include -I/opt/ghc/7.10.3/lib/ghc-7.10.3/include -I/opt/ghc/7.10.3/lib/ghc-7.10.3/include/

Hmm. Perhaps something is not being built.

$ cabal build

Okay, that was successful. Let's try GHCi again.

$ cabal repl
Preprocessing library network-2.6.3.1...
GHCi, version 7.10.3: http://www.haskell.org/ghc/  :? for help
[ 1 of 11] Compiling Network.Socket.ByteString.IOVec ( dist/build/Network/Socket/ByteString/IOVec.hs, interpreted )
[ 2 of 11] Compiling Network.Socket.Types ( dist/build/Network/Socket/Types.hs, interpreted )

Network/Socket/Types.hsc:761:16: parse error on input ‘CALLCONV’
Failed, modules loaded: Network.Socket.ByteString.IOVec.
*Network.Socket.ByteString.IOVec>

Progress!

Looking into CALLCONV... I'm not sure why it's not defined in dist/build/Network/Socket/Types.hs. But I can define it myself.

$ cabal repl --ghc-options="-DCALLCONV=ccall"
Preprocessing library network-2.6.3.1...
GHCi, version 7.10.3: http://www.haskell.org/ghc/  :? for help
[ 1 of 11] Compiling Network.Socket.ByteString.IOVec ( dist/build/Network/Socket/ByteString/IOVec.hs, interpreted )
[ 2 of 11] Compiling Network.Socket.Types ( dist/build/Network/Socket/Types.hs, interpreted )
[ 3 of 11] Compiling Network.Socket.Internal ( dist/build/Network/Socket/Internal.hs, interpreted )
[ 4 of 11] Compiling Network.Socket   ( dist/build/Network/Socket.hs, interpreted )

ByteCodeLink: can't find label
During interactive linking, GHCi couldn't find the following symbol:
  sendFd
This may be due to you not asking GHCi to load extra object files,
archives or DLLs needed by your current session.  Restart GHCi, specifying
the missing library using the -L/path/to/object/dir and -lmissinglibname
flags, or simply by naming the relevant files on the GHCi command line.
Alternatively, this link failure might indicate a bug in GHCi.
If you suspect the latter, please send a bug report to:
  glasgow-haskell-bugs@haskell.org

Hmm. Seems like ancilData.o is not being linked in. Oh, let's try using the object code.

$ cabal repl --ghc-options="-DCALLCONV=ccall -fobject-code"
Preprocessing library network-2.6.3.1...
GHCi, version 7.10.3: http://www.haskell.org/ghc/  :? for help
[ 1 of 11] Compiling Network.Socket.ByteString.IOVec ( dist/build/Network/Socket/ByteString/IOVec.hs, dist/build/Network/Socket/ByteString/IOVec.o )
[ 2 of 11] Compiling Network.Socket.Types ( dist/build/Network/Socket/Types.hs, dist/build/Network/Socket/Types.o )
[ 3 of 11] Compiling Network.Socket.Internal ( dist/build/Network/Socket/Internal.hs, dist/build/Network/Socket/Internal.o )
[ 4 of 11] Compiling Network.Socket   ( dist/build/Network/Socket.hs, dist/build/Network/Socket.o )
[ 5 of 11] Compiling Network.Socket.ByteString.MsgHdr ( dist/build/Network/Socket/ByteString/MsgHdr.hs, dist/build/Network/Socket/ByteString/MsgHdr.o )
[ 6 of 11] Compiling Network.Socket.ByteString.Internal ( Network/Socket/ByteString/Internal.hs, dist/build/Network/Socket/ByteString/Internal.o )
[ 7 of 11] Compiling Network.Socket.ByteString ( dist/build/Network/Socket/ByteString.hs, dist/build/Network/Socket/ByteString.o )
[ 8 of 11] Compiling Network.Socket.ByteString.Lazy.Posix ( Network/Socket/ByteString/Lazy/Posix.hs, dist/build/Network/Socket/ByteString/Lazy/Posix.o )
[ 9 of 11] Compiling Network.Socket.ByteString.Lazy ( Network/Socket/ByteString/Lazy.hs, dist/build/Network/Socket/ByteString/Lazy.o )
[10 of 11] Compiling Network.BSD      ( dist/build/Network/BSD.hs, dist/build/Network/BSD.o )
[11 of 11] Compiling Network          ( Network.hs, dist/build/Network.o )
Ok, modules loaded: Network, Network.BSD, Network.Socket, Network.Socket.Internal, Network.Socket.Types, Network.Socket.ByteString, Network.Socket.ByteString.Internal, Network.Socket.ByteString.IOVec, Network.Socket.ByteString.MsgHdr, Network.Socket.ByteString.Lazy, Network.Socket.ByteString.Lazy.Posix.
Prelude Network>

Success?

Prelude Network> h <- connectTo "localhost" (PortNumber 23)
ghc: panic! (the 'impossible' happened)
  (GHC version 7.10.3 for x86_64-unknown-linux):
	Loading temp shared object failed: /tmp/ghc3717_0/libghc_51.so: undefined symbol: sendFd

No!

After researching some more, I found a trick suggested at commercialhaskell/stack#1239 (comment) to specify the object file explicitly.

$ cabal repl --ghc-options="-DCALLCONV=ccall dist/build/cbits/ancilData.o"
...
Prelude Network> h <- connectTo "localhost" (PortNumber 23)
*** Exception: connect: does not exist (Connection refused)

Success!

After researching some more, I realize that the generated network.buildinfo file includes all of the host-specific configuration that extends the network.cabal.

So my question is: What can be done to improve support for cabal repl? This brought to mind a few questions:

  • Can some of the host-specific configuration be moved into network.cabal?
  • Should cabal repl respect the generated network.buildinfo file?
  • Should there be a script or documentation for running cabal repl for network?
@Mistuke
Copy link
Collaborator

Mistuke commented Jul 19, 2018

this should no longer be an issue starting with network 2.7 If I remember correctly, but certainly not with 3.0. Could you try master?

@spl
Copy link
Contributor Author

spl commented Jul 19, 2018

That's good news. Please feel free to close the issue if it works for you. I don't have the time to look into it right now.

@RyanGlScott
Copy link
Member

I do not experience this issue with network-3.0.0.0 (commit 16fce86), but I do experience it with network-2.8.0.0.

@eborden
Copy link
Collaborator

eborden commented Jan 19, 2019

Closing this issue since it is resolved for 3.0.0.0.

@eborden eborden closed this as completed Jan 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants