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

Allow compilation with clang 13 and Libcpp #496

Merged
merged 12 commits into from
Oct 6, 2021
12 changes: 7 additions & 5 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ jobs:
strategy:
fail-fast: false
matrix:
compiler: [ g++-10, clang++-12 ]
compiler: [ gcc10, clang13 ]
os: [ ubuntu-latest ]
warnings: [ "", -Werror ]
exclude:
- compiler: g++-10
- compiler: gcc10
warnings: -Werror


Expand All @@ -33,8 +33,10 @@ jobs:

- name: Install dependencies
run: sudo apt-get install -y libicu-dev tzdata gcc-10 libzstd-dev libjemalloc-dev
- name: Install clang 12
run: wget https://apt.llvm.org/llvm.sh && sudo chmod +x llvm.sh && sudo ./llvm.sh 12
- name: Install clang 13
run: wget https://apt.llvm.org/llvm.sh && sudo chmod +x llvm.sh && sudo ./llvm.sh 13
- name: Install libc++-13
run : sudo apt install -y libunwind-13-dev libc++abi-13-dev libc++-13-dev

- name: Python dependencies
run: sudo apt-get install python3-yaml unzip pkg-config python3-icu
Expand All @@ -46,7 +48,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_COMPILER=${{matrix.compiler}} -DADDITIONAL_COMPILER_FLAGS=${{matrix.warnings}}
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=$(pwd)/toolchains/${{matrix.compiler}}.cmake -DADDITIONAL_COMPILER_FLAGS=${{matrix.warnings}}

- name: Build
# Build your program with the given configuration
Expand Down
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ if (USE_PARALLEL)
if (OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
add_definitions("-D_PARALLEL_SORT")
endif ()
endif()
Expand Down Expand Up @@ -159,6 +159,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")

set(RE2_BUILD_TESTING OFF CACHE BOOL "enable testing for RE2" FORCE)
add_subdirectory(third_party/re2 EXCLUDE_FROM_ALL)
target_compile_options(re2 PUBLIC -Wno-unused-but-set-variable)
include_directories(SYSTEM third_party/re2)

# reinstate original flags including all warnings
Expand Down Expand Up @@ -208,7 +209,7 @@ configure_file(src/web/script.js script.js)
add_executable(IndexBuilderMain src/index/IndexBuilderMain.cpp)
target_link_libraries(IndexBuilderMain index ${CMAKE_THREAD_LIBS_INIT})

add_executable(CreatePatternsMain src/index/CreatePatternsMain.cpp)
add_executable(CreatePatternsMain src/index/CreatePatternsMain.cpp src/util/jthread.h)
target_link_libraries(CreatePatternsMain index ${CMAKE_THREAD_LIBS_INIT})

add_executable(SparqlEngineMain src/SparqlEngineMain.cpp)
Expand Down
6 changes: 3 additions & 3 deletions src/parser/SparqlLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ void SparqlLexer::readNext() {
// unescaping of RDFLiteral, only applied to the actual literal and
// not the datatype/langtag
auto lastQuote = raw.rfind('"');
std::string_view quoted{raw.begin(), raw.begin() + lastQuote + 1};
std::string_view langtagOrDatatype{raw.begin() + lastQuote + 1,
raw.end()};
std::string_view quoted{raw.data(), lastQuote + 1};
std::string_view langtagOrDatatype{raw.data() + lastQuote + 1,
raw.size() - (lastQuote + 1)};
raw = RdfEscaping::normalizeRDFLiteral(quoted) + langtagOrDatatype;
}
break; // we check the regexes in an order that ensures that stopping
Expand Down
1 change: 1 addition & 0 deletions src/util/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef QLEVER_RANDOM_H
#define QLEVER_RANDOM_H

#include <array>
#include <cstring>
#include <random>
#include <type_traits>
Expand Down
1 change: 1 addition & 0 deletions src/util/Synchronized.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define QLEVER_SYNCHRONIZED_H

#include <atomic>
#include <condition_variable>
#include <shared_mutex>

#include "./OnDestruction.h"
Expand Down
3 changes: 2 additions & 1 deletion src/util/TaskQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "./Exception.h"
#include "./Timer.h"
#include "./jthread.h"

namespace ad_utility {
/**
Expand All @@ -27,7 +28,7 @@ class TaskQueue {
using Task = std::function<void()>;
using Timer = ad_utility::Timer;

std::vector<std::jthread> _threads;
std::vector<ad_utility::JThread> _threads;
std::queue<Task> _queuedTasks;
size_t _queueMaxSize = 1;
// CV to notify that a new task has been added to the queue
Expand Down
45 changes: 45 additions & 0 deletions src/util/jthread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Created by projector-user on 10/6/21.
//

#ifndef QLEVER_JTHREAD_H

#include <thread>
#include <version>

// While libc++ has no std::jthread, we ship our own
#ifdef _LIBCPP_VERSION
namespace ad_utility {
struct JThread : public std::thread {
#ifdef __cpp_lib_jthread
static_assert(false,
"std::jthread is now supported by libc++, get rid of "
"ad_utility::Jthread");
#endif
using Base = std::thread;
using Base::Base;
JThread(JThread&&) noexcept = default;
~JThread() {
if (joinable()) {
join();
}
}
};
} // namespace ad_utility

#else
// libstdc++ already supports jthread, simply use it
#ifndef __cpp_lib_jthread
static_assert(false,
"std::jthread is not supported by the version of libstdc++ you "
"are using, please update or using QLever inside of Docker");
#endif
namespace ad_utility {
using JThread = std::jthread;
}

#endif

#define QLEVER_JTHREAD_H

#endif // QLEVER_JTHREAD_H
6 changes: 4 additions & 2 deletions test/FTSAlgorithmsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,11 @@ TEST(FTSAlgorithmsTest, multVarsAggScoresAndTakeTopKContexts) {
cids, eids, scores, nofVars, k, &resW4);
ASSERT_EQ(13u, resW4.size());
std::sort(std::begin(resW4), std::end(resW4),
[](const auto& a, const auto& b) { return a[1] > b[1]; });
ASSERT_EQ(3u, resW4(0, 1));
[](const auto& a, const auto& b) {
return a[1] != b[1] ? a[1] > b[1] : a[0] < b[0];
});
ASSERT_EQ(0u, resW4(0, 0));
ASSERT_EQ(3u, resW4(0, 1));
ASSERT_EQ(0u, resW4(0, 2));
ASSERT_EQ(0u, resW4(0, 3));
ASSERT_EQ(1u, resW4(1, 0));
Expand Down
1 change: 1 addition & 0 deletions test/TupleHelpersTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <gtest/gtest.h>

#include <array>
#include <string>

#include "../src/util/TupleHelpers.h"
Expand Down
2 changes: 1 addition & 1 deletion third_party/abseil-cpp
Submodule abseil-cpp updated 265 files
2 changes: 1 addition & 1 deletion third_party/stxxl
Submodule stxxl updated from bd6394 to d61d26
5 changes: 5 additions & 0 deletions toolchains/clang13.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CMake toolchain file for using `clang++-13` together with `libc++`
set(CMAKE_C_COMPILER clang-13)
set(CMAKE_CXX_COMPILER clang++-13)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++abi")
3 changes: 3 additions & 0 deletions toolchains/gcc10.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CMake toolchain file for using `clang++-13` together with `libc++`
set(CMAKE_C_COMPILER gcc-10)
set(CMAKE_CXX_COMPILER g++-10)