1

I'm trying to get emacs haskell-mode working with a cabal project. Whenever I try to compile or load a file interactively I get the following output in the haskell-process-log

compiling (via (C-c C-c)):

cabal.exe: No targets given and there is no package in the current directory.

and when loading (via (C-c C-l)):

cabal.exe: Unrecognised target syntax for ' --ghc-option=-ferror-spans'


Set up: Windows 10, GHC 8.10.2, Cabal 3.2.0.0, emacs 27.1, haskell-mode 20201120.755

My emacs init file has the following:

(require 'haskell-interactive-mode)
(require 'haskell-process)
(add-hook 'haskell-mode-hook 'interactive-haskell-mode)

(eval-after-load "haskell-mode"
    '(define-key haskell-mode-map (kbd "C-c C-c") 'haskell-compile))

(eval-after-load "haskell-cabal"
    '(define-key haskell-cabal-mode-map (kbd "C-c C-c") 'haskell-compile))

With a simple Haskell project, created by running cabal init

i.e. with a Main.hs:

module Main where

main :: IO ()
main = putStrLn "Hello, Haskell!"

and my-project.cabal :

cabal-version:       >=1.10
-- Initial package description 'my-project.cabal' generated by
--  'cabal init'.  For further documentation, see
-- http://haskell.org/cabal/users-guide/

name:                my-project
version:             0.1.0.0
-- synopsis:
-- description:
-- bug-reports:
-- license:
license-file:        LICENSE
author:              ################
maintainer:          ##################
-- copyright:
-- category:
build-type:          Simple
extra-source-files:  CHANGELOG.md, README.md

executable my-project
  main-is:             Main.hs
  -- other-modules:
  -- other-extensions:
  build-depends:       base >=4.14 && <4.15
  hs-source-dirs:      
  default-language:    Haskell2010

If I try to compile via C-c C-c I get the following in the haskell-process-log buffer:

cabal.exe: No targets given and there is no package in the current directory.
Use the target 'all' for all packages in the project or specify packages or
components by name or location. See 'cabal build --help' for more details on
target options.

If I try to load via C-c C-l the haskell process immediately dies prompting me to restart and the haskell-process-log displays:

cabal.exe: Unrecognised target syntax for ' --ghc-option=-ferror-spans'.

with '(haskell-process-log t) and '(haskell-process-show-debug-tips t) set within my init file custom vars this changes to:

("Starting inferior `cabal repl' process using cabal ..." "my-project" nil "cabal" "repl" " --ghc-option=-ferror-spans")
-> Prelude.putStrLn ""
   :set -v1
   :set +c
-> :set prompt "\4"
-> :set prompt-cont "λ| "
<- cabal.exe: Unrecognised target syntax for ' --ghc-option=-ferror-spans'.
Event: "exited abnormally with code 1 "
Process reset.

Everything works fine in emacs when working on a lone haskell file, i.e. not inside a cabal project.

Compilation and cabal repl within the cabal project via command line also works fine.

I've been searching through the docs and googling for a solid day and a half now. Any help would be appreciated.

frabrooks
  • 155
  • 8
  • Update: It seems to be something to do with call-process in the emacs source. cabal reports as if it's in the wrong directory even though it isn't. Bizarrely changing the command manually to `cd . ; cabal build` fixes the issue and cabal builds happily. See here: https://emacs.stackexchange.com/questions/63078/bizarre-behaviour-using-call-process-cabal-fails-as-if-it-is-in-wrong-directo – frabrooks Jan 30 '21 at 20:04
  • Update: I tried a fresh install on Ubuntu 20.04 and could not replicate the issue. Meanwhile on Windows 10 the problem persists no matter what shell I set as the default shell in emacs (git bash, cygwin, cmd etc.) – frabrooks Jan 30 '21 at 20:08
  • Update: Downgrading to cabal 2.4 fixes the issue and moving back up to 3.2 restores the problem immediately – frabrooks Jan 30 '21 at 20:11
  • I use Spacemacs. And this is about invoking `cabal run` within emacs right ? – Mohan Radhakrishnan Aug 08 '22 at 14:46
  • iirc it was when invoking `cabal run` or `cabal build` among possibly others – frabrooks Aug 27 '22 at 22:14

1 Answers1

5

This turned out to be a bug in Cabal. Specifically in the cabal-install command-line tool that prevented the automatic detection of the primary package on Windows due to Windows denoting drive letters with a capital letter.

I've submitted a pull request:

https://github.com/haskell/cabal/pull/7310

frabrooks
  • 155
  • 8