commercialhaskell / stack-ide

Stack-based JSON interface to ide-backend
98 stars 23 forks source link

"Could not resolve file" error when building master. #96

Closed seanparsons closed 8 years ago

seanparsons commented 8 years ago

I get the following error when trying to build the project (note this is a subsequent build):

➜  stack-ide git:(master) stack build --copy-bins                             
ide-backend-server-0.10.0: build
Could not resolve file /home/sean/workspace/stack-ide/ide-backend/ide-backend-server/In file included from Posix.hsc
Globidev commented 8 years ago

:+1: Just tried it, got the same error

rvion commented 8 years ago

did you install with

git clone https://github.com/commercialhaskell/stack-ide.git
cd stack-ide
git submodule update --init --recursive
stack build --copy-bins

?

Globidev commented 8 years ago

yes

rvion commented 8 years ago

@seanparsons @Globidev


It's working for me with stack version 0.1.9.0 , on mac: edit: also working with stack HEAD (Version 0.1.11.0, Git revision 189d677ca6d63012ebe56083c9bee49f635bcc0d x86_64)

➜  stack-ide git:(master) stack --version
Version 0.1.9.0, Git revision 1482c5c52a59c7a6f607570c65be5dc3f0387bcf (dirty) (2663 commits) x86_64
stack-ide git:(master) uname -a
Darwin MacBook-Air-de-Yolo.local 15.0.0 Darwin Kernel Version 15.0.0: Sat Sep 19 15:53:46 PDT 2015; root:xnu-3247.10.11~1/RELEASE_X86_64 x86_64
➜  dev git:(master) ✗ mkdir plop
➜  dev git:(master) ✗ cd plop
➜  plop git:(master) ✗ git clone https://github.com/commercialhaskell/stack-ide.git
Cloning into 'stack-ide'...
remote: Counting objects: 1044, done.
remote: Total 1044 (delta 0), reused 0 (delta 0), pack-reused 1044
Receiving objects: 100% (1044/1044), 212.70 KiB | 0 bytes/s, done.
Resolving deltas: 100% (519/519), done.
Checking connectivity... done.
➜  plop git:(master) ✗ cd stack-ide
➜  stack-ide git:(master) git submodule update --init --recursive
Submodule 'ide-backend' (git://github.com/fpco/ide-backend.git) registered for path 'ide-backend'
Cloning into 'ide-backend'...
remote: Counting objects: 9824, done.
remote: Total 9824 (delta 0), reused 0 (delta 0), pack-reused 9824
Receiving objects: 100% (9824/9824), 2.91 MiB | 1.09 MiB/s, done.
Resolving deltas: 100% (7069/7069), done.
[...]
stack-ide-0.1.0.0: configure
stack-ide-0.1.0.0: build
Warning: module not listed in stack-ide.cabal for 'stack-ide' component (add to other-modules): Paths_stack_ide
stack-ide-0.1.0.0: copy/register
Completed all 71 actions.
Copying from /Users/yolo/dev/plop/stack-ide/.stack-work/install/x86_64-osx/lts-3.13/7.10.2/bin/ide-backend-exe-cabal to /Users/yolo/.local/bin/ide-backend-exe-cabal
Copying from /Users/yolo/dev/plop/stack-ide/.stack-work/install/x86_64-osx/lts-3.13/7.10.2/bin/ide-backend-server to /Users/yolo/.local/bin/ide-backend-server
Copying from /Users/yolo/dev/plop/stack-ide/.stack-work/install/x86_64-osx/lts-3.13/7.10.2/bin/stack-ide to /Users/yolo/.local/bin/stack-ide

Copied executables to /Users/yolo/.local/bin:
- stack-ide
- ide-backend-server
- ide-backend-exe-cabal
➜  stack-ide git:(master)
stack-ide --version
Version 0.1.0.0, Git revision c1e8416b2beb86c7f50109255d28379ca0b17735 (177 commits) X86_64
Globidev commented 8 years ago

It's working for me with stack version 0.1.9.0 , on mac

Haha :wink:

Well, here is a minimalist, easy to recreate, linux environment where we observe the error reported by the OP:

FROM debian

# Install curl, git and stack/stack-ide dependencies
# I just guessed the dependencies from the error messages of my `stack build`
# I don't know if those are documented anywhere?
RUN apt-get update && apt-get install -y \
    curl \
    git \
    build-essential \
    libgmp-dev \
    xz-utils \
    zlib1g-dev

# Install stack
RUN curl -L https://www.stackage.org/stack/linux-x86_64 > /tmp/stack.tar.gz
RUN tar xf /tmp/stack.tar.gz -C /tmp/ --strip-component 1
RUN chmod +x /tmp/stack
RUN mv /tmp/stack /usr/local/bin/stack

# Should be the latest release I guess ?
RUN stack --version
# Should be a x86_64 Linux
RUN uname -a

# Install stack ide
RUN git clone https://github.com/commercialhaskell/stack-ide.git
WORKDIR /stack-ide
RUN git submodule update --init --recursive
# It's apparently necessary to `stack setup` beforehand
# (not documented but I guess it's stack related knowledge)
RUN stack setup
RUN stack build --copy-bins

Just tried building it and got:

Step 7 : RUN stack --version
 ---> Running in 89253e44161a
Version 0.1.10.1, Git revision 83ec40fc5fd6d300c73d23deb1f41d30168fc236 (2783 commits) x86_64

and, not surprisingly:

Step 8 : RUN uname -a
 ---> Running in 97c1589ccaaf
Linux 609b1a101af3 3.19.0-41-generic #46~14.04.2-Ubuntu SMP Tue Dec 8 17:46:10 UTC 2015 x86_64 GNU/Linux

Build ends with a failure on the last step (output truncated):

Step 13 : RUN stack build --copy-bins
 ---> Running in 04a8a9958a73
[1 of 1] Compiling Main             ( /tmp/stack5/Setup.hs, /tmp/stack5/Setup.o )
Linking /root/.stack/setup-exe-cache/x86_64-linux/tmp-setup-Simple-Cabal-1.22.4.0-ghc-7.10.2 ...
...
...
Lots of packages being dowloaded configured and built...
...
...
Warning: modules not listed in ide-backend.cabal for 'ide-backend-exe-cabal' component (add to other-modules):
    IdeSession.Cabal
    IdeSession.Config
    IdeSession.Licenses
    IdeSession.RPC.Client
    IdeSession.State
ide-backend-0.10.0: copy/register
haskell-src-exts-1.16.0.1: copy/register
Could not resolve file /stack-ide/ide-backend/ide-backend-server/In file included from Posix.hsc
The command '/bin/sh -c stack build --copy-bins' returned a non-zero code: 1

Note: I think a Dockerfile like this could be used for CI

seanparsons commented 8 years ago

I can't really upgrade my stack with the git upgrade option as I'm using an apt installed version, so that's entirely likely to screw everything up.

I've done this on an effectively clean built Ubuntu 15.10 setup as well, so there's not much scope for environmental shenanigans.

Globidev commented 8 years ago

Added

RUN stack upgrade --git
RUN mv /root/.local/bin/stack /usr/local/bin/stack

got version:

Step 9 : RUN stack --version
 ---> Running in 5c13b15ad0b4
Version 0.1.11.0, Git revision 189d677ca6d63012ebe56083c9bee49f635bcc0d x86_64

But still fails with the same error

rvion commented 8 years ago

I moved the dockerfile here: https://github.com/rvion/stack-ide-issue-96/blob/master/Dockerfile I also splitted the last command to non-failing and failing parts, so image is cached until just before the actual failure.

[...]
RUN stack build --dependencies-only
CMD stack build -v --copy-bins

image is available on docker hub as rvion/stack-ide-issue-96

rvion commented 8 years ago

for info, Posix.hsc file is here: https://github.com/fpco/ide-backend/blob/3419618c714d0775d1eb17334d1277e166c5a78a/ide-backend-server/Posix.hsc

rvion commented 8 years ago

@Globidev @seanparsons

I found the bug.

hsc2hs is a tool that automates C->haskell ffi bindings .hsc is the extension of files processed by hsc2hs, that contains a mix of c and haskell. In Posix.hsc, line 60, there is a c import directive

#include "HsUnix.h"

but "HsUnix.h" is not found.

It is strange , because it should have been installed via the unix package, which is one of transitive dependencies.

Here is the explanation of why "HsUnix.h" is not found:

According to the thread HsUnix.h on Ubuntu Linux

you are on a Linux which does separate runtime and dev packages even for Haskell packages which are arguably dev only

the "brute" solution proposed is to bring HsUnix.h in non-dev "scope":

[...], and you need to install something like libghc-unix-dev

indeed, installing libghc-unix-dev (apt-get install libghc-unix-dev) make stack aware of HsUnix.h, and the compilation succeed :)

Before closing this issue

one should:

Globidev commented 8 years ago

Nice find :+1:

seanparsons commented 8 years ago

I'm guessing libghc-unix-dev relates tightly to the version of GHC used though right? In my case I'm letting Stack handle the GHC versions which would imply this is potentially a Stack problem then right?

rvion commented 8 years ago

@seanparsons Yes, the problem is probably on the stack side. to be clear, the "fix" above seems quite sloppy : in the docker debian above, apt-get install libghc-unix-dev install ghc 7.6, but stack-ide use 7.10 hopefully stack check if local ghc match version number before using it, and use its own ghc setup otherwise.

:memo: in stack's stack.yaml config file, there is a few options one can read about:

@Globidev instead of rolling your own docker image, you can take a look at that:

edit:

borsboom commented 8 years ago

You need Ubuntu package libbsd-devinstalled. It contains bsd/libutil.h, which HsUnix.h #includes. More details in https://github.com/commercialhaskell/stack/issues/1576.

rvion commented 8 years ago

Thanks @borsboom ! :)