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

Add support for clang-cl (fixes #84) #86

Merged
merged 7 commits into from
Jun 24, 2022
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
42 changes: 26 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ jobs:
QT_VERSION_MAJOR=$(echo ${{ matrix.qt_version }} | cut -d'.' -f1)

if [[ "${{ matrix.platform }}" != "windows" ]]; then
# Don't built QCoro as .dlls on Windows - making it work with ASAN on Github CI
# is major PITA...
# Don't fiddle with dlls in Windows, it makes things complicated...
EXTRA_CMAKE_FLAGS="${EXTRA_CMAKE_FLAGS} -DBUILD_SHARED_LIBS=ON"
fi
if [[ "${{ matrix.platform }}" == "windows" && "${QT_VERSION_MAJOR}" == "5" ]]; then
EXTRA_CMAKE_FLAGS="${EXTRA_CMAKE_FLAGS} -DQCORO_ENABLE_ASAN=OFF"
else
if [[ "${{ matrix.compiler }}" == "clang-cl" ]]; then
# FIXME: allow ASAN with clang-cl
EXTRA_CMAKE_FLAGS="${EXTRA_CMAKE_FLAGS} -T ClangCL -DQCORO_ENABLE_ASAN=OFF"
fi
if [[ "${QT_VERSION_MAJOR}" == "5" ]]; then
EXTRA_CMAKE_FLAGS="${EXTRA_CMAKE_FLAGS} -DQCORO_ENABLE_ASAN=OFF"
fi
fi

cmake $GITHUB_WORKSPACE \
Expand All @@ -84,18 +88,24 @@ jobs:

- name: Add ASAN DLL directory to PATH
if: ${{ matrix.platform == 'windows' }}
shell: cmd
shell: pwsh
run: |
setlocal enabledelayedexpansion
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (set InstallDir=%%i)
if exist "%InstallDir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" (
set /p Version=<"%InstallDir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"
set Version=!Version: =!
)
if not "%Version%" == "" (
set /p="%InstallDir%\VC\Tools\MSVC\%Version%\bin\HostX64\x64" < nul > %GITHUB_PATH%
exit 0
)
$installDir=(& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath)
echo "Detected MSVC install dir: \"${installDir}\""
if ("${{ matrix.compiler}}" -eq "msvc") {
if (Test-Path -Path "${installDir}\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt") {
$vctoolsVersion=(Get-Content -Path "${installDir}\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt")
echo "Detected VCTools version: ${vctoolsVersion}"
} else {
echo "Failed to detect MSVC version"
exit 1
}
"${installDir}\VC\Tools\MSVC\${vctoolsVersion}\bin\HostX64\x64" >> $env:GITHUB_PATH
} else {
$clangVersion=((& "${installDir}\VC\Tools\Llvm\x64\bin\clang.exe" --version) | Select-String -Pattern "\d+.\d+.\d+" | % { $_.Matches } | % { $_.Value })
echo "Detected clang version: ${clangVersion}"
"${installDir}\VC\Tools\Llvm\x64\lib\clang\${clangVersion}\lib\windows" >> $env:GITHUB_PATH
}

- name: Build
shell: bash
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/generate-matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
platforms = [
{
"name": "windows",
"compilers": [{ "name": "msvc" }]
"compilers": [
{ "name": "msvc" },
{ "name": "clang-cl" }
]
},
{
"name": "macos",
Expand Down
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ endif()

if (QCORO_ENABLE_ASAN)
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /INCREMENTAL:NO")
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fsanitize=address")
endif()
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
endif()
Expand Down
7 changes: 7 additions & 0 deletions examples/network/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
#include "qcoro/qcorotask.h"

#include <QApplication>
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-enum-enum-conversion" // QSizePolicy seems problematic...
#endif // __clang__
#include <QBoxLayout>
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
#include <QMainWindow>
#include <QMessageBox>
#include <QNetworkAccessManager>
Expand Down
8 changes: 6 additions & 2 deletions qcoro/QCoroMacros.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
macro(qcoro_enable_coroutines)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # GCC
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines-ts")
if (MSVC)
# clang-cl behaves like MSVC and enables coroutines automatically when C++20 is enabled
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines-ts")
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# MSVC auto-enables coroutine support when C++20 is enabled
else()
Expand Down
37 changes: 19 additions & 18 deletions qcoro/qcoroasyncgenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,25 @@ class AsyncGeneratorIterator final
{
using promise_type = detail::AsyncGeneratorPromise<T>;
using handle_type = std::coroutine_handle<promise_type>;

class IncrementIteratorAwaitable final : public detail::IteratorAwaitableBase {
public:
explicit IncrementIteratorAwaitable(AsyncGeneratorIterator &iterator) noexcept
: detail::IteratorAwaitableBase(iterator.m_coroutine.promise(), iterator.m_coroutine),
m_iterator(iterator) {}

AsyncGeneratorIterator<T> &await_resume() {
if (m_promise->finished()) {
m_iterator = AsyncGeneratorIterator<T>{nullptr};
m_promise->rethrow_if_unhandled_exception();
}
return m_iterator;
}

private:
AsyncGeneratorIterator<T> &m_iterator;
};

public:
using iterator_category = std::input_iterator_tag;
// Not sure what type should be used for difference_type as we don't
Expand All @@ -189,24 +208,6 @@ class AsyncGeneratorIterator final
{}

auto operator++() noexcept {
class IncrementIteratorAwaitable final : public detail::IteratorAwaitableBase {
public:
explicit IncrementIteratorAwaitable(AsyncGeneratorIterator &iterator) noexcept
: detail::IteratorAwaitableBase(iterator.m_coroutine.promise(), iterator.m_coroutine)
, m_iterator(iterator)
{}

AsyncGeneratorIterator<T> &await_resume() {
if (m_promise->finished()) {
m_iterator = AsyncGeneratorIterator<T>{nullptr};
m_promise->rethrow_if_unhandled_exception();
}
return m_iterator;
}
private:
AsyncGeneratorIterator<T> &m_iterator;
};

return IncrementIteratorAwaitable{*this};
}

Expand Down
2 changes: 1 addition & 1 deletion tests/qcorogenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private Q_SLOTS:
values.emplace_back(*it);
}

QCOMPARE(values.size(), 10);
QCOMPARE(values.size(), 10U);
QCOMPARE(values, (std::vector<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}));
}

Expand Down