Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-102592

Setting a common CMAKE_STAGING_PREFIX breaks build rpaths of non-qtbase repositories

    XMLWordPrintable

Details

    • 251033fb0a (qt/qtbase/dev) 251033fb0a (qt/tqtc-qtbase/dev)

    Description

      Upstream issue https://gitlab.kitware.com/cmake/cmake/-/issues/23421

      Scenario:

      Desktop Linux / macOS

      qtbase/configure -extprefix /tmp/sysroot -prefix /usr && ninja instlal
      qt-configure-module qtshadertools && ninja install
      qt-configure-module qtdeclarative && ninja
      

      qtdeclarative will fail to build with

       Automatic QML type registration for target Qml
      FAILED: src/qml/qml_qmltyperegistrations.cpp
      
      dyld: Library not loaded: @rpath/libQt6Core_debug.6.dylib
        Referenced from: /qtdeclarative_build/libexec/qmltyperegistrar
        Reason: image not found
      /bin/sh: line 1:  2493 Abort trap: 6 qtdeclarative_build/libexec/qmltyperegistrar
      

      CMake has logic to replace any rpath that it encounters that starts with CMAKE_STAGING_PREFIX, with CMAKE_INSTALL_PREFIX.

      I believe this makes sense for install rpaths, but not build rpaths.

      qmltyperegistrar depends on QtCore, so I expect the /tmp/sysroot/lib rpath to be present, so that it successfully loads Core, but it's rewritten to /usr/lib, which has no Qt on my machine, and fails to run.

      All binaries / libraries outside of qtbase are affected, but the issue mostly surfaces with tools that actually need to run during the build.

      Upon installation, all the build rpaths are rewritten to correct install rpaths, so installed binaries are not affected.

      Cross-builds in the CI (e.g. qemu / yocto) are not affected, because they use host tools, and none of our host CI builds use CMAKE_STAGING_PREFIX.

      Top-level builds are not affected because CMake will not embed any rpaths to the staging area, because there are no packages / libraries loaded from there at build time.

      Non-prefix staging builds also have wrong rpaths, aka

      mkdir ~/qtbase_build && cd ~/qtbase_build
      ~/qtbase/configure -extprefix ~/qtbase_build -prefix /usr
      

      but they usually don't fail because qt_apply_rpaths adds additional build time relative rpaths with $ORIGIN/@loader_path , which are not rewritten.
      If relative rpaths are disabled or unsupported, the build still fails.

      Also, for standalone tests, we explicitly work around the issue by setting CMAKE_STAGING_PREFIX of the tests subdirectory to an empty string, to avoid CMake rewriting the rpaths. It's safe to do for tests, because we never intend to install tests.
      https://codereview.qt-project.org/c/qt/qtbase/+/318708/3/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              alexandru.croitor Alexandru Croitor
              alexandru.croitor Alexandru Croitor
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes