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

Allow overriding gcc-location #593

Closed
kgadek opened this issue Jul 15, 2015 · 11 comments
Closed

Allow overriding gcc-location #593

kgadek opened this issue Jul 15, 2015 · 11 comments

Comments

@kgadek
Copy link

@kgadek kgadek commented Jul 15, 2015

I want to override default GCC location, which is required in some FFI use-cases. Originally, the discussion was started on haskell-stack mailing group.

Let's use some basic example: https://github.com/kgadek/ffi-stack-test . I want to compile this FFI code that uses C++. The important part: I'm using OS X 10.9 so /usr/bin/gcc is actually clang; I have GCC 5.0 from homebrew in /usr/local/bin/gcc-5.

First: cabal. Only having the repo, cabal build fails the first time and magically works the second — vide: http://lpaste.net/136600 . After some struggling, I finally made it work by adding this in the ~/.cabal/config:

program-locations
    gcc-location: /usr/local/bin/gcc-5

The obvious wart is that this is a global setting, but I could live with that.

But how to make that work in stack? The output from stack build:

ffi-stack-test-0.1.0.0: configure
Configuring ffi-stack-test-0.1.0.0...
Setup.hs: Missing dependency on a foreign library:
* Missing (or bad) header file: foo.h
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
If the header file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.

--  While building package ffi-stack-test-0.1.0.0 using:
      /Users/konrad/.ghc-current/bin/runhaskell -package=Cabal-1.18.1.5 -clear-package-db -global-package-db -package-db=/Users/konrad/.stack/snapshots/x86_64-osx/lts-2.18/7.8.4/pkgdb/ /var/folders/ht/r6kkmd8s467c4hwqbbpvymxh0000gp/T/stack90764/Setup.hs --builddir=.stack-work/dist/x86_64-osx/Cabal-1.18.1.5/ configure --user --package-db=clear --package-db=global --package-db=/Users/konrad/.stack/snapshots/x86_64-osx/lts-2.18/7.8.4/pkgdb/ --package-db=/Users/konrad/tmp/ffi-stack-test/.stack-work/install/x86_64-osx/lts-2.18/7.8.4/pkgdb/ --constraint=base==4.7.0.2 --libdir=/Users/konrad/tmp/ffi-stack-test/.stack-work/install/x86_64-osx/lts-2.18/7.8.4/lib --bindir=/Users/konrad/tmp/ffi-stack-test/.stack-work/install/x86_64-osx/lts-2.18/7.8.4/bin --datadir=/Users/konrad/tmp/ffi-stack-test/.stack-work/install/x86_64-osx/lts-2.18/7.8.4/share --docdir=/Users/konrad/tmp/ffi-stack-test/.stack-work/install/x86_64-osx/lts-2.18/7.8.4/doc/ffi-stack-test-0.1.0.0 --htmldir=/Users/konrad/tmp/ffi-stack-test/.stack-work/install/x86_64-osx/lts-2.18/7.8.4/doc/ffi-stack-test-0.1.0.0 --haddockdir=/Users/konrad/tmp/ffi-stack-test/.stack-work/install/x86_64-osx/lts-2.18/7.8.4/doc/ffi-stack-test-0.1.0.0
    Process exited with code: ExitFailure 1

This is the error I have seen when trying to fix the project for cabal. Verbose output: http://lpaste.net/136624

Is there any workaround before this feature is implemented, except for symlinking /usr/bin/gcc?

@phadej
Copy link
Collaborator

@phadej phadej commented Jul 15, 2015

For cabal-install you can do cabal configure --with-gcc=/usr/local/bin/gcc-5 (didn't tried though). Don't know about stack :(

@borsboom
Copy link
Contributor

@borsboom borsboom commented Jul 21, 2015

Stack does not currently provide an option to override the GCC location. I'm not sure if you've tried this, but could you adjust the PATH environment variable so the desired gcc is used by default (or make a wrapper script that uses an environment variable to choose)? That way at least it would only be local to your shell session rather than system-wide.

In general, I'm thinking it might be nice for stack to support most of the --with-PROG and --PROG-option that Cabal does. @snoyberg any opinion on that? It should be a fairly easy change, and we would welcome a pull request (basically passing these arguments through to stack's calls to runhaskell Setup.hs configure).

@borsboom borsboom added this to the Later improvements milestone Jul 21, 2015
@snoyberg
Copy link
Contributor

@snoyberg snoyberg commented Jul 21, 2015

👍

@kgadek
Copy link
Author

@kgadek kgadek commented Jul 22, 2015

👍, sounds like a good idea.

@snoyberg
Copy link
Contributor

@snoyberg snoyberg commented Jul 22, 2015

@kgadek Interested in taking a stab at this one then, since you've got a good use case to test it out on?

@kgadek
Copy link
Author

@kgadek kgadek commented Jul 22, 2015

Not this week for sure, but maybe next? I'll try to dive into internals soon, can't give a date though. I'll keep this thread up-to-date when I start working on this one.

TL;DR: if anyone wants this one, go for it. If no one, then I'll try this.

@sjakobi
Copy link
Member

@sjakobi sjakobi commented Nov 17, 2015

In general, I'm thinking it might be nice for stack to support most of the --with-PROG and --PROG-option that Cabal does.

From cabal install --help:

The flags --with-PROG and --PROG-option(s) can be used with the following programs:
  alex ar c2hs cpphs gcc ghc ghc-pkg ghcjs ghcjs-pkg greencard haddock happy
  haskell-suite haskell-suite-pkg hmake hpc hsc2hs hscolour jhc ld lhc lhc-pkg
  pkg-config strip tar uhc

It seems like there wouldn't be much point in accepting a --with-haskell-suite argument?
Can anybody who is more knowledgeable about the Haskell ecosystem make a list of the programs that should be supported?

Also, where do these happen:

stack's calls to runhaskell Setup.hs configure

And finally, which stack commands should accept the new options? init, build?

@mgsloan
Copy link
Contributor

@mgsloan mgsloan commented Nov 17, 2015

The actual call to configure happens here - note that it's computing and passing in --with-ghc / etc options there. However, these options would probably end up going in https://github.com/fpco/stack/blob/fd19fc674948ab07bd795a4b75843f47578e704c/src/Stack/Types/Build.hs#L677

I wouldn't want to see this add a ton of flags to --help, though (see #1333).

How about instead, we just add the ability to specify any cabal configure flags (#846)? The downside of this is that it wouldn't allow overriding the programs used directly by stack.

@borsboom
Copy link
Contributor

@borsboom borsboom commented Nov 27, 2015

Discussion about adding arbitrary cabal configure options: #1438

@thejohnfreeman
Copy link

@thejohnfreeman thejohnfreeman commented Apr 16, 2016

Regardless of what the options end up being, here is a hotfix for users that I was able to narrow down.

hfsevents-0.1.6 could not be built, and the error message led me to this issue. I had Homebrew installed GCC in /usr/local/bin/gcc and apparently hfsevents needs Clang (installed by XCode at /usr/bin/gcc). I could try linking /usr/bin/gcc as /usr/local/bin/gcc, but that would only work because I have sudo access on the machine. In the general case, we need to change the path to GCC that stack uses. Changing the PATH environment variable is not enough; I straight up removed /usr/local/bin/gcc and stack just complained that it didn't exist.

Instead, search for the string /usr/local/bin/gcc in ~/.stack. It should occur in a settings file.

$ ag '/usr/local/bin/gcc' ~/.stack/
~/.stack/programs/x86_64-osx/ghc-7.10.3/lib/ghc-7.10.3/settings
2: ("C compiler command", "/usr/local/bin/gcc"),
5: ("Haskell CPP command","/usr/local/bin/gcc"),
$ sed -i -e 's,/usr/local/bin/gcc,/usr/bin/gcc,' ~/.stack/programs/x86_64-osx/ghc-7.10.3/lib/ghc-7.10.3/settings

The absolute path will change depending on which GHC you've configured stack to use.

@sjakobi
Copy link
Member

@sjakobi sjakobi commented Jul 12, 2016

The --with-gcc option has been added in #2264.

I have opened #2369 to track configuration options for other programs than gcc.

@sjakobi sjakobi closed this Jul 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.