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

Fix QML build regressions on macOS #13334

Merged
merged 8 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
-DMACOS_BUNDLE=ON
-DMODPLUG=ON
-DQT6=ON
-DQML=OFF
-DQML=ON
-DWAVPACK=ON
-DVCPKG_TARGET_TRIPLET=arm64-osx-min1100-release
-DVCPKG_DEFAULT_HOST_TRIPLET=x64-osx-min1100-release
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/rendering/controllerrenderingengine.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <GL/gl.h>

#include <QObject>
#include <QOpenGLContext>
#include <QOpenGLFramebufferObject>
#include <chrono>
#include <gsl/pointers>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
#include <QQuickWindow>
#include <QtEndian>
#include <algorithm>

// Prevent conflict with methods called 'emit' in <execution> source
#pragma push_macro("emit")
#undef emit
#include <execution>
#pragma pop_macro("emit")
#endif

#include "control/controlobject.h"
Expand Down Expand Up @@ -323,7 +317,7 @@ void ControllerScriptEngineLegacy::setScriptFiles(
m_scriptFiles = scripts;

#ifdef MIXXX_USE_QML
setQMLMode(std::any_of(std::execution::par_unseq,
setQMLMode(std::any_of(
m_scriptFiles.cbegin(),
m_scriptFiles.cend(),
[](const auto& scriptFileInfo) {
Expand Down Expand Up @@ -660,7 +654,9 @@ void ControllerScriptEngineLegacy::handleScreenFrame(
emit previewRenderedScreen(screenInfo, screenDebug);
}

QByteArray input(std::bit_cast<const char*>(frame.constBits()), frame.sizeInBytes());
// TODO: Refactor this to a `std::bit_cast` once we drop support for older
// compilers that don't support it (e.g. older than Xcode 14.3/macOS 13)
QByteArray input(reinterpret_cast<const char*>(frame.constBits()), frame.sizeInBytes());
Copy link
Member Author

Choose a reason for hiding this comment

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

From what I understand, casting between const char * and const unsigned char * using reinterpret_cast seems to be fine, stackoverflow confirms that. This would fix the build on some older compilers where std::bit_cast isn't available, such as the macOS 11 runners we are building on in CI.

Would appreciate a second pair of eyes checking that this is fine though.

Copy link
Member

Choose a reason for hiding this comment

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

AFAIR, this is what I was using, but I was requested to change it to bit_cast. Perhaps you could keep this cast specific to Mac?

Copy link
Member Author

@fwcd fwcd Jun 6, 2024

Choose a reason for hiding this comment

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

My gut feeling would be that it would be better not to have different code paths here to avoid introducing subtle semantic differences here. From what I understand the semantics shouldn't differ, but I think it would be better to hit a bug on all platforms rather than just one (that isn't as well-tested as e.g. Linux).

Perhaps a comment that this should be refactored to a std::bit_cast once we drop support for macOS 11 (or build on a newer runner)?

Copy link
Member

Choose a reason for hiding this comment

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

A comment sounds good yeah!

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps a comment that this should be refactored to a std::bit_cast once we drop support for macOS 11 (or build on a newer runner)?

is this specific to the build environment or to the runner? Cuz the runner was recently updated #13296.

Here's a little more context for reinterpret_cast vs std::bit_cast: https://stackoverflow.com/a/53402217

Copy link
Member Author

Choose a reason for hiding this comment

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

Should be specific to the compiler, i.e. the Xcode version that the runner uses. macOS 12 is two years old too, so my best guess would be that it doesn't support bit_cast either yet.

Copy link
Member

Choose a reason for hiding this comment

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

https://developer.apple.com/xcode/cpp/ says bit-casting requires XCode 14.3. Seems like that's only available on MacOS 13...

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah okay, thanks for checking. I think as long as we're building against an SDK older than that (in CI), we are going to get an error, regardless of whether we use a newer runner. I'll update the comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a neat site btw, have to bookmark that.

Copy link
Member

Choose a reason for hiding this comment

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

Even better: https://en.cppreference.com/w/cpp/compiler_support

Apparently they also track apple clang now, which they previously haven't which is why I defaulted to the apple site.

const TransformScreenFrameFunction& transformMethod =
m_transformScreenFrameFunctions[screenInfo.identifier];

Expand Down