Home > Blockchain >  XMonad crashing: how to do proper build with Stack and custom build script?
XMonad crashing: how to do proper build with Stack and custom build script?

Time:11-24

OS: linux gentoo 6.0.9

I am attempting to build a custom version of XMonad using Stack and a build script I wrote, which is closely based on this one here.

build.sh:

#!/bin/sh
SRC_DIR=$HOME/.config/xmonad
EXE_DIR=$HOME/.local/bin
EXE_NAME=xmonad
######################
unset STACK_YAML
cd $SRC_DIR
stack build 2>.log
ln -f -T $(stack exec -- which $EXE_NAME) $EXE_DIR/$EXE_NAME 2>.log
rm ./src/$EXE_NAME.hi ./src/$EXE_NAME.o 2>/dev/null

The stack build invocation above fails to compile a module that I wrote called Prompt.Man (not to be confused by XMonad.Prompt.Man, which I did not write) that previously compiled fine, and I do not understand the GHC error at all; when I try looking at the file the error references (XMonad/Actions/OnScreen.dyn_hi), it is a binary.

.log:

Building executable 'xmonad-vem:xmobar'.
Other executables with the same name might be overwritten: 'xmobar:xmobar'.

Building executable 'xmonad-vem:xmonad'.
Other executables with the same name might be overwritten: 'xmonad:xmonad'.

Building all executables for `xmonad-vem' once. After a successful build of all of them, only specified executables will be rebuilt.
xmonad-vem> configure (exe)
xmonad-vem> Configuring xmonad-vem-0.3...
xmonad-vem> build (exe)
xmonad-vem> Preprocessing executable 'xmobar' for xmonad-vem-0.3..
xmonad-vem> Building executable 'xmobar' for xmonad-vem-0.3..
xmonad-vem> [9 of 9] Compiling Prompt.Man
xmonad-vem> 
xmonad-vem> /home/myuser/.config/xmonad/src/Prompt/Man.hs:9:1: error:
xmonad-vem>     Bad interface file: /home/myuser/.config/xmonad/.stack-work/install/x86_64-linux-tinfo6/11f8cebbee3588011a80cb3a0acfb83ab68c1e233a64bf2f944fbcae91e1b2fb/8.10.6/lib/x86_64-linux-ghc-8.10.6/xmonad-contrib-0.17.0-KtuI6PQ7yCQKkNv0hd26Wj/XMonad/Actions/OnScreen.dyn_hi
xmonad-vem>         Something is amiss; requested module  xmonad-contrib-0.17.0:XMonad.Actions.OnScreen differs from name found in the interface file xmonad-contrib-0.17.0-Jq55vblrWW56gRIiMssDFv:XMonad.Actions.OnScreen (if these names look the same, try again with -dppr-debug)
xmonad-vem>   |
xmonad-vem> 9 | import XMonad.Actions.OnScreen (onlyOnScreen)
xmonad-vem>   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

--  While building package xmonad-vem-0.3 (scroll up to its section to see the error) using:
      /home/myuser/.stack/setup-exe-cache/x86_64-linux-tinfo6/Cabal-simple_mPHDZzAJ_3.2.1.0_ghc-8.10.6 --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0 build exe:xmobar exe:xmonad --ghc-options ""
    Process exited with code: ExitFailure 1

Adding the flag -dppr-debug to ghc-opts in package.yaml as suggested by GHC yields the exact same error message upon attempt to rebuild.

I've also tried deleting my .stack and .stack-work directories and then re-running as a hopeless attempt to see if that fixes anything, to no avail.

What is causing this error, and how can I resolve it?

Additional files

stack.yaml:

resolver: lts-18.7
packages:
  - .
  - /var/cache/distfiles/xmobar-0.44.1
  - /var/cache/distfiles/xmonad-0.17.0
  - /var/cache/distfiles/xmonad-contrib-0.17.0
extra-deps: []
flags:
  xmobar:
    with_xpm: false
    with_threaded: false
    with_xft: true
    with_rtsopts: false
    with_alsa: true
    with_mpd: false
    with_weather: false
    with_dbus: false
    with_mpris: false
    with_inotify: false
    with_nl80211: false
    with_iwlib: false
    with_datezone: false
    with_uvmeter: false
    with_kraken: false
arch: x86_64

/var/cache/distfiles/ is where I have specific versions of the source code for xmonad, xmonad-contrib, and xmobar saved.

package.yaml:

name: xmonad-vem
version: 0.3

ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints -O2 -j -dynamic

dependencies:
  - base
  - containers
  - directory
  - filepath
  - process
  - regex-tdfa
  - utf8-string
  - unix
  - xmobar
  - xmonad >= 0.17
  - xmonad-contrib >= 0.17

source-dirs:
  - src

executables:
  xmonad:
    main: xmonad.hs
    dependencies:
      - xmonad
      - X11 >= 1.10
  xmobar:
    main: xmobar.hs
    dependencies:
      - xmobar

UPDATE #1

At the request of a comment saying that the issue is with the globally-installed version of xmonad-contrib-0.17.0, I tried stack exec ghc-pkg unregister xmonad-contrib-0.17.0 && stack build, which now compiles but immediately crashes at runtime with the following error:

discover_other_daemon: 0/home/myuser/.local/bin/xmonad: error while loading shared libraries: libHSxmonad-contrib-0.17.0-Jq55vblrWW56gRIiMssDFv-ghc8.10.6.so: cannot open shared object file: No such file or directory

UPDATE #2

I figured part of this out thanks to a comment; I needed to update my stack.yaml to not include the local versions of xmonad, xmonad-contrib, and xmobar and let Stack just fetch them for me:

stack.yaml:

resolver: lts-18.7
packages:
  - .
extra-deps:
  - xmonad-0.17.0
  - xmonad-contrib-0.17.0
  - xmobar-0.44.1
  xmobar:
    with_xpm: false
    with_threaded: false
    with_xft: true
    with_rtsopts: false
    with_alsa: true
    with_mpd: false
    with_weather: false
    with_dbus: false
    with_mpris: false
    with_inotify: false
    with_nl80211: false
    with_iwlib: false
    with_datezone: false
    with_uvmeter: false
    with_kraken: false
arch: x86_64

...and slightly edit the build script: build.sh:

#!/bin/sh
SRC_DIR=$HOME/.config/xmonad
EXE_DIR=$HOME/.local/bin
EXE_NAME_XMONAD=xmonad
EXE_NAME_XMOBAR=xmobar
######################
unset STACK_YAML
cd $SRC_DIR
stack build 2>.log
ln -f -T $(stack exec -- which $EXE_NAME_XMONAD) $EXE_DIR/$EXE_NAME_XMONAD 2>.log
ln -f -T $(stack exec -- which $EXE_NAME_XMOBAR) $EXE_DIR/$EXE_NAME_XMOBAR 2>.log
rm ./src/$EXE_NAME_XMONAD.hi ./src/$EXE_NAME_XMONAD.o ./src/$EXE_NAME_XMOBAR.hi ./src/$EXE_NAME_XMOBAR.o 2>/dev/null

And I still get a similar runtime error after executing build.sh and trying to run the new xmonad and xmobar from /home/myuser/.local/bin on X server:

discover_other_daemon: 0XMonad is recompiling and replacing itself with another XMonad process because the current process is called "xmonad" but the compiled configuration should be called "xmonad-x86_64-linux"
XMonad will use build script at "/home/myuser/.config/xmonad/build" to recompile.
XMonad recompiling because a custom build script is being used.
XMonad recompilation process exited with success!
/home/myuser/.cache/xmonad/xmonad-x86_64-linux: error while loading shared libraries: libHSxmonad-contrib-0.17.0-KtuI6PQ7yCQKkNv0hd26Wj-ghc8.10.6.so: cannot open shared object file: No such file or directory

CodePudding user response:

I figured this out. This is what I had to do:

#1

Use the following as my starting point for the Stack config.

stack.yaml:

resolver: lts-18.7
packages:
  - .
extra-deps:
  - xmonad-0.17.0
  - xmonad-contrib-0.17.0
  - xmobar-0.44.1
  xmobar:
    with_xpm: false
    with_threaded: false
    with_xft: true
    with_rtsopts: false
    with_alsa: true
    with_mpd: false
    with_weather: false
    with_dbus: false
    with_mpris: false
    with_inotify: false
    with_nl80211: false
    with_iwlib: false
    with_datezone: false
    with_uvmeter: false
    with_kraken: false
arch: x86_64

package.yaml:

name: xmonad-vem
version: 0.3

ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints -O2 -j -dynamic

dependencies:
  - base
  - containers
  - directory
  - filepath
  - process
  - regex-tdfa
  - utf8-string
  - unix
  - xmobar
  - xmonad >= 0.17
  - xmonad-contrib >= 0.17

source-dirs:
  - src

executables:
  xmonad:
    main: xmonad.hs
    dependencies:
      - xmonad
      - X11 >= 1.10
  xmobar:
    main: xmobar.hs
    dependencies:
      - xmobar
Explanation

Needed to make sure Stack pulls in as dependencies the versions of xmonad, xmonad-contrib, and xmobar that I want to use as a starting point, as specified by the dependencies in package.yaml; as opposed to trying to use the globally installed versions I have on my machine.

#2

Update my build script to the following:

#!/bin/sh
SRC_DIR=$HOME/.config/xmonad
EXE_NAME=xmonad
unset STACK_YAML
FAIL=0
cd $SRC_DIR
stack build 2>.log || FAIL=1
ln -f -T $(stack exec -- which $EXE_NAME) $1 2>.log || FAIL=2
rm ./src/*.hi ./src/*.o 2>/dev/null
exit $FAIL

then invoking xmonad --recompile && startx works how it should.

Explanation

The recompiling process for XMonad does more than what my build script did. In mine, I was simply linking the compiled xmonad and xmobar binaries directly to my local bin and exiting, then invoking ./build on the command line to recompile xmonad; however, calling the build script via xmonad --recompile actually passes an argument to ./build and is supposed to link the binaries to that.

Thanks to @lsmor for pointing this out.

  • Related