Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

depends: Remove Qt build-time dependencies #29923

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

laanwj
Copy link
Member

@laanwj laanwj commented Apr 20, 2024

In the spirit of the halving, let's (approximately) halve the number of packages in depends. Remove the following packages:

  bdb.mk
  boost.mk
  capnp.mk
- expat.mk
- fontconfig.mk
- freetype.mk
  libevent.mk
  libmultiprocess.mk
  libnatpmp.mk
- libXau.mk
- libxcb.mk
- libxcb_util.mk
- libxcb_util_image.mk
- libxcb_util_keysyms.mk
- libxcb_util_render.mk
- libxcb_util_wm.mk
- libxkbcommon.mk
  miniupnpc.mk
  native_capnp.mk
  native_cctools.mk
  native_libmultiprocess.mk
  native_libtapi.mk
  native_llvm.mk
  packages.mk
  qrencode.mk
  qt.mk
+ qtsowrap.mk
  sqlite.mk
  systemtap.mk
- xcb_proto.mk
- xproto.mk
  zeromq.mk

This is done by loading all of Qt's system dependencies at run-time, replacing them with an auto-generated wrapper library qtsowrap:

Basic diagram

See https://github.com/laanwj/qtsowrap for details.

After this, bitcoin-qt has the same direct linking dependencies as bitcoind and other binaries:

$ ldd build/src/qt/bitcoin-qt
        linux-vdso.so.1 (0x00007ffc01d83000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f76dbf1f000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f76dbc00000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f76de7a7000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f76dba1f000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f76de7d7000)

(libdl.so.X needed too depending on the libc version)

For comparison, bitcoin-qt from release 27.0 has the following:

$ ldd ~/workdir/x86_64-linux-gnu/bitcoin-27.0/bin/bitcoin-qt 
        linux-vdso.so.1 (0x00007ffde7f73000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa098e37000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa098e2f000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa098d4f000)
        libfontconfig.so.1 => /lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007fa098cff000)
        libfreetype.so.6 => /lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007fa09632f000)
        libxcb-icccm.so.4 => /lib/x86_64-linux-gnu/libxcb-icccm.so.4 (0x00007fa098cf7000)
        libxcb-image.so.0 => /lib/x86_64-linux-gnu/libxcb-image.so.0 (0x00007fa098cef000)
        libxcb-shm.so.0 => /lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007fa098ce7000)
        libxcb-keysyms.so.1 => /lib/x86_64-linux-gnu/libxcb-keysyms.so.1 (0x00007fa096000000)
        libxcb-randr.so.0 => /lib/x86_64-linux-gnu/libxcb-randr.so.0 (0x00007fa098ccf000)
        libxcb-render-util.so.0 => /lib/x86_64-linux-gnu/libxcb-render-util.so.0 (0x00007fa095c00000)
        libxcb-render.so.0 => /lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007fa098cbf000)
        libxcb-shape.so.0 => /lib/x86_64-linux-gnu/libxcb-shape.so.0 (0x00007fa098cb7000)
        libxcb-sync.so.1 => /lib/x86_64-linux-gnu/libxcb-sync.so.1 (0x00007fa098caf000)
        libxcb-xfixes.so.0 => /lib/x86_64-linux-gnu/libxcb-xfixes.so.0 (0x00007fa098c9f000)
        libxcb-xinerama.so.0 => /lib/x86_64-linux-gnu/libxcb-xinerama.so.0 (0x00007fa096327000)
        libxcb-xkb.so.1 => /lib/x86_64-linux-gnu/libxcb-xkb.so.1 (0x00007fa096307000)
        libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007fa0962d7000)
        libxkbcommon-x11.so.0 => /lib/x86_64-linux-gnu/libxkbcommon-x11.so.0 (0x00007fa0962c7000)
        libxkbcommon.so.0 => /lib/x86_64-linux-gnu/libxkbcommon.so.0 (0x00007fa09627f000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa09625f000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa095e1f000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fa098e4f000)
        libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007fa09622f000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fa09620f000)
        libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16 (0x00007fa095bc7000)
        libbrotlidec.so.1 => /lib/x86_64-linux-gnu/libbrotlidec.so.1 (0x00007fa095e0f000)
        libxcb-util.so.1 => /lib/x86_64-linux-gnu/libxcb-util.so.1 (0x00007fa095bbf000)
        libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007fa096207000)
        libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007fa095800000)
        libbrotlicommon.so.1 => /lib/x86_64-linux-gnu/libbrotlicommon.so.1 (0x00007fa095b97000)
        libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007fa095b7f000)
        libmd.so.0 => /lib/x86_64-linux-gnu/libmd.so.0 (0x00007fa095b6f000)

This does not affect Windows or MacOS, which already do not have this problem of having to build half the OS in the dependency chain.

This will make it possible to add Wayland support to the release binaries without requiring the Wayland (or X) libraries to be installed on every system that runs them.

Reviewing/Testing

TODOs (all done)

(before merge, probably)

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 20, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK jonatack

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #30049 (build, test, doc: Temporarily remove Android-related stuff by hebasto)
  • #29880 (depends: build FreeType with CMake by fanquake)
  • #29878 (depends: build expat with CMake by fanquake)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@luke-jr
Copy link
Member

luke-jr commented Apr 21, 2024

Instead of Qt's dependencies, maybe we should wrap Qt itself this way? Or do C++ templates break that too much?

@laanwj
Copy link
Member Author

laanwj commented Apr 21, 2024

Instead of Qt's dependencies, maybe we should wrap Qt itself this way? Or do C++ templates break that too much?

This is basically not possible with a C++ library. It is thanks to C's lack of name mangling and its straightforward linkage model that makes this possible. Also Qt has a ton of symbols compared to these libraries. And even if you narrow it down to only the used symbols, it's much harder to keep track of.

Conceptually, a few low-level X11 (or in the future, Wayland) and font libraries are much more likely to be on the user's system than a compatible version of Qt. That will only become worse with Qt 5 versus 6. This PR, as is, doesn't change the needed libraries, only how they're imported.

@DrahtBot
Copy link
Contributor

Guix builds (on x86_64)

File commit 67c0d93
(master)
commit eed10dd
(master and this pull)
SHA256SUMS.part 0744b1285352a368... 1a98bfe3c1beccf7...
*-aarch64-linux-gnu-debug.tar.gz 16b414f82f4f07bd... 67822a1b1b1ba79a...
*-aarch64-linux-gnu.tar.gz 117b35bd779ed725... c62e79c489bb0cb6...
*-arm-linux-gnueabihf-debug.tar.gz 07e864c7389441c9... 29c2ee47a1176010...
*-arm-linux-gnueabihf.tar.gz db135d89aa80ca9a... 1c0f91b81c0cefdf...
*-arm64-apple-darwin-unsigned.tar.gz 98e4bf8a803c8a43... fd94966e3845c4db...
*-arm64-apple-darwin-unsigned.zip 6aecc3420e8db5f6... d3febce3a26e5eed...
*-arm64-apple-darwin.tar.gz 0f34ec3767a21c30... 05cb2476b672acf9...
*-powerpc64-linux-gnu-debug.tar.gz ffee35ca9046fcfe... 566d5b48f75755bf...
*-powerpc64-linux-gnu.tar.gz 5d7b88059c977045... eb009b208f979a01...
*-riscv64-linux-gnu-debug.tar.gz 40554584a6519644... e3659a5086fe1b79...
*-riscv64-linux-gnu.tar.gz 0e28036c9438f9d3... 5fd8ac0c3f1e39a4...
*-x86_64-apple-darwin-unsigned.tar.gz c9f7d339c48b8c3a... ff199bd2a879b198...
*-x86_64-apple-darwin-unsigned.zip 6bb037c1a1e0003c... cd284f0531fb033d...
*-x86_64-apple-darwin.tar.gz 02856cf44b673e4d... 4d4ffc4a383a8038...
*-x86_64-linux-gnu-debug.tar.gz 8938c00d38015b39... e539b47da948ddc1...
*-x86_64-linux-gnu.tar.gz d6ed9bb233a75b51... 361a416eb9b6c192...
*.tar.gz 8a85911c482de010... 1a83436d12c8d025...
guix_build.log 1cef86b1f8b71fe8... 91d6890f319ecbbd...
guix_build.log.diff 97e151810f253905...

@laanwj
Copy link
Member Author

laanwj commented Apr 22, 2024

One important thing to test here is that the resulting bitcoin-qt binaries work on a range of different Linux distributions (also older ones that people still care about).

There's no inherent reason to assume this will make compatibility worse, but it currently loads all symbols from the headers for the respective libraries (https://github.com/laanwj/qtsowrap?tab=readme-ov-file#versions) which might enforce the lower bound on version stronger than used to be done.

Might consider downgrading the headers, if this turns out to be a problem. Or add a list in the descriptor per library of the functions actually used. But this is more work to maintain than a list of version numbers.

@laanwj
Copy link
Member Author

laanwj commented Apr 22, 2024

Example: failure on Ubuntu 22.04:

$ ./bitcoin-qt
/lib/x86_64-linux-gnu/libxcb-xfixes.so.0: undefined symbol: xcb_xfixes_set_client_disconnect_mode_checked
qt.qpa.xcb: Unable to load required libraries, skipping initialization of XCB backend.
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.

Aborted (core dumped)

Ubuntu 22.04 has the following version of libxcb-xfixes:

$ apt-cache show libxcb-xfixes0
Package: libxcb-xfixes0
Architecture: amd64
Version: 1.14-3ubuntu3

1.14. That's kind of strange! That's the same one we have.
It may be due to a difference in xcb_proto (which supplies the protocols that the header files are generated from) instead.
Ours is 1.15.2 (as of 7cb88c8), ubuntu 22.04 has 1.14. So i'll downgrade to that.

Edit: that was it! Ubuntu 22.04 now works.

@DrahtBot
Copy link
Contributor

Guix builds (on x86_64)

File commit 67c0d93
(master)
commit 510237f
(master and this pull)
SHA256SUMS.part 0744b1285352a368... 3ae06a46ca780c3c...
*-aarch64-linux-gnu-debug.tar.gz 16b414f82f4f07bd... d0129eb64e24dc3f...
*-aarch64-linux-gnu.tar.gz 117b35bd779ed725... cb011e21503ded6f...
*-arm-linux-gnueabihf-debug.tar.gz 07e864c7389441c9... 5d6a6d11e3e615ae...
*-arm-linux-gnueabihf.tar.gz db135d89aa80ca9a... ca915b6fc079495b...
*-arm64-apple-darwin-unsigned.tar.gz 98e4bf8a803c8a43... 025f3135577269af...
*-arm64-apple-darwin-unsigned.zip 6aecc3420e8db5f6... 9698d6f66962aabc...
*-arm64-apple-darwin.tar.gz 0f34ec3767a21c30... 853bbf572d24f213...
*-powerpc64-linux-gnu-debug.tar.gz ffee35ca9046fcfe... 1cd5511bf725a041...
*-powerpc64-linux-gnu.tar.gz 5d7b88059c977045... 8a3d01afae413c2a...
*-riscv64-linux-gnu-debug.tar.gz 40554584a6519644... a4471ab56fa86368...
*-riscv64-linux-gnu.tar.gz 0e28036c9438f9d3... a80860a866930eeb...
*-x86_64-apple-darwin-unsigned.tar.gz c9f7d339c48b8c3a... 12d8bf9080c88e99...
*-x86_64-apple-darwin-unsigned.zip 6bb037c1a1e0003c... a245b1f75d50d4b0...
*-x86_64-apple-darwin.tar.gz 02856cf44b673e4d... 45496c3276b269d0...
*-x86_64-linux-gnu-debug.tar.gz 8938c00d38015b39... 446391abd341af1f...
*-x86_64-linux-gnu.tar.gz d6ed9bb233a75b51... aa5d8a27ec441c31...
*.tar.gz 8a85911c482de010... 28b5b41a3d16ba53...
guix_build.log 682b861e333169fc... d817b205d0a593da...
guix_build.log.diff bb1c42ae597e504e...

@laanwj
Copy link
Member Author

laanwj commented Apr 23, 2024

i've added some review notes for the Qt patch here: https://github.com/laanwj/qtsowrap?tab=readme-ov-file#patching-qt

What is important to ensure is that initialize_ happens before any calls to a library, as calling early will cause a crash. Forgetting to wrap a header will be found during linking as the symbol will be wrong.

@laanwj
Copy link
Member Author

laanwj commented Apr 29, 2024

Rebased for merge conflict (trivial: only modify/deletes in packages that go away) and to apply fixup commits.

@laanwj
Copy link
Member Author

laanwj commented Apr 30, 2024

Rebased for #29985 (add/add).

@laanwj
Copy link
Member Author

laanwj commented May 16, 2024

All outstanding TODOs were done. Rebased to master, collected fixups.

Copy link
Contributor

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK. This looks like amazing work, great!

I'm not sure how to help test. Using arm64 macOS 14.4.1, this branch builds cleanly, the unit tests pass, and the GUI runs fine. Don't see any issues on first read of the code.

$ clang --version
Homebrew clang version 18.1.5
Target: arm64-apple-darwin23.4.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin

@laanwj
Copy link
Member Author

laanwj commented May 16, 2024

I'm not sure how to help test. Using arm64 macOS 14.4.1, this branch builds cleanly, the unit tests pass, and the GUI runs fine. Don't see any issues on first read of the code.

Thanks for testing! To be clear, this shouldn't affect MacOS at all, Qt on MacOS (and Windows) doesn't have any of the huge bag of dependencies that Qt Linux/UNIX has.

@maflcko
Copy link
Member

maflcko commented May 17, 2024

I did test an earlier draft of this pull request and the only thing I noticed was that on a fresh desktop install of a Linux distro, sometimes a package would be missing, and the GUI would fail to start. If this is expected, I guess the docs should be adjusted to clarify that users would have to install the packages themselves?

@laanwj
Copy link
Member Author

laanwj commented May 17, 2024

I did test an earlier draft of this pull request and the only thing I noticed was that on a fresh desktop install of a Linux distro, sometimes a package would be missing, and the GUI would fail to start.

Do you have specific output or details? That isn't expected behavior. This PR doesn't change the libraries required to be installed on the user's system, all the dependencies that this removes were already built only to link against. The only difference is that they're loaded at runtime using dlopen instead of by the dynamic linker before the binary runs.

One advantage is that this allows to be more tolerant about which libraries are installed on the user's system, by having control over the loading, not less.

@maflcko
Copy link
Member

maflcko commented May 17, 2024

Do you have specific output or details?

The DrahtBot builds (as well as the log outputs) are deleted by now, as they are short-lived test-only assets. I'll create fresh DrahtBot builds and try again with the current state of this pull request.

@DrahtBot
Copy link
Contributor

Guix builds (on x86_64) [untrusted test-only build, possibly unsafe, not for production use]

File commit a786fd2
(master)
commit 1f1acc8
(master and this pull)
SHA256SUMS.part 14f282b5bf7ebcd4... 5cd90a51129444a6...
*-aarch64-linux-gnu-debug.tar.gz b2364625629230d1... d8ce7d472bec46e4...
*-aarch64-linux-gnu.tar.gz b05fc0561baa0966... fddcd9f96524f394...
*-arm-linux-gnueabihf-debug.tar.gz 4545637daf89882c... 3bb71e7becebbf9f...
*-arm-linux-gnueabihf.tar.gz 27115f4c7e251175... 571615ee8982eb9e...
*-arm64-apple-darwin-unsigned.tar.gz cf3950f9d05fb1c0... 98ddd2d738e9b3d0...
*-arm64-apple-darwin-unsigned.zip b1c32e004722a3b4... f6dd76b44178f3f3...
*-arm64-apple-darwin.tar.gz f09a38acef4b141b... 08ac95f36cd12d01...
*-powerpc64-linux-gnu-debug.tar.gz 75cfe8d73120b00d... 6902c17146d69987...
*-powerpc64-linux-gnu.tar.gz d4f8c1296886fac4... c0f0e350ad3e3c4a...
*-riscv64-linux-gnu-debug.tar.gz a8f56aee14e85f29... 5a50ad28ac39edf7...
*-riscv64-linux-gnu.tar.gz d8a4ae4295e6aa9f... 2e922f98bf947423...
*-x86_64-apple-darwin-unsigned.tar.gz ff9ae232120c85f9... 86b6122b0a21ed79...
*-x86_64-apple-darwin-unsigned.zip 9917159a6fd59954... e49fb32a43702ba6...
*-x86_64-apple-darwin.tar.gz 61112274cace86c4... 84f4d4b75cf59793...
*-x86_64-linux-gnu-debug.tar.gz 557d05bc585a2910... a04a003417323042...
*-x86_64-linux-gnu.tar.gz 4928355769a494d7... d2f9940506b6b9ea...
*.tar.gz 49c2acd89613cf65... a6d1c45d0951e930...
guix_build.log 88d5371b29f8bb75... ecc9eeef1e0f8051...
guix_build.log.diff c47a48e33b450b28...

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

Successfully merging this pull request may close these issues.

None yet

6 participants