Skip to content

Conversation

@hebasto
Copy link
Member

@hebasto hebasto commented May 28, 2021

On master (1186910), 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.

@hebasto
Copy link
Member Author

hebasto commented May 28, 2021

cc @dongcarl @jarolrod

@DrahtBot
Copy link
Contributor

DrahtBot commented May 28, 2021

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.

Copy link
Contributor

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

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

ACK 6f44c42

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.

@@ -1,3 +1,7 @@
ifneq ($(shell which $(host)-g++-posix),)
mingw32_CXX := $(host)-g++-posix
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need := here? Can we just do =?

Copy link
Member Author

Choose a reason for hiding this comment

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

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?

Copy link
Member

Choose a reason for hiding this comment

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

I do not know enough of the make assignment semantics to weigh in here.

@hebasto
Copy link
Member Author

hebasto commented Jun 2, 2021

Rebased 6f44c42 -> 2fda0c7 (pr22093.01 -> pr22093.02) due to the conflict with #22088.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 2, 2021

Gitian builds

File commit 7e83e74
(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...

Copy link
Contributor

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

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

re-ACK 2fda0c7

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:

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

Guix Hashes:

$ find guix-build-$(git rev-parse --short=12 HEAD)/output/ -type f -print0 | env LC_ALL=C sort -z | xargs -r0 sha256sum

e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  guix-build-2fda0c785188/output/dist-archive/SKIPATTEST.TAG
129fe7c0234cf1e1d2b8c71dc36469a7dcb07e1a7c1806c547ecb29824a43c78  guix-build-2fda0c785188/output/dist-archive/bitcoin-2fda0c785188.tar.gz
0e13399126a5acbc1ab62d32700dd37ae7a43490c0ef74aa35d347bb9e1dadb9  guix-build-2fda0c785188/output/x86_64-w64-mingw32/bitcoin-2fda0c785188-win-unsigned.tar.gz
5d0468c34d947251e472ac9bf6182d9bb1a48be16c1d8fe48ad6f6ed423f87b3  guix-build-2fda0c785188/output/x86_64-w64-mingw32/bitcoin-2fda0c785188-win64-debug.zip
d757fa29ae8e7ee6ba709efca19549a9837df4173633c3b9fbf1753b156cd29a  guix-build-2fda0c785188/output/x86_64-w64-mingw32/bitcoin-2fda0c785188-win64-setup-unsigned.exe
49057728c99484ca7b96727183a368ea5ffd0b8f58e2d51e806c17946ba8caf4  guix-build-2fda0c785188/output/x86_64-w64-mingw32/bitcoin-2fda0c785188-win64.zip
10e3dda06008af8c7db65f1ee4d943df7f6f5138d35eaa3931676ed25648fcf5  guix-build-2fda0c785188/output/x86_64-w64-mingw32/inputs.SHA256SUMS

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 4, 2021

Guix builds

File commit 8837f1e
(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...

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 6, 2021

Gitian builds

File commit 346e52a
(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...

@laanwj
Copy link
Member

laanwj commented Aug 2, 2021

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.


The first step is to install the mingw-w64 cross-compilation tool chain:

sudo apt install g++-mingw-w64-x86-64
Copy link
Member

Choose a reason for hiding this comment

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

This always installs both variants?

Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

@shaavan shaavan left a comment

Choose a reason for hiding this comment

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

tACK 2fda0c7

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:

make[2]: *** [Makefile:10778: qt/libbitcoinqt_a-bitcoin.o] Error 1
make[2]: Leaving directory '/home/shaman/Documents/summerofbitcoin/window_cross/bitcoin/src'
make[1]: *** [Makefile:16271: all-recursive] Error 1
make[1]: Leaving directory '/home/shaman/Documents/summerofbitcoin/window_cross/bitcoin/src'
make: *** [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.

@hebasto
Copy link
Member Author

hebasto commented Jan 23, 2022

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

$ make -j 9 -C depends --no-print-directory print-qt_cxx HOST=x86_64-w64-mingw32
qt_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 🤦‍♂️

Our CI task passes due to

if [[ $HOST = *-mingw32 ]]; then
DOCKER_EXEC update-alternatives --set "${HOST}-g++" \$\(which "${HOST}-g++-posix"\)
fi

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:

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

UPDATE 2: A fix suggested in #24131.

fanquake added a commit to bitcoin-core/gui that referenced this pull request Feb 3, 2022
…ith Qt 5.15

9796dca doc: Install only "-posix" MinGW compiler when possible (Hennadii Stepanov)
0bbae23 ci: Drop no longer needed `update-alternatives` (Hennadii Stepanov)
01d1845 build, qt: Specify QMAKE_CXX explicitly (Hennadii Stepanov)

Pull request description:

  While changes introduced in bitcoin/bitcoin#22093 worked fine with Qt 5.12, after bumping Qt up to 5.15 the cross-compiling of `qt` package for Windows fails with `error: ‘mutex’ in namespace ‘std’ does not name a type`.

  The first commit fixes this bug.

  The second commit cleans up a related CI script.

  The third commit improves related docs (see bitcoin/bitcoin#22093 (comment)).

ACKs for top commit:
  prusnak:
    ACK 9796dca

Tree-SHA512: 0dc46c5dfab85bd6d2901052cd630e86f9b4e09c08ef87136b44ddecb1783cdf3cd0a6e67b95ac7a78da24cd7adedc88745f61f9a8d9993fbff26d33bf88d874
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 3, 2022
9796dca doc: Install only "-posix" MinGW compiler when possible (Hennadii Stepanov)
0bbae23 ci: Drop no longer needed `update-alternatives` (Hennadii Stepanov)
01d1845 build, qt: Specify QMAKE_CXX explicitly (Hennadii Stepanov)

Pull request description:

  While changes introduced in bitcoin#22093 worked fine with Qt 5.12, after bumping Qt up to 5.15 the cross-compiling of `qt` package for Windows fails with `error: ‘mutex’ in namespace ‘std’ does not name a type`.

  The first commit fixes this bug.

  The second commit cleans up a related CI script.

  The third commit improves related docs (see bitcoin#22093 (comment)).

ACKs for top commit:
  prusnak:
    ACK 9796dca

Tree-SHA512: 0dc46c5dfab85bd6d2901052cd630e86f9b4e09c08ef87136b44ddecb1783cdf3cd0a6e67b95ac7a78da24cd7adedc88745f61f9a8d9993fbff26d33bf88d874
@bitcoin bitcoin locked and limited conversation to collaborators Jan 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants