fix(CPP): fix linux compiling issues

Fix BigInt compilation on linux
Remove c++20 optimization for NamedType
Add assert for failing getChats that was providing an easy to miss warning
Enable linux CI build
Don't run tests. They fail to run in docker with
 "malloc_consolidate(): invalid chunk size", probably due to status-go
This commit is contained in:
Stefan 2022-08-10 12:08:21 +02:00 committed by Stefan Dunca
parent 29c40a0695
commit cfef7dc443
9 changed files with 60 additions and 26 deletions

View File

@ -39,20 +39,6 @@ Platform specific conan profile
Update `CMake` to the [Latest Release](https://cmake.org/download/) or use the Qt's "$QTBASE/Tools/CMake/..." Update `CMake` to the [Latest Release](https://cmake.org/download/) or use the Qt's "$QTBASE/Tools/CMake/..."
### Build with conan
```bash
# linux
CMAKE_PREFIX_PATH="$HOME/Qt/6.3.2/gcc_64" conan build . -if=build/conan -bf=build
# MacOS: CMAKE_PREFIX_PATH="$HOME/Qt/6.3.2/macos" conan build . -if=build/conan -bf=build
# Windows: CMAKE_PREFIX_PATH="$HOME/Qt/6.3.2/mingw_64" conan build . -if=build/conan -bf=build
ctest -VV -C Release
./status-desktop
```
### Build with cmake ### Build with cmake
```bash ```bash
@ -71,3 +57,14 @@ cmake --build build
```bash ```bash
ctest --test-dir ./build ctest --test-dir ./build
``` ```
### Build with QtCreator
If go is installed with brew use the following configuration otherwise adapt the configuration.
Go to QtCreator's preferences navigate to Environment -> System -> Environment -> Change and paste
```ini
GOBIN=${GOPATH}/bin
GOPATH=${HOME}/go
PATH=${PATH}:${GOBIN}:/opt/homebrew/bin:/opt/homebrew/sbin
```

View File

@ -7,7 +7,7 @@ Item {
property alias enableHideWindow: hideWindowShortcut.enabled property alias enableHideWindow: hideWindowShortcut.enabled
Shortcut { Shortcut {
sequence: StandardKey.FullScreen sequences: [StandardKey.FullScreen]
onActivated: { onActivated: {
if (visibility === Window.FullScreen) if (visibility === Window.FullScreen)
window.showNormal() window.showNormal()

View File

@ -45,10 +45,17 @@ pipeline {
steps { steps {
sh "conan install ${env.WORKSPACE}/ --profile=${env.WORKSPACE}/vendor/conan-configs/linux.ini -s build_type=Release --build=missing -if=${env.WORKSPACE}/build/conan -of=${env.WORKSPACE}/build" sh "conan install ${env.WORKSPACE}/ --profile=${env.WORKSPACE}/vendor/conan-configs/linux.ini -s build_type=Release --build=missing -if=${env.WORKSPACE}/build/conan -of=${env.WORKSPACE}/build"
// TODO: This fails compiling status-go with Jenkins user but not when run with docker's user. Fix go installation to work for all users or build docker with jenkin's // TODO: This fails compiling status-go with Jenkins user but not when run with docker's user. Fix go installation to work for all users or build docker with jenkin's
sh "conan build ${env.WORKSPACE} --build-folder=${env.WORKSPACE}/build/conan" sh "CC=gcc-10 CXX=g++-10 qt-cmake ${env.WORKSPACE}/ -G Ninja -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${env.WORKSPACE}/build/conan/conan_toolchain.cmake"
sh "cmake --build ${env.WORKSPACE}/build"
} }
} }
// stage('Run Tests') {
// steps {
// sh "CTEST_OUTPUT_ON_FAILURE=1 QT_QPA_PLATFORM=offscreen ctest --test-dir ${env.WORKSPACE}/build"
// }
// }
stage('Package') { stage('Package') {
steps { steps {
sh "linuxdeploy --plugin qt --executable=${env.WORKSPACE}/build/status-desktop --appdir ${env.WORKSPACE}/build/AppDir --desktop-file=${env.WORKSPACE}/status.desktop --icon-file=${env.WORKSPACE}/status.svg --custom-apprun=${env.WORKSPACE}/AppRun-cpp" sh "linuxdeploy --plugin qt --executable=${env.WORKSPACE}/build/status-desktop --appdir ${env.WORKSPACE}/build/AppDir --desktop-file=${env.WORKSPACE}/status.desktop --icon-file=${env.WORKSPACE}/status.svg --custom-apprun=${env.WORKSPACE}/AppRun-cpp"

View File

@ -2,10 +2,27 @@ FROM stateoftheartio/qt6:6.3-gcc-aqt
RUN export DEBIAN_FRONTEND=noninteractive \ RUN export DEBIAN_FRONTEND=noninteractive \
&& sudo apt update -yq \ && sudo apt update -yq \
&& sudo apt install -yq libgl-dev libvulkan-dev libxcb*-dev libxkbcommon-x11-dev python3-pip gcc-10 golang-go && sudo apt install -yq libgl-dev libvulkan-dev libxcb*-dev libxkbcommon-x11-dev python3-pip gcc-10 golang-go wget
RUN sudo pip install conan RUN sudo pip install conan
# Installing Golang
RUN GOLANG_SHA256="9e5de37f9c49942c601b191ac5fba404b868bfc21d446d6960acc12283d6e5f2" \
&& GOLANG_TARBALL="go1.18.5.linux-amd64.tar.gz" \
&& wget -q "https://dl.google.com/go/${GOLANG_TARBALL}" \
&& echo "${GOLANG_SHA256} ${GOLANG_TARBALL}" | sha256sum -c \
&& sudo tar -C /usr/local -xzf "${GOLANG_TARBALL}" \
&& rm "${GOLANG_TARBALL}" \
&& sudo ln -s /usr/local/go/bin/go /usr/local/bin
RUN sudo apt install -yq g++-10
# Jenkins user needs a specific UID/GID to work
RUN sudo groupadd -g 1001 jenkins \
&& sudo useradd --create-home -u 1001 -g 1001 jenkins
USER jenkins
ENV HOME="/home/jenkins"
# TODO finish installing dependencies then enable building the appimage in CI # TODO finish installing dependencies then enable building the appimage in CI
# RUN cd /tmp && git clone --single-branch --recursive https://github.com/AppImage/AppImageKit && cd AppImageKit/ && cmake -B ./build -S . # RUN cd /tmp && git clone --single-branch --recursive https://github.com/AppImage/AppImageKit && cd AppImageKit/ && cmake -B ./build -S .
# If still needed # If still needed

View File

@ -11,6 +11,7 @@ ChatSectionController::ChatSectionController()
void ChatSectionController::init(const QString& sectionId) void ChatSectionController::init(const QString& sectionId)
{ {
auto chatSectionData = m_dataProvider->getSectionData(sectionId); auto chatSectionData = m_dataProvider->getSectionData(sectionId);
assert(chatSectionData.chats.size() > 0);
std::vector<ChatItemPtr> model; std::vector<ChatItemPtr> model;
for (auto c : chatSectionData.chats) { for (auto c : chatSectionData.chats) {
model.push_back(std::make_shared<ChatItem>(std::move(c))); model.push_back(std::make_shared<ChatItem>(std::move(c)));

View File

@ -4,7 +4,6 @@
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
#include <compare>
using json = nlohmann::json; using json = nlohmann::json;
@ -33,18 +32,12 @@ public:
return m_value; return m_value;
} }
#if defined __cpp_impl_three_way_comparison && defined __cpp_lib_three_way_comparison
friend auto operator<=>(const NamedType<T, Parameter>& l, const NamedType<T, Parameter>& r) noexcept {
return l.m_value <=> r.m_value;
};
#else
bool operator<(const NamedType<T, Parameter> &other) const { return m_value < other.m_value; }; bool operator<(const NamedType<T, Parameter> &other) const { return m_value < other.m_value; };
bool operator>(const NamedType<T, Parameter> &other) const { return m_value > other.m_value; }; bool operator>(const NamedType<T, Parameter> &other) const { return m_value > other.m_value; };
bool operator<=(const NamedType<T, Parameter> &other) const { return m_value <= other.m_value; }; bool operator<=(const NamedType<T, Parameter> &other) const { return m_value <= other.m_value; };
bool operator>=(const NamedType<T, Parameter> &other) const { return m_value >= other.m_value; }; bool operator>=(const NamedType<T, Parameter> &other) const { return m_value >= other.m_value; };
bool operator==(const NamedType<T, Parameter> &other) const { return m_value == other.m_value; }; bool operator==(const NamedType<T, Parameter> &other) const { return m_value == other.m_value; };
bool operator!=(const NamedType<T, Parameter> &other) const { return m_value != other.m_value; }; bool operator!=(const NamedType<T, Parameter> &other) const { return m_value != other.m_value; };
#endif
T &operator=(NamedType<T, Parameter> const& rhs) { T &operator=(NamedType<T, Parameter> const& rhs) {
return m_value = rhs.m_value; return m_value = rhs.m_value;

View File

@ -38,6 +38,7 @@ QVariant UserAccountsModel::data(const QModelIndex& index, int role) const
switch(static_cast<ModelRole>(role)) { switch(static_cast<ModelRole>(role)) {
case Name: return QVariant::fromValue(m_accounts[index.row()].get()->name()); case Name: return QVariant::fromValue(m_accounts[index.row()].get()->name());
case Account: return QVariant::fromValue<QObject*>(m_accounts[index.row()].get()); case Account: return QVariant::fromValue<QObject*>(m_accounts[index.row()].get());
default: return QVariant();
} }
} }

View File

@ -64,9 +64,27 @@ add_custom_command(
install( install(
IMPORTED_RUNTIME_ARTIFACTS IMPORTED_RUNTIME_ARTIFACTS
statusgo_shared statusgo_shared
) )
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_custom_command(
TARGET
${PROJECT_NAME}
POST_BUILD
# Workaround, status-go CMakeLists.txt should set the correct TARGET_SONAME_FILE
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_SONAME_FILE:statusgo_shared>/libstatus.so.0
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
COMMENT "Copying status-go libstatus.so.0 lib beside project executable"
)
install(
FILES
$<TARGET_SONAME_FILE:statusgo_shared>/libstatus.so.0
TYPE LIB
)
endif()
target_sources(${PROJECT_NAME} target_sources(${PROJECT_NAME}
PRIVATE PRIVATE
src/StatusGo/General.h src/StatusGo/General.h

View File

@ -10,7 +10,7 @@ namespace StatusGo::Wallet {
std::string toHexData(const BigInt &num, bool uppercase) std::string toHexData(const BigInt &num, bool uppercase)
{ {
return num.str(0, std::ios_base::showbase | std::ios_base::hex | (uppercase ? std::ios_base::uppercase : 0)); return num.str(0, std::ios_base::showbase | std::ios_base::hex | (uppercase ? std::ios_base::uppercase : std::ios_base::fmtflags(0)));
} }