build: Try posix-specific CXX first for mingw32 host #22093

pull hebasto wants to merge 2 commits into bitcoin:master from hebasto:210528-posix changing 2 files +4 −31
  1. hebasto commented at 7:30 am on May 28, 2021: member

    On master (1186910b6b7ba7c7e5193c76f33f25825e6cc0b7), when cross-compiling for Windows using our depends build system, we must manually choose the POSIX thread model for the x86_64-w64-mingw32-g++ compiler.

    This PR improves the build system to make this choice automagically.

  2. hebasto added the label Docs on May 28, 2021
  3. hebasto added the label Windows on May 28, 2021
  4. hebasto added the label Build system on May 28, 2021
  5. hebasto commented at 7:31 am on May 28, 2021: member
  6. DrahtBot commented at 3:16 pm on May 28, 2021: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #22380 (build: add and use C_STANDARD and CXX_STANDARD in depends 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.

  7. jarolrod commented at 8:47 pm on May 28, 2021: member

    ACK 6f44c42e77c3dddd51a6f113163a168f60be9206

    I was able to build and run a cross-compiled windows executable after manually choosing the win32 CXX. Nice!

    Will close #22088 if this is merged.

  8. in depends/hosts/mingw32.mk:2 in 6f44c42e77 outdated
    0@@ -1,3 +1,7 @@
    1+ifneq ($(shell which $(host)-g++-posix),)
    2+mingw32_CXX := $(host)-g++-posix
    


    dongcarl commented at 9:01 pm on May 28, 2021:
    Do we need := here? Can we just do =?

    hebasto commented at 9:47 am on May 29, 2021:

    Do we need := here?

    No, we don’t.

    Can we just do =?

    Yes, we can.

    But I do prefer simply expanded make variables to recursively expanded ones. They make debugging and reasoning about Makefiles much easier. Actually, I think the choice of a simply expanded variable is the default, while the usage of a recursively expanded variable requires justification.

    In this particular case the host variable is simply expanded, and all code is placed in an included file. Honestly, I cannot see advantages for mingw32_CXX being a recursively expanded variable here.

    Or did I miss something?


    laanwj commented at 12:02 pm on August 2, 2021:
    I do not know enough of the make assignment semantics to weigh in here.
  9. MarcoFalke added the label Needs gitian build on May 31, 2021
  10. MarcoFalke added the label Needs Guix build on May 31, 2021
  11. build: Try posix-specific CXX first for mingw32 host f09ed92be1
  12. doc: Drop no longer required notes for Windows builds 2fda0c7851
  13. hebasto force-pushed on Jun 2, 2021
  14. hebasto commented at 3:08 pm on June 2, 2021: member
    Rebased 6f44c42e77c3dddd51a6f113163a168f60be9206 -> 2fda0c785188ae94fba921c1b8f6f2c005faf1d4 (pr22093.01 -> pr22093.02) due to the conflict with #22088.
  15. DrahtBot commented at 11:27 pm on June 2, 2021: member

    Gitian builds

    File commit 7e83e74e7fca7e1adee2174fee447a86af9bc68d(master) commit 82c7038faadece44a596dc4afbf03e853150f9b5(master and this pull)
    *-aarch64-linux-gnu-debug.tar.gz 3657abadb1a2ab5c... 43875e0baaa0a6a3...
    *-aarch64-linux-gnu.tar.gz 7fd67104fe882648... 5db302b62e883e10...
    *-arm-linux-gnueabihf-debug.tar.gz e864f6fcb3711448... ad91a96ab82c3e01...
    *-arm-linux-gnueabihf.tar.gz d54334cc945b689f... 0b05cac07255bba8...
    *-osx-unsigned.dmg 4be7f425ad28df9d... 4c0a2e7af3a729d5...
    *-osx64.tar.gz a19c21a64d040323... 76fd790cb73319a8...
    *-powerpc64-linux-gnu-debug.tar.gz 522f9e97292bd700... f61f3a4b4422576c...
    *-powerpc64-linux-gnu.tar.gz b55c2053ec4adbd7... c144e3daf42aebcd...
    *-powerpc64le-linux-gnu-debug.tar.gz 247fbf4c9dd24a8a... 372d8c465cc205c1...
    *-powerpc64le-linux-gnu.tar.gz f32e55973c5de857... b7ee180c23f2db00...
    *-riscv64-linux-gnu-debug.tar.gz 3b86b27a2c23349a... 9a689af3f6effb4c...
    *-riscv64-linux-gnu.tar.gz 9fa601963f7c4411... 7ee3a907059c90b2...
    *-win64-debug.zip eb8c5d461b0eeaee... fe2688ec93e7db88...
    *-win64-setup-unsigned.exe 95a0057c8a431946... e8124c9814a7dd25...
    *-win64.zip 94c351a21c99c7b0... ce31bdf3e5b48d36...
    *-x86_64-linux-gnu-debug.tar.gz c268d72417c37b51... a50ad9ca438989b6...
    *-x86_64-linux-gnu.tar.gz fa102d164ebdb62b... fc96a931dc22ad7b...
    *.tar.gz 64b0afb9f6181440... 45e67638c56dd0bc...
    bitcoin-core-linux-22-res.yml 0d8bb6a1b6d3ce1c... 6e82d6a0ed4130d8...
    bitcoin-core-osx-22-res.yml c8069c3eb3032cc5... 4247a3846acb97f0...
    bitcoin-core-win-22-res.yml 4c2fa3dd147e7647... a593bfef95823fdf...
    linux-build.log 9359c8c34c2224dd... 9823baf3313dfa10...
    osx-build.log 81ca2fbb8b66f3c0... cf8e3fa8c03ff69b...
    win-build.log eccf6426ec0a6d33... 3c40962fa70d9fbf...
    bitcoin-core-linux-22-res.yml.diff 972aa54f1bd0d26b...
    bitcoin-core-osx-22-res.yml.diff 98d67e1805d20b2f...
    bitcoin-core-win-22-res.yml.diff 1f43a4c847771ac2...
    linux-build.log.diff 7e943860942d3ccc...
    osx-build.log.diff 6ace9258d76b6729...
    win-build.log.diff 7449026fdc3ca8cd...
  16. DrahtBot removed the label Needs gitian build on Jun 2, 2021
  17. MarcoFalke added the label Needs gitian build on Jun 3, 2021
  18. jarolrod commented at 3:28 am on June 4, 2021: member

    re-ACK 2fda0c785188ae94fba921c1b8f6f2c005faf1d4

    I think it is better to automatically set this rather than have a user manually configure this. Tested on Ubuntu 20.04.

    Note that on another system where the mingw-cxx is not bundled with different versions like the ubuntu package is, such as Arch Linux, the following line will be in the depends output:

    0which: no x86_64-w64-mingw32-g++-posix in  ...
    

    Guix Hashes:

    0$ find guix-build-$(git rev-parse --short=12 HEAD)/output/ -type f -print0 | env LC_ALL=C sort -z | xargs -r0 sha256sum
    1
    2e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  guix-build-2fda0c785188/output/dist-archive/SKIPATTEST.TAG
    3129fe7c0234cf1e1d2b8c71dc36469a7dcb07e1a7c1806c547ecb29824a43c78  guix-build-2fda0c785188/output/dist-archive/bitcoin-2fda0c785188.tar.gz
    40e13399126a5acbc1ab62d32700dd37ae7a43490c0ef74aa35d347bb9e1dadb9  guix-build-2fda0c785188/output/x86_64-w64-mingw32/bitcoin-2fda0c785188-win-unsigned.tar.gz
    55d0468c34d947251e472ac9bf6182d9bb1a48be16c1d8fe48ad6f6ed423f87b3  guix-build-2fda0c785188/output/x86_64-w64-mingw32/bitcoin-2fda0c785188-win64-debug.zip
    6d757fa29ae8e7ee6ba709efca19549a9837df4173633c3b9fbf1753b156cd29a  guix-build-2fda0c785188/output/x86_64-w64-mingw32/bitcoin-2fda0c785188-win64-setup-unsigned.exe
    749057728c99484ca7b96727183a368ea5ffd0b8f58e2d51e806c17946ba8caf4  guix-build-2fda0c785188/output/x86_64-w64-mingw32/bitcoin-2fda0c785188-win64.zip
    810e3dda06008af8c7db65f1ee4d943df7f6f5138d35eaa3931676ed25648fcf5  guix-build-2fda0c785188/output/x86_64-w64-mingw32/inputs.SHA256SUMS
    
  19. DrahtBot commented at 9:41 pm on June 4, 2021: member

    Guix builds

    File commit 8837f1ebde0537b0fdfa1353d06ae8e61a259982(master) commit f073168efc654ebfc3c93cc2295b56301b68a33a(master and this pull)
    SKIPATTEST.TAG e3b0c44298fc1c14... e3b0c44298fc1c14...
    *-aarch64-linux-gnu-debug.tar.gz df038f5ab2665fe5... ecbbc4505b304b78...
    *-aarch64-linux-gnu.tar.gz c4ae196f5bac31ca... b637e110c18a2a66...
    *-arm-linux-gnueabihf-debug.tar.gz b1a4c77e17038f80... dd3e69f9ec4b016f...
    *-arm-linux-gnueabihf.tar.gz 5f0f6567b59c05bd... 5fb1d5d5224ed191...
    *-osx-unsigned.dmg 54454da4ceccc860... a97957718e70f60d...
    *-osx-unsigned.tar.gz ee82525cbc961783... 13fa91d5514715cd...
    *-osx64.tar.gz 0174c53f25343239... 8ad050cef604a82e...
    *-powerpc64-linux-gnu-debug.tar.gz 535ff47f4b1a8c2c... 2a2cb99c9eb40e88...
    *-powerpc64-linux-gnu.tar.gz 51206e2a4b195ca9... a7d3cdd056685024...
    *-powerpc64le-linux-gnu-debug.tar.gz 51c11da589995f6e... fc5568002e8f81ee...
    *-powerpc64le-linux-gnu.tar.gz c331e0684cb238fb... 0a45be70abadff8c...
    *-riscv64-linux-gnu-debug.tar.gz 3e9b290a27c78610... 653d45b39081353e...
    *-riscv64-linux-gnu.tar.gz 423c770209d61098... 88edb4022e5a28a0...
    *-win-unsigned.tar.gz 5fd055634a7437bc... 7ecdcb9467ed11ba...
    *-win64-debug.zip 37c6d1ac3c276a9e... 966c490e40c505fa...
    *-win64-setup-unsigned.exe 3ae9a4aea85ca4c1... 26da905e734c0f23...
    *-win64.zip 5dab283a0eb0eeae... 45281f9a590d34f2...
    *-x86_64-linux-gnu-debug.tar.gz 1ad9e69fba985f11... 83c24f6ce9b82209...
    *-x86_64-linux-gnu.tar.gz f8f58188918d5e0d... 65403b96c28f0ef3...
    *.tar.gz 5103b5d6130fbe1e... c92f1b2da7a306ab...
    guix_build.log c4cd6b445cdcce18... aa0f6055d6b2e4d8...
    inputs.SHA256SUMS 2a4cdf7202c23024... 78d4e7e7306bc60b...
    guix_build.log.diff c5b73b9c98338635...
  20. DrahtBot removed the label Needs Guix build on Jun 4, 2021
  21. DrahtBot commented at 4:20 am on June 6, 2021: member

    Gitian builds

    File commit 346e52afd6d5e317c96fc506bb54cde13e87c8b2(master) commit 267048ce988822e775e6b465e2ed4562bcdeeceb(master and this pull)
    *-aarch64-linux-gnu-debug.tar.gz 438c3423dfc3ae3e... c7f660a04153e0a8...
    *-aarch64-linux-gnu.tar.gz d0043e104d8f1e14... 00539e329713c25f...
    *-arm-linux-gnueabihf-debug.tar.gz 0ca83d45d0f31868... db41a51c1dce7b2b...
    *-arm-linux-gnueabihf.tar.gz 271fbf401101b4bf... d92d87e477b9482d...
    *-osx-unsigned.dmg e9272207d04aed41... e5e15345caa6ff65...
    *-osx64.tar.gz ed1917ef6d128bdb... 82ff42bb3d2e2633...
    *-powerpc64-linux-gnu-debug.tar.gz 489428a7bad74864... d84bd8dd741e5046...
    *-powerpc64-linux-gnu.tar.gz fe91a33579431a20... 83f31b222fe347a5...
    *-powerpc64le-linux-gnu-debug.tar.gz fd87159e48c97f5c... 08400415351df4ee...
    *-powerpc64le-linux-gnu.tar.gz fdc67310c7ecca3e... ce3a168af7d8f5dc...
    *-riscv64-linux-gnu-debug.tar.gz ccac591e4a485626... 76a41d485c3e1695...
    *-riscv64-linux-gnu.tar.gz a9c23bd42b8b3aff... 6334921fb7a29ec7...
    *-win64-debug.zip e6f3dfbd9c0ffceb... e3f65f90e7ca2d1a...
    *-win64-setup-unsigned.exe aa0abbc5e14530bf... d0f5703bac4dfeec...
    *-win64.zip 80bde49fb3c3de96... dec712012bc3d8e0...
    *-x86_64-linux-gnu-debug.tar.gz 43827d1c4ed174fc... 36c595484e2b3ce7...
    *-x86_64-linux-gnu.tar.gz 6042138716248662... 8ea0927f1d50ba91...
    *.tar.gz 37186ffcfb22d83a... 08472ff1085f6b9e...
    bitcoin-core-linux-22-res.yml 00ac34baa788ab2b... ca8aa0c2896b9142...
    bitcoin-core-osx-22-res.yml 68d7f6074e044140... bb6d43050f807bcb...
    bitcoin-core-win-22-res.yml aff4edd53a201a10... f267862eefa80fa4...
    linux-build.log fe69c5b5f20bbcb9... 59346e51ce2c34c0...
    osx-build.log 7afab84aa251675f... 585c8946c8ad5be8...
    win-build.log 7a885a1c8f6f6729... eaac43b4037bd1f8...
    bitcoin-core-linux-22-res.yml.diff b393cc0ec939c1ab...
    bitcoin-core-osx-22-res.yml.diff b5d4ec3b68342fc7...
    bitcoin-core-win-22-res.yml.diff 93a4f9c28087dbb4...
    linux-build.log.diff 18933c57c3f89f89...
    osx-build.log.diff ac20b219e40e42fa...
    win-build.log.diff 150aaeb13814739c...
  22. DrahtBot removed the label Needs gitian build on Jun 6, 2021
  23. laanwj commented at 11:57 am on August 2, 2021: member

    I wonder if the mingw developers plan on supporting the C++ threading stuff in the -win32 variant (this is the only reason we require -posix). There is no inherent reason not to, for example MSVC can do C++ threading without explicit POSIX compatibility. But it might be a lot of work for some other reason.

    That said, this makes sense for now. Concept ACK.

  24. in doc/build-windows.md:82 in 2fda0c7851
    80@@ -81,27 +81,6 @@ The first step is to install the mingw-w64 cross-compilation tool chain:
    81 
    82     sudo apt install g++-mingw-w64-x86-64
    


    laanwj commented at 11:59 am on August 2, 2021:
    This always installs both variants?

    laanwj commented at 12:01 pm on August 2, 2021:

    Apparently yes: https://packages.ubuntu.com/hirsute/g++-mingw-w64-x86-64

    g++-mingw-w64-x86-64 is an umbrella package that depends on g++-mingw-w64-x86-64-posix and g++-mingw-w64-x86-64-win32. It does not contain any compiler itself, just some documentation files.

  25. shaavan commented at 7:47 pm on August 5, 2021: contributor

    tACK 2fda0c785188ae94fba921c1b8f6f2c005faf1d4

    Tested on Ubuntu 20.04

    This PR adds functionality to automatically select the POSIX model for cross-compilation of Windows bitcoin-core on Ubuntu. It is achieved by modifying mingw32.mk file so that if the POSIX thread model is present in the system, then declare ming32_CXX variable using Simply Expanded Variable declaration and equals it to the POSIX model’s location.

    Tested the PR by first selecting the POSIX model, and trying to cross-compile the PR. And then cross-compiling the PR again while setting a non-POSIX(win32) model. I was able to successfully cross-compile the PR in both cases.

    On master: The cross-compilation was successful when the POSIX model was selected but failed when (win32) model was selected.

    Error message while using (win32) model:

    0make[2]: *** [Makefile:10778: qt/libbitcoinqt_a-bitcoin.o] Error 1
    1make[2]: Leaving directory '/home/shaman/Documents/summerofbitcoin/window_cross/bitcoin/src'
    2make[1]: *** [Makefile:16271: all-recursive] Error 1
    3make[1]: Leaving directory '/home/shaman/Documents/summerofbitcoin/window_cross/bitcoin/src'
    4make: *** [Makefile:823: all-recursive] Error 1
    

    On PR: The cross-compilation was successful in both cases when the POSIX model was selected, and when the non-POSIX (win32) model was selected.

    I agree with the changes suggested by op. These changes will lead to successful cross-compilation of bitcoin-core, even when the POSIX thread model is not selected. I think this particular change will help in two cases:

    1. Ease the windows cross-compilation process on Ubuntu a little bit easier.
    2. If the user is using some other software that requires win32 based thread model (non-POSIX model) for their working, they need not have to worry about changing the thread model, each time they cross-compile bitcoin-core.
  26. laanwj merged this on Jan 7, 2022
  27. laanwj closed this on Jan 7, 2022

  28. hebasto deleted the branch on Jan 9, 2022
  29. sidhujag referenced this in commit 6ef44bf5b4 on Jan 9, 2022
  30. hebasto commented at 12:26 pm on January 23, 2022: member

    My apologies about this.

    While this PR worked with Qt 5.12.11, it got broken with Qt 5.15.2.

    Even though the correct compiler has been chosen

    0$ make -j 9 -C depends --no-print-directory print-qt_cxx HOST=x86_64-w64-mingw32
    1qt_cxx=x86_64-w64-mingw32-g++-posix
    

    it appears that without update-alternatives step (i.e., -win32 has been chosen manually or by default) make -C depends qt HOST=x86_64-w64-mingw32 fails with error: ‘mutex’ in namespace ‘std’ does not name a type :man_facepalming:

    Our CI task passes due to https://github.com/bitcoin/bitcoin/blob/6d859cbd794a36ed1c0c72324a4ec54d029b3d3b/ci/test/05_before_script.sh#L46-L48

    I have no explanation for now, but this PR must be reverted.


    Apparently yes: https://packages.ubuntu.com/hirsute/g++-mingw-w64-x86-64

    g++-mingw-w64-x86-64 is an umbrella package that depends on g++-mingw-w64-x86-64-posix and g++-mingw-w64-x86-64-win32. It does not contain any compiler itself, just some documentation files.

    This is not the case for bionic or focal. But for hirsute, impish and jammy, if g++-mingw-w64-x86-64-posix has been installed but not g++-mingw-w64-x86-64-win32 this PR works again.


    cc @laanwj @dongcarl @jarolrod @shaavan


    UPDATE: Another possible solution:

    0--- a/depends/packages/qt.mk
    1+++ b/depends/packages/qt.mk
    2@@ -158,6 +158,7 @@ $(package)_config_opts_mingw32 += -no-dbus
    3 $(package)_config_opts_mingw32 += -no-freetype
    4 $(package)_config_opts_mingw32 += -xplatform win32-g++
    5 $(package)_config_opts_mingw32 += "QMAKE_CFLAGS = '$($(package)_cflags) $($(package)_cppflags)'"
    6+$(package)_config_opts_mingw32 += "QMAKE_CXX = '$($(package)_cxx)'"
    7 $(package)_config_opts_mingw32 += "QMAKE_CXXFLAGS = '$($(package)_cflags) $($(package)_cppflags)'"
    8 $(package)_config_opts_mingw32 += "QMAKE_LFLAGS = '$($(package)_ldflags)'"
    9 $(package)_config_opts_mingw32 += -device-option CROSS_COMPILE="$(host)-"
    

    UPDATE 2: A fix suggested in #24131.

  31. fanquake referenced this in commit c194293883 on Feb 3, 2022
  32. sidhujag referenced this in commit 531ea19dfd on Feb 3, 2022
  33. DrahtBot locked this on Jan 23, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-09-29 01:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me