How to build the dune-based project from inside the Emacs

Hi all,

I moved my project into dunes and now I have a probably very stupid question:
Let’s say, I’m in Emacs editing my dune or .ml file. How can I start building my entire project from inside Emacs and get the list of all errors in all files? I did try С-с С-с with “dune build @install” and “make -f /path/to/my/project/Makefile”. Doesn’t work.

Thanks a lot in advance :slight_smile:

cd to your project root before running dune may help
dune build @check builds the minimum to get the list of errors

Gaëtan Gilbert

Wow! Thanks :slight_smile:

cd really helped which is a little bit confusing as from the command line I can run dune from every subdirectory of the project and everything works as expected.

I use this snippet so pressing M-c will @check everything, IMHO it works well:

(defun eg-compile ()
  (let* ((default-directory
           (or (locate-dominating-file buffer-file-name "Makefile") default-directory))
         (compile-command (concat "(cd " default-directory " && dune build @check)"))
          (or (locate-dominating-file buffer-file-name "Makefile") nil)))

(eval-after-load 'tuareg
     (require 'merlin-xref)
     (add-hook 'xref-backend-functions #'merlin-xref-backend)
     (define-key tuareg-mode-map "\M-c" 'eg-compile)
     (define-key tuareg-mode-map "\M-p" 'merlin-error-prev)
     (define-key tuareg-mode-map "\M-n" 'merlin-error-next)))

Thanks a lot, works for me too :slight_smile: