Cabal install criterion out of memory

1k views Asked by At

I'm running on a container with 768MB ram and 512 MB swap space. I can't increase either of this. cabal install criterion always gives

Failed during the building phase.
The exception was: ExitFailure (-9)
This may be due to an out-of-memory condition.

during Compiling Criterion.Types. Is there any way around this or do I have to make do without criterion?

2

There are 2 answers

3
Li-yao Xia On BEST ANSWER

Set RTS flags on GHC to limit its memory usage (--ghc-options="+RTS -M600M") and avoid running multiple jobs in parallel (-j1).

2
marcel_g On

Answer to @DavidAzar's comment on the answer:

@Li-yaoXia's solution worked, but then I had more problems. This is all from my rough notes as I tracked my way through the problem. So there might be a more streamlined solution.

Well, actually it compiled everything, but cabal --version still says 2.4, not 3.4. Maybe it's not in the path?

Warning: could not create a symlink in /root/.cabal/bin for cabal because 
the file exists there already but is not managed by cabal. You can create a symlink for 
this executable manually if you wish. The executable file has been installed at /root/.cabal/bin/cabal

There appears to be a solution here: https://stackoverflow.com/a/17030330/52236 But I have to figure out how to remove the existing symlink before redoing the cabal install and doing the recompile process all over again.

There is also this solution here, which I will try first: updating cabal-install, but version is not changed

  • Ran unminimize from bash, which installs all the normal stuff to ubuntu.

  • First, in /bin, create a folder called /cabal-old, then copy the cabal executable to the cabal-old folder. Then remove cabal from the /bin folder.

  • Then create a new symlink pointing to the new cabal executable:

    ln -s /root/.cabal/bin/cabal cabal

  • This gets cabal 3.4 to show up when doing cabal --version.

  • Next, install git: apt-get install git

  • Then go to plutus-pioneer-program/code/week01/ folder and enter cabal build

  • This downloads a lot of stuff from git, and then fails.

    Warning: Requested index-state 2021-02-24T00:00:00Z is newer than 'hackage.haskell.org'! Falling back to older state (2021-02-23T23:53:53Z). Resolving dependencies...cabal: Could not resolve dependencies: [__0] trying: Win32-network-0.1.0.0 (user goal) [__1] trying: base-4.12.0.0/installed-4.12.0.0 (dependency of Win32-network) [__2] next goal: plutus-pioneer-program-week01 (user goal) [__2] rejecting: plutus-pioneer-program-week01-0.1.0.0 (conflict:base==4.12.0.0/installed-4.12.0.0, plutus-pioneer-program-week01 =>base^>=4.14.1.0) [__2] fail (backjumping, conflict set: base, plutus-pioneer-program-week01)

    After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: base, Win32-network,plutus-pioneer-program-week01

  • I got a suggestion from someone on Stackoverflow that the Plutus-Pioneer code might need ghc 8.10, and I'm on a version of 8.6.5, so next step is to figure out how to update that.

  • Before getting ghc 8.10, I apparently need to have ghcup installed, run this as non-root user?:

    curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh

  • this started the install, but failed because I don't have 'make' installed. Run this:

    apt-get install make

  • then re-run the curl command. The curl installer output shows ghc 8.10 being installed, but after it's done, ghc --version outputs 8.6.5 still. Another symlink issue?

  • I found this issue in the output:

    In order to run ghc and cabal, you need to adjust your PATH variable. You may want to source '/root/.ghcup/env' in your shell configuration to do so (e.g. ~/.bashrc).

  • It also might require figuring out how to specify which version of ghc to use.

  • I need to update the simlink in the bin folder in order to get the correct version of ghc being used, and there are the following other links to update:

lrwxrwxrwx 1 root root   9 Mar 24  2020 ghc -> ghc-8.6.5
-rwxr-xr-x 1 root root 226 Mar 24  2020 ghc-8.6.5  
lrwxrwxrwx 1 root root  13 Mar 24  2020 ghc-pkg -> ghc-pkg-8.6.5
-rwxr-xr-x 1 root root 258 Mar 24  2020 ghc-pkg-8.6.5  
lrwxrwxrwx 1 root root  10 Mar 24  2020 ghci -> ghci-8.6.5
-rwxr-xr-x 1 root root  55 Mar 24  2020 ghci-8.6.5

First, created a new symlink for ghcup:

ln -s /root/.ghcup/bin/ghcup ghcup

(Although I can't remember what I needed ghcup for.)

  • Next, update the ghc symlinks for all 3 symlinks listed above in the /bin folder:

    mv -T ghc ghc-old-link ln -s /root/.ghcup/bin/ghc ghc

  • This works to get the newer version of ghc showing up in the bash shell.

  • Now trying to build, and it downloads and starts building a lot of stuff, but now this error happens:

    cabal: Failed to build cborg-0.2.4.0 (which is required by plutus-pioneer-program-week01-0.1.0.0). The build process was killed (i.e.SIGKILL). The typical reason for this is that there is not enough memory available (e.g. the OS killed a process using lots of memory).

Solution for this: Docker -> Preferences -> Resources -> increase RAM, and swap space. In my case from 2-8GB RAM, and from 1 to 2 GB swap space.

Now it builds the Plutus Pioneer code for week 1.