8

If I run stack clean && stack build --profile, I get an executable that is slower than if I had run stack clean && stack build, this is normal and fine.

If I run stack clean && stack build --profile && stack build then I get an executable that is just as slow, and this persists until I run stack clean && stack build

I have set the option rebuild-ghc-options: true in stack.yaml, but I'm either not understanding the proper use of stack or I'm misusing it somehow, because I don't have a clear mental model of what state is affected when I run stack build. It is clearly affecting future builds until I run stack clean, is it also affecting dependencies? How do I make sure that when I build with default settings that I get the same executable out every time?

Edit: Let me be clear, I understand what is going on mechanically, I understand that stack build rebuilds only what "needs to be rebuilt", the thing is if I run stack build what I want is for it to rebuild everything that required to make a release build, and if I had just built with profiling, and that means to rebuild everything, so be it.

Edit 2: Okay, I know that stack has no idea about a release or profiling build etc, that there's no fundamental distinction, but --profile just changes ghc flags right? I guess what I'm asking is, why doesn't rebuild-ghc-options do what it says on the tin? If the ghc options change, why isn't it fully rebuilding the project? What does that flag actually do?

  • 1
    Perhaps I'm missing something, but isn't that just a side effect of incremental building? `stack build` will only build the modules that were changed since the last invocation, and so if that happened to involve `--profile` then the changed modules would need to be built with `--profile` as well, even if you don't specify the option the second time. – duplode Oct 11 '16 at 16:25
  • 1
    @duplode Yeah it is obviously a side effect of previous builds, sorry maybe I wasn't clear that's exactly what I *don't* want. I want a command, whatever it is, to build a "release build" and a "profile build", and if I run the command to build the "release build" I don't want to have to think about the state of things right now I just want it to produce a release build. I could just clean every time, but that slows down my build process, I want stack to figure this out for me! –  Oct 11 '16 at 17:02
  • There is no formal distinguishment in the stack system between a 'release build' and any other build. The command `stack build` will simply build your targets according to the build plan, if it exists, and if not, create some build plan according to some defaults and then build that. If you have an existing build plan (but not the one you want) you must first replace it. Does `-no-executable-profiling` do what you want? Or perhaps adding a cabal flag which formally specifies the difference between release and devel? Changing any flag requires a re-configure (stack will see this, I presume) – user2407038 Oct 12 '16 at 04:12
  • @user2407038 I know there's no formal distinction between a 'release build' and a 'profiling build', but the ghc options change right? I guess what I'm asking is, if I change the ghc options, why is stack not rebuilding everything in my project with the new ghc options, even though the option I thought that would enable this `rebuild-ghc-options`, does not seem to work or works differently than I expect. What should be my workflow? Always simply remember to run build clean after building with custom ghc options? –  Oct 12 '16 at 19:40

0 Answers0