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 Libcxx Compatability Mode to AnyBlob #4

Merged
merged 2 commits into from
Nov 28, 2023
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
35 changes: 35 additions & 0 deletions .github/actions/do-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "Build AnyBlob"
description: "Build AnyBlob using either clang or gcc"
inputs:
clang-toolchain:
required: false
description: "Build with clang and use libcxx as the standard library"
default: false

runs:
using: "composite"
steps:
# CMake configuration option 1 - GCC toolchain
- name: Configure CMake
if: ${{ inputs.clang-toolchain == 'false' }}
run: |
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
shell: bash

# CMake configuration option 2 - Clang toolchain
- name: Configure CMake
if: ${{ inputs.clang-toolchain == 'true' }}
# Explicitly use clang-15. The runner comes with clang-13, 14, and 15.
# However, only clang-15 and up support `-Wno-unqualified-std-cast-call`.
run: |
sudo apt install libc++-15-dev libc++abi-15-dev
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
-DCMAKE_C_COMPILER=clang-15 \
-DCMAKE_CXX_COMPILER=clang++-15 \
-DANYBLOB_LIBCXX_COMPAT=1
shell: bash

# Build library and test binaries
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
shell: bash
11 changes: 11 additions & 0 deletions .github/actions/install-deps/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "Install Dependencies"
description: "Installs dynamic libraries required by AnyBlob"

runs:
using: "composite"
steps:
# Install dependencies
- name: Install dependencies
run: sudo apt update && sudo apt install liburing-dev openssl libssl-dev libjemalloc-dev lld
shell: bash

26 changes: 16 additions & 10 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ on:

env:
BUILD_TYPE: Debug
# False ASAN positives for alloc_dealloc_mismatch when running with clang
# https://github.com/llvm/llvm-project/issues/59432
ASAN_OPTIONS: alloc_dealloc_mismatch=0

jobs:
integration-test:
name: Integration Tests (Clang ${{ matrix.clang-toolchain }})
# Run on ubuntu
runs-on: ubuntu-latest
# Use both the GCC and Clang Toolchain
strategy:
matrix:
clang-toolchain: [true, false]

# Define the steps
steps:
Expand All @@ -39,17 +47,15 @@ jobs:
with:
submodules: true

# Install dependencies
- name: Install dependencies
run: sudo apt update && sudo apt install liburing-dev openssl libssl-dev libjemalloc-dev lld
# Use action to install dependencies
- name: Install Dependencies
uses: ./.github/actions/install-deps

# CMake configuration
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

# Build library and integration tester
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
# Use action to build
- name: Build AnyBlob
uses: ./.github/actions/do-build
with:
clang-toolchain: ${{ matrix.clang-toolchain }}

# Run the integration test
- name: Integration Test
Expand Down
30 changes: 18 additions & 12 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ on:

env:
BUILD_TYPE: Debug
# False ASAN positives for alloc_dealloc_mismatch when running with clang
# https://github.com/llvm/llvm-project/issues/59432
ASAN_OPTIONS: alloc_dealloc_mismatch=0

jobs:
uint-test:
unit-test:
name: Unit Tests (Clang ${{ matrix.clang-toolchain }})
# Run on ubuntu
runs-on: ubuntu-latest
# Use both the GCC and Clang Toolchain
strategy:
matrix:
clang-toolchain: [true, false]

# Define the steps
steps:
Expand All @@ -25,19 +33,17 @@ jobs:
with:
submodules: true

# Install dependencies
- name: Install dependencies
run: sudo apt update && sudo apt install liburing-dev openssl libssl-dev libjemalloc-dev lld
# Use action to install dependencies
- name: Install Dependencies
uses: ./.github/actions/install-deps

# CMake configuration
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

# Build library and tester
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
# Use action to build
- name: Build AnyBlob
uses: ./.github/actions/do-build
with:
clang-toolchain: ${{ matrix.clang-toolchain }}

# Run the unit test
# Run the unit tests
- name: Unit Test
working-directory: ${{github.workspace}}/build
run: ./tester
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo" "Coverage")
endif()

option(ANYBLOB_LIBCXX_COMPAT "Build AnyBlob in a way that's compatible with libcxx." OFF)
if (ANYBLOB_LIBCXX_COMPAT)
message("Building AnyBlob with libcxx")
# Update compiler flags to use libcxx as standard library.
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -stdlib=libc++")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -stdlib=libc++")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -stdlib=libc++")
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE} -stdlib=libc++")
endif()

# ---------------------------------------------------------------------------
# Coverage Environment
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -113,6 +123,9 @@ include("${PROJECT_SOURCE_DIR}/test/integration/local.cmake")
add_library(AnyBlob STATIC ${SRC_CPP} ${INCLUDE_HPP})
target_link_libraries(AnyBlob PUBLIC OpenSSL::SSL Threads::Threads ${LIBURING_LIBRARY} jemalloc)
target_include_directories(AnyBlob PUBLIC ${PROJECT_SOURCE_DIR}/include)
if (ANYBLOB_LIBCXX_COMPAT)
target_compile_definitions(AnyBlob PRIVATE ANYBLOB_LIBCXX_COMPAT)
endif()

# ---------------------------------------------------------------------------
# Unit tests
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ AnyBlob relies on some third-party libraries:
- openssl
- jemalloc

For Ubuntu the following command install the third-party libraries:
For Ubuntu 22.04+ the following command installs the third-party libraries:
```
sudo apt update && sudo apt install liburing-dev openssl libssl-dev libjemalloc-dev lld g++ cmake
```
Expand Down
2 changes: 2 additions & 0 deletions include/cloud/provider.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include <memory>
#include <vector>
#include <string>
#include <string_view>
//---------------------------------------------------------------------------
// AnyBlob - Universal Cloud Object Storage Library
// Dominik Durner, 2021
Expand Down
2 changes: 1 addition & 1 deletion include/network/io_uring_socket.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "network/throughput_resolver.hpp"
#include "network/resolver.hpp"
#include <memory>
#include <string>
#include <unordered_map>
Expand Down
3 changes: 2 additions & 1 deletion include/network/tasked_send_receiver.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#pragma once
#include "network/config.hpp"
#include "network/io_uring_socket.hpp"
#include "network/message_task.hpp"
#include "network/tls_context.hpp"
#include "network/config.hpp"
#include "utils/ring_buffer.hpp"
#include <atomic>
#include <condition_variable>
#include <memory>
#include <mutex>
#include <queue>
#include <span>
#include <thread>
#include <vector>
//---------------------------------------------------------------------------
// AnyBlob - Universal Cloud Object Storage Library
Expand Down
5 changes: 5 additions & 0 deletions include/network/throughput_resolver.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#pragma once
// The `ThroughputResolver` depends on gnu stdlib associative containers that are
// not supported by libcxx. We remove the throughput resolver in its entirety when
// building with libcxx.
#ifndef ANYBLOB_LIBCXX_COMPAT
#include "network/resolver.hpp"
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
Expand Down Expand Up @@ -55,3 +59,4 @@ class ThroughputResolver : public network::Resolver {
}; // namespace network
//---------------------------------------------------------------------------
}; // namespace anyblob
#endif // ANYBLOB_LIBCXX_COMPAT
1 change: 1 addition & 0 deletions src/cloud/aws.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <chrono>
#include <iomanip>
#include <string>
#include <sstream>
//---------------------------------------------------------------------------
// AnyBlob - Universal Cloud Object Storage Library
// Dominik Durner, 2021
Expand Down
2 changes: 1 addition & 1 deletion src/cloud/azure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "network/http_helper.hpp"
#include "network/original_message.hpp"
#include "network/tasked_send_receiver.hpp"
#include "network/throughput_resolver.hpp"
#include "network/resolver.hpp"
#include "utils/data_vector.hpp"
#include <chrono>
#include <iomanip>
Expand Down
2 changes: 1 addition & 1 deletion src/cloud/gcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "network/http_helper.hpp"
#include "network/original_message.hpp"
#include "network/tasked_send_receiver.hpp"
#include "network/throughput_resolver.hpp"
#include "network/resolver.hpp"
#include "utils/data_vector.hpp"
#include <chrono>
#include <iomanip>
Expand Down
1 change: 1 addition & 0 deletions src/network/http_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstring>
#include <stdexcept>
#include <string_view>
#include <string>
//---------------------------------------------------------------------------
// AnyBlob - Universal Cloud Object Storage Library
// Dominik Durner, 2021
Expand Down
10 changes: 10 additions & 0 deletions src/network/io_uring_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#ifndef ANYBLOB_LIBCXX_COMPAT
#include "network/throughput_resolver.hpp"
#endif
//---------------------------------------------------------------------------
// AnyBlob - Universal Cloud Object Storage Library
// Dominik Durner, 2021
Expand Down Expand Up @@ -43,7 +46,14 @@ IOUringSocket::IOUringSocket(uint32_t entries, int32_t /*flags*/) : _resolverCac
if (_eventId < 0)
throw runtime_error("Event FD creation error!");
io_uring_register_eventfd(&_uring, _eventId);
#ifndef ANYBLOB_LIBCXX_COMPAT
// By default, use the ThroughputResolver.
_resolverCache.emplace("", make_unique<ThroughputResolver>(entries));
#else
// If we build in libcxx compatability mode, we need to use the default resolver.
// The ThroughputResolver currently does not build with libcxx.
_resolverCache.emplace("", make_unique<Resolver>(entries));
#endif
}
//---------------------------------------------------------------------------
int32_t IOUringSocket::connect(string hostname, uint32_t port, TCPSettings& tcpSettings, int retryLimit)
Expand Down
2 changes: 2 additions & 0 deletions src/network/throughput_resolver.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifndef ANYBLOB_LIBCXX_COMPAT
#include "network/throughput_resolver.hpp"
#include <cstring>
#include <limits>
Expand Down Expand Up @@ -106,3 +107,4 @@ void ThroughputResolver::stopSocket(int fd, uint64_t bytes)
}; // namespace network
//---------------------------------------------------------------------------
}; // namespace anyblob
#endif // ANYBLOB_LIBCXX_COMPAT
1 change: 1 addition & 0 deletions src/network/tls_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <openssl/crypto.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <cassert>
//---------------------------------------------------------------------------
// AnyBlob - Universal Cloud Object Storage Library
// Dominik Durner, 2023
Expand Down
3 changes: 2 additions & 1 deletion test/unit/network/io_uring_socket_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "network/io_uring_socket.hpp"
#include "catch2/single_include/catch2/catch.hpp"
#include "cloud/aws_resolver.hpp"
#include "network/io_uring_socket.hpp"
#include "perfevent/PerfEvent.hpp"
//---------------------------------------------------------------------------
// AnyBlob - Universal Cloud Object Storage Library
Expand Down
1 change: 0 additions & 1 deletion test/unit/network/resolver_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "network/resolver.hpp"
#include "catch2/single_include/catch2/catch.hpp"
#include "network/throughput_resolver.hpp"
//---------------------------------------------------------------------------
// AnyBlob - Universal Cloud Object Storage Library
// Dominik Durner, 2022
Expand Down