Zokka-Dev / zokka-compiler

Fork of compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
81 stars 0 forks source link

Find out some way to use `cabal install` instead of `cabal build` in the GH workflow file #5

Closed changlinli closed 6 months ago

changlinli commented 7 months ago

Quick Summary:

Currently we use a combination of cabal build and cabal list-bin to extract a binary that's built by Elm. This is because cabal install results in a Template Haskell error related to changeWorkingDirectory.

It would be much more ideal to use cabal install directly instead of this two-step hack, both because that's the preferred way to actually generate binaries with Cabal, but also because cabal list-bin is quite fragile in the face of different Cabal build optimizations. E.g. cabal list-bin no longer lists the correct directory path if I pass optimization flags to Cabal, so the current executable is just not using the highest optimization level (I wonder if the vanilla Elm compiler is affected by this as well and hence isn't actually as fast it could be with -O2 used instead of just -O1).

This issue tracks solving that TH error when using cabal install. It might be the case that we give up using Template Haskell altogether and embed the data for the reactor subcommand some other way as a post-compile step.

SSCCE

Run cabal install and we get the following error:

terminal/src/Develop/StaticFiles.hs:92:3: error:
    • Exception when trying to run compile-time code:
        reactor: changeWorkingDirectory: does not exist (No such file or directory)
      Code: (bsToExp
               =<<
                 runIO
                   (do setLogFlag True
                       Build.buildReactorFrontEnd))
    • In the untyped splice:
        $(bsToExp
            =<<
              runIO
                (do setLogFlag True
                    Build.buildReactorFrontEnd))
   |
92 |   $(bsToExp =<< runIO (do setLogFlag True; Build.buildReactorFrontEnd))
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: cabal: Failed to build exe:zelm from elm-0.19.1. See the build log
above for details.
changlinli commented 7 months ago

In particular while the vanilla Elm compiler uses -O2 as a GHC flag, that probably applies only to the executable. I want to apply -O2 to the entire dependency tree

changlinli commented 6 months ago

Turns out if we specify the optimization level in cabal.project instead of passing --enable-optimizations as a flag, cabal list-bin does just fine.

changlinli commented 6 months ago

That's enough to close the issue since getting cabal install to work is not as pressing