Skip to content

cabal v2-test fails when opening shared object file #8580

Closed

Description

@brandonchinn178

I'm trying to add Cabal to my CI matrix, but running cabal exec -- cabal v2-test fails in CI with

libHS-tasty-autocollect-0.3.1.0-inplace-ghc9.4.2.so: cannot open shared object file: No such file or directory

The mentioned file is the same library I'm building; the tricky thing about this library is that the library defines a compiler plugin, and the test suite uses the plugin itself.

It works with Stack in CI and locally, and cabal exec -- cabal v2-test works locally.

Note: please let me know if there's a better place to ask for help. I tried posting on the #ghc IRC channel and in r/haskell, but got no responses

Activity

  1. gbaz commented on Nov 9, 2022

    @gbaz
    Collaborator

    The confusing thing here is that you say it works locally. So the question is -- what is the CI script doing that the local build is not? My hunch is that it must be doing something different, and I suspect it may be some sort of cleaning between the actions? Would a workaround be to actually install the plugin (or at least v2-install it) and then make use of the installed plugin, or is that not possible due to the way cabal sets things up?

    Alternately -- create a cabal project, and have one the test package depend on the main one?

  2. brandonchinn178 commented on Nov 9, 2022

    @brandonchinn178
    CollaboratorAuthor

    I mean the obvious difference is I'm on Mac and CI is on Ubuntu. But there's no cleaning, the CI action is literally

      cabal_test:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v3
    
          - run: cabal update
          
          # cache stuff
          - run: cabal freeze
          - run: date +%m > /tmp/cache-month
          - uses: actions/cache@v3
            with:
              path: ~/.cabal
              key: ${{ runner.os }}-cabal-cache-${{ hashFiles('/tmp/cache-month') }}-${{ hashFiles('cabal.project.freeze') }}
              restore-keys: |
                   ${{ runner.os }}-cabal-cache-${{ hashFiles('/tmp/cache-month') }}-
    
          # build + test
          - run: cabal v2-build
          - run: cabal exec -- cabal v2-test

    I would prefer to avoid adding extra layers of indirection, since it works as-is with Stack. Why would Stack build the test suite fine, but Cabal not?

  3. gbaz commented on Nov 9, 2022

    @gbaz
    Collaborator

    "Why would Stack build the test suite fine, but Cabal not?"

    But cabal does build the test suite fine, you observed! It just doesn't build it in the particular CI setup on ubuntu! That's the question you need to ask. Since I only have a mac, I can't replicate this in a way that's meaningful, and I also suspect that it'll work fine from the command line on ubuntu as well, since cabal behaves almost the same on both systems -- its going to have to be something specific to CI, and I honestly can't tell you what. Perhaps its the interaction with the freeze or cache stuff?

  4. brandonchinn178 commented on Nov 9, 2022

    @brandonchinn178
    CollaboratorAuthor

    Ok this is interesting. I changed CI to run just

      cabal_test:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v3
          - uses: haskell/actions/setup@v2
            with:
              ghc-version: '9.2'
          - run: cabal update
          - run: cabal exec -- cabal v2-test

    and now it's failing on: (link)

    libHSparsec-3.1.15.0-ghc9.2.4.so: cannot open shared object file: No such file or directory
    

    I can also reproduce with this Dockerfile:

    Docker repro
    FROM ubuntu:latest
    
    # set UTF-8 locale
    RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y locales
    RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
        dpkg-reconfigure --frontend=noninteractive locales && \
        update-locale LANG=en_US.UTF-8
    ENV LANG en_US.UTF-8
    
    # install haskell toolchain
    RUN apt-get update \
        && apt-get install -y build-essential curl libnuma-dev \
        && curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_NONINTERACTIVE=1 sh
    ENV PATH="$PATH:/root/.ghcup/bin"
    
    # clone repo
    RUN apt-get update \
        && apt-get install -y git \
        && git clone https://github.com/brandonchinn178/tasty-autocollect
    WORKDIR tasty-autocollect
    
    # build + test
    RUN apt-get update \
        && apt-get install -y libgmp-dev libncurses5 libncurses-dev libtinfo5
    RUN cabal update \
        && cabal exec -- cabal v2-test

    Since I can repro locally via Docker, it seems like it's not specific to my CI setup.

    If I comment out the last cabal v2-test line and start a shell in the Docker container with docker run, I can debug a bit further.

    Debug info
    $ cabal exec -- cabal v2-test
    ...
    libHSparsec-3.1.15.0-ghc9.2.5.so: cannot open shared object file: No such file or directory
    
    $ find / -name 'libHSparsec*'
    /root/.ghcup/ghc/9.2.5/lib/ghc-9.2.5/parsec-3.1.15.0/libHSparsec-3.1.15.0-ghc9.2.5.so
    /root/.ghcup/ghc/9.2.5/lib/ghc-9.2.5/parsec-3.1.15.0/libHSparsec-3.1.15.0.a
    /root/.ghcup/ghc/9.2.5/lib/ghc-9.2.5/parsec-3.1.15.0/libHSparsec-3.1.15.0_p.a
    
    $ cabal exec -- /root/.ghcup/bin/ghc -itest test/Main.hs -F '-pgmF=tasty-autocollect' 
    Loaded package environment from /tasty-autocollect/dist-newstyle/tmp/environment.-6795/.ghc.environment.aarch64-linux-9.2.5
    <command line>: libHSparsec-3.1.15.0-ghc9.2.5.so: cannot open shared object file: No such file or directory
    
    $ cabal exec -- /root/.ghcup/bin/ghc -itest test/Main.hs -F '-pgmF=tasty-autocollect' -v
    Loaded package environment from /tasty-autocollect/dist-newstyle/tmp/environment.-6935/.ghc.environment.aarch64-linux-9.2.5
    Glasgow Haskell Compiler, Version 9.2.5, stage 2 booted by GHC version 8.10.7
    *** initializing unit database:
    Using binary package database: /root/.ghcup/ghc/9.2.5/lib/ghc-9.2.5/package.conf.d/package.cache
    Using binary package database: /root/.cabal/store/ghc-9.2.5/package.db/package.cache
    Using binary package database: /tasty-autocollect/dist-newstyle/packagedb/ghc-9.2.5/package.cache
    ...
    
    $ tail -n20 /root/.ghcup/ghc/9.2.5/lib/ghc-9.2.5/package.conf.d/parsec-3.1.15.0.conf 
        Text.ParserCombinators.Parsec.Perm
        Text.ParserCombinators.Parsec.Pos
        Text.ParserCombinators.Parsec.Prim
        Text.ParserCombinators.Parsec.Token
    
    import-dirs:          /root/.ghcup/ghc/9.2.5/lib/ghc-9.2.5/parsec-3.1.15.0
    library-dirs:         /root/.ghcup/ghc/9.2.5/lib/ghc-9.2.5/parsec-3.1.15.0
    dynamic-library-dirs: /root/.ghcup/ghc/9.2.5/lib/ghc-9.2.5/parsec-3.1.15.0
    data-dir:
        /root/.ghcup/ghc/9.2.5/share/aarch64-linux-ghc-9.2.5/parsec-3.1.15.0
    
    hs-libraries:         HSparsec-3.1.15.0
    depends:
        base-4.16.4.0 bytestring-0.11.3.1 mtl-2.2.2 text-1.2.5.0
    
    haddock-interfaces:
        /root/.ghcup/ghc/9.2.5/share/doc/ghc-9.2.5/html/libraries/parsec-3.1.15.0/parsec.haddock
    
    haddock-html:
        /root/.ghcup/ghc/9.2.5/share/doc/ghc-9.2.5/html/libraries/parsec-3.1.15.0

    So GHC is loading the correct package.conf.d, which points to the directory containing the .so file??

  5. tbidne commented on Nov 10, 2022

    @tbidne
    Contributor

    Interestingly, changing the cabal exec -- cabal v2-test to cabal test allows it to run without issues. Here's the run, and here is the yaml file. Some of the tests fail though, presumably the ones that needed cabal exec in the first place.

    Your failing test logs mentions this at one point:

    Loaded package environment from /home/runner/work/tasty-autocollect/tasty-autocollect/dist-newstyle/tmp/environment.-3614/.ghc.environment.x86_64-linux-9.4.2
    

    Maybe that's right, but my experience is to be wary of .ghc.environment.* files. Unfortunately, --write-ghc-environment-files does not seem to have any effect.

  6. brandonchinn178 commented on Nov 12, 2022

    @brandonchinn178
    CollaboratorAuthor

    Ah yes, I did know that, but that did give me one final idea that got it working! I was able to do

    cabal configure --enable-tests
    cabal v2-build
    cabal exec -- v2-test

    i.e. build the test outside of the cabal exec environment, then run the tests inside it.

    This still seems like a Cabal bug; conceptually, I would think that cabal exec -- v2-build --enable-tests should always work (i.e. cabal exec shouldn't affect the build). It seems like there might be some edge case around Ubuntu + writing a compiler plugin + cabal exec. But I recognize this is probably a very rare edge case, so feel free to close until another incident comes up. At the very least, this is now documented

  7. Mikolaj commented on Dec 5, 2022

    @Mikolaj
    Member

    Thank you for documenting this. Let's remember to compare once we have new data points. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions