Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cabal compiles code twice

Tags:

haskell

cabal

When I run cabal build, cabal goes through the process of compiling twice. Since compiling takes relatively long time already (~60 seconds), this is starting to impede my workflow.

Here is the ghc options in my cabal file:

GHC-Options: -O3 -rtsopts -funbox-strict-fields -threaded -Wall -feager-blackholing -fllvm -optlo-O3
if flag(Eventlog)
  GHC-Options: -O3 -rtsopts -funbox-strict-fields -threaded -eventlog -Wall
if flag(Profiling)
  ghc-prof-options: -O3 -auto-all
  GHC-Options: -O3 -rtsopts -funbox-strict-fields -threaded -fprof-auto -Wall
if flag(Dump)
  GHC-options: -O3 -funbox-strict-fields -Wall -ddump-simpl -dsuppress-module-prefixes -dsuppress-uniques -ddump-to-file

The output from cabal build looks completely normal except the compilation restarts as soon as the last module finishes compiling the first time.

[ 1 of 13] Compiling HaObj            ( src/HaObj.hs, nothing )
[ 2 of 13] Compiling Surfaces         ( src/Surfaces.hs, nothing )
[ 3 of 13] Compiling Materials        ( src/Materials.hs, nothing )
[ 4 of 13] Compiling Geometry3        ( src/Geometry3.hs, nothing )
[ 5 of 13] Compiling Triangles        ( src/Triangles.hs, nothing )
[ 6 of 13] Compiling BoundingVolumeHierarchy ( src/BoundingVolumeHierarchy.hs, nothing )
[ 7 of 13] Compiling RayTracer        ( src/RayTracer.hs, nothing )
[ 8 of 13] Compiling BenchmarkScene5  ( src/BenchmarkScene5.hs, nothing )
[ 9 of 13] Compiling BenchmarkScene4  ( src/BenchmarkScene4.hs, nothing )
[10 of 13] Compiling BenchmarkScene3  ( src/BenchmarkScene3.hs, nothing )
[11 of 13] Compiling BenchmarkScene2  ( src/BenchmarkScene2.hs, nothing )
[12 of 13] Compiling BenchmarkScene   ( src/BenchmarkScene.hs, nothing )
[13 of 13] Compiling Main             ( src/Main.hs, nothing )
[ 1 of 13] Compiling HaObj            ( src/HaObj.hs, nothing )
[ 2 of 13] Compiling Surfaces         ( src/Surfaces.hs, nothing )
[ 3 of 13] Compiling Materials        ( src/Materials.hs, nothing )
[ 4 of 13] Compiling Geometry3        ( src/Geometry3.hs, nothing )
[ 5 of 13] Compiling Triangles        ( src/Triangles.hs, nothing )
[ 6 of 13] Compiling BoundingVolumeHierarchy ( src/BoundingVolumeHierarchy.hs, nothing )
[ 7 of 13] Compiling RayTracer        ( src/RayTracer.hs, nothing )
[ 8 of 13] Compiling BenchmarkScene5  ( src/BenchmarkScene5.hs, nothing )
[ 9 of 13] Compiling BenchmarkScene4  ( src/BenchmarkScene4.hs, nothing )
[10 of 13] Compiling BenchmarkScene3  ( src/BenchmarkScene3.hs, nothing )
[11 of 13] Compiling BenchmarkScene2  ( src/BenchmarkScene2.hs, nothing )
[12 of 13] Compiling BenchmarkScene   ( src/BenchmarkScene.hs, nothing )
[13 of 13] Compiling Main             ( src/Main.hs, nothing )

I'm using Ubuntu 14.04, GHC 7.10.1, cabal-install 1.22.4, cabal library 1.22.3. Here is a link to the repo if you are interested in trying to reproduce. I would recommend running cabal build --ghc-options="-fno-code" to decrease build time to a couple of seconds.

EDIT: Zeta pointed out that is was because I have both an executable ray-tracer and a benchmark bench in my cabal file. Is there a way to build only one of them? I tried cabal build ray-tracer but this also built both targets. I also tried cabal configure --disable-benchmarks. Is there a way to selectively build only one of the targets without reorganizing the structure of the cabal file?

like image 848
Justin Raymond Avatar asked Nov 09 '22 07:11

Justin Raymond


1 Answers

Posting the answer from comments as community-wiki:

The syntax to build a single component is (for example) cabal build exe:ray-tracer

like image 111
sclv Avatar answered Nov 15 '22 07:11

sclv