Changes in Xcode 11 Objective-C Runtime cause an error (#16387) during building on MacOS 10.15 Catalina.
This PR fixes this issue by replacing objc_msgSend() function calls with the native Objective-C syntax.
Refs:
Changes in Xcode 11 Objective-C Runtime cause an error (#16387) during building on MacOS 10.15 Catalina.
This PR fixes this issue by replacing objc_msgSend() function calls with the native Objective-C syntax.
Refs:
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, this pull request conflicts with the following ones:
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.
I can confirm 77dabca still builds on macOS Mojave 10.14.6. It also fixes the build for me on macOS Catalina 10.15 beta 3.
Conversely you can reproduce the error in Mojave by setting -DOBJC_OLD_DISPATCH_PROTOTYPES=0.
I suggest tagging this 0.19, but hold off merging in favor of a solution that uses the new syntax. Apple deprecated this back in 2015.
I suggest tagging this 0.19, but hold off merging in favor of a solution that uses the new syntax. Apple deprecated this back in 2015.
Done, agree here.
I suggest tagging this 0.19, but hold off merging in favor of a solution that uses the new syntax.
Done with the native Objective-C syntax.
Nice! Will test soon. Maybe set -DOBJC_OLD_DISPATCH_PROTOTYPES=0 for good measure?
42 | @@ -44,3 +43,12 @@ void setupDockClickHandler() { 43 | { 44 | delete s_instance; 45 | } 46 | + 47 | +/** 48 | + * Force application activation on macOS. With Qt 5.4 this is required when
Given that we don't support Qt 5.4 anymore, can you update this comment? Obviously this workaround is still required with Qt 5.5+. Is there a Qt version where it's no-longer necessary?
That would indeed be useful to know. I didn't try removing the workaround altogether.
Is there a Qt version where it's no-longer necessary?
Looking through the Qt code base:
since Qt 5.3: https://github.com/qt/qtbase/blob/5.3/src/plugins/platforms/cocoa/qcocoaintegration.mm#L299
since Qt 5.6: https://github.com/qt/qtbase/blob/5.6/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm#L299
since Qt 5.8: https://github.com/qt/qtbase/blob/5.8/src/plugins/platforms/cocoa/qcocoawindow.mm#L1013
I suppose the workaround is not needed on Qt 5.6+. But I have no capabilities to test this hypothesis now.
I didn't try removing the workaround altogether.
I did. It works as expected on Catalina (Beta 3) + Qt 5.13.
Our minimum QT version is 5.5.1, so maybe we should make a Github issue to consider dropping this workaround at the next bump https://github.com/bitcoin/bitcoin/blob/master/doc/dependencies.md
Tested ACK f959d2f on Mojave and Catalina, using homebrew QT 5.13.0
57 | @@ -58,9 +58,10 @@ 58 | #pragma GCC diagnostic push 59 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 60 | 61 | -#include <objc/objc-runtime.h> 62 | #include <CoreServices/CoreServices.h> 63 | #include <QProcess> 64 | + 65 | +void ForceActivation();
Perhaps move the function declaration to macdockiconhandler.h and include this header instead?
What are benefits of doing that? A header including will increase the current translation unit, however.
When I noticed the function declaration it was not immediately obvious why the corresponding definition was not in the same cpp file. It was only obvious why it is as it is after I found the corresponding function definition in the mackdockiconhandler.mm file.
I thought that by declaring the function in the mackdockiconhandler.h header file and keeping the declaration and definition close to each other, it would save the next person from wondering the same.
But perhaps it just me. I am afraid I don't have a better argument.
19 | @@ -21,9 +20,9 @@ bool dockClickHandler(id self, SEL _cmd, ...) { 20 | } 21 | 22 | void setupDockClickHandler() { 23 | - id app = objc_msgSend((id)objc_getClass("NSApplication"), sel_registerName("sharedApplication")); 24 | - id delegate = objc_msgSend(app, sel_registerName("delegate")); 25 | - Class delClass = (Class)objc_msgSend(delegate, sel_registerName("class")); 26 | + id app = [NSApplication sharedApplication]; 27 | + id delegate = [app delegate]; 28 | + Class delClass = (Class)[delegate class];
Simplify id app = ...; id delegate = ...; Class delClass = ...; to Class delClass = [NSApplication.sharedApplication.delegate class];?
As dot notation is present in both C++ and Objective-C syntaxes, I'd prefer to keep the native Objective-C code as different from C++'s one as possible in mixed "Objective-C++" source files.
The suggestion to combine some statements into the single one will be implemented.
Concept ACK!
utACK 0bb33b5348dbddd65b88a7f00449c965562355d3 - Confirmed that the called macOS framework function is available on our build targets.
Travis error is irrelevant.
ACK 0bb33b5348dbddd65b88a7f00449c965562355d3 - Still works as expected.
ACK 0bb33b5 - Diff looks good. Sending messages via native Objective-C code feels more robust and is more readable than casting all the objc_msgSend function calls to the appropriate function signature (which would also have fixed the issue).
Milestone
0.19.0