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

Clang support #83

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 0 additions & 10 deletions .github/actions/setup-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@ runs:
run: make dependencies-mac
if: ${{ runner.os == 'macOS' }}

# - name: Setup vcpkg cache in shell
# shell: bash
# run: |
# which -a gcc-12
# echo "CC=/usr/local/bin/gcc-12" >> $GITHUB_ENV
# echo "CMAKE_C_COMPILER=/usr/local/bin/gcc-12" >> $GITHUB_ENV
# echo "CXX=/usr/local/bin/g++-12" >> $GITHUB_ENV
# echo "CMAKE_CXX_COMPILER=/usr/local/bin/g++-12" >> $GITHUB_ENV
# if: ${{ runner.os == 'macOS' }}

################
# Windows
- name: Windows init steps (vc143)
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,11 @@ jobs:

########
# Macos
- name: Python Build Steps (Macos x86)
- name: Python Build Steps (Macos - cibuildwheel)
run: make dist-py-cibw
env:
CIBW_BUILD: "${{ matrix.cibuildwheel }}-macos*"
CIBW_ENVIRONMENT_MACOS: CC="/usr/local/bin/gcc-13" CXX="/usr/local/bin/g++-13" CCACHE_DIR="/Users/runner/work/csp/csp/.ccache" VCPKG_DEFAULT_BINARY_CACHE="${{ env.VCPKG_DEFAULT_BINARY_CACHE }}" VCPKG_DOWNLOADS="${{ env.VCPKG_DOWNLOADS }}"
CIBW_ENVIRONMENT_MACOS: CCACHE_DIR="/Users/runner/work/csp/csp/.ccache" VCPKG_DEFAULT_BINARY_CACHE="${{ env.VCPKG_DEFAULT_BINARY_CACHE }}" VCPKG_DOWNLOADS="${{ env.VCPKG_DOWNLOADS }}"
CIBW_ARCHS_MACOS: x86_64
CIBW_BUILD_VERBOSITY: 3
if: ${{ matrix.os == 'macos-12' }}
Expand All @@ -293,7 +293,7 @@ jobs:
run: make dist-py-cibw
env:
CIBW_BUILD: "${{ matrix.cibuildwheel }}-macos*"
CIBW_ENVIRONMENT_MACOS: PATH="/opt/homebrew/opt/bison/bin/:$PATH" CC="/opt/homebrew/bin/gcc-13" CXX="/opt/homebrew/bin/g++-13" LDFLAGS="-Wl,-ld_classic" CCACHE_DIR="/Users/runner/work/csp/csp/.ccache" VCPKG_DEFAULT_BINARY_CACHE="${{ env.VCPKG_DEFAULT_BINARY_CACHE }}" VCPKG_DOWNLOADS="${{ env.VCPKG_DOWNLOADS }}"
CIBW_ENVIRONMENT_MACOS: PATH="/opt/homebrew/opt/bison/bin/:$PATH" LDFLAGS="-Wl,-ld_classic" CCACHE_DIR="/Users/runner/work/csp/csp/.ccache" VCPKG_DEFAULT_BINARY_CACHE="${{ env.VCPKG_DEFAULT_BINARY_CACHE }}" VCPKG_DOWNLOADS="${{ env.VCPKG_DOWNLOADS }}"
CIBW_ARCHS_MACOS: arm64
CIBW_BUILD_VERBOSITY: 3
if: ${{ matrix.os == 'macos-14' }}
Expand Down
14 changes: 8 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,16 @@ endif()
# RPath #
#########
if(MACOS)
set(CMAKE_INSTALL_RPATH "@loader_path/:@loader_path/../lib")
set(CMAKE_INSTALL_RPATH "@loader_path/")
elseif(LINUX)
set(CMAKE_INSTALL_RPATH "\$ORIGIN:\$ORIGIN/../lib")
set(CMAKE_INSTALL_RPATH "\$ORIGIN")
endif()

###################################################################################################################################################
# Flags #
#########
# Compiler version flags
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")


# Optimization Flags
Expand Down Expand Up @@ -230,9 +228,13 @@ else()
-Wall \
-Wno-deprecated-declarations \
-Wno-deprecated \
-Wno-maybe-uninitialized \
")
add_definitions(-DNDEBUG)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-Wno-maybe-uninitialized \
")
endif()
endif()
endif()

Expand Down
2 changes: 1 addition & 1 deletion cpp/csp/adapters/parquet/ArrowSingleColumnArrayBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class PrimitiveTypedArrayBuilder : public BaseTypedArrayBuilder<ValueType, Arrow
protected:
void pushValueToArray()
{
this -> m_builderPtr -> Append( *this -> m_value );
(void) this -> m_builderPtr -> Append( *this -> m_value );
}
};

Expand Down
5 changes: 3 additions & 2 deletions cpp/csp/adapters/parquet/ParquetReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <csp/engine/Struct.h>
#include <arrow/type.h>
#include <arrow/table.h>
#include <arrow/type_traits.h>
#include <memory>
#include <parquet/arrow/reader.h>
#include <string>
Expand Down Expand Up @@ -240,7 +241,7 @@ class ParquetReader
using ArrowArrayType = typename arrow::TypeTraits<typename arrow::CTypeTraits<T>::ArrowType>::ArrayType;
auto &listAdapter = dynamic_cast<ListColumnAdapter<ArrowArrayType> &>(*columnAdapterReference);
listAdapter.addSubscriber( inputAdapter, symbol,
listReaderInterface );
listReaderInterface );
} );
}
}
Expand Down Expand Up @@ -376,7 +377,7 @@ class SingleTableParquetReader : public ParquetReader
const std::optional<utils::Symbol> &symbol, const DialectGenericListReaderInterface::Ptr &listReaderInterface ) override
{
ParquetReader::addListSubscriber( column, inputAdapter, symbol, listReaderInterface);
m_columnSubscriptionContainer.m_listColumnSubscriptions[column].push_back(ListColumnSubscriberInfo{inputAdapter, symbol, listReaderInterface});
m_columnSubscriptionContainer.m_listColumnSubscriptions[column].push_back(ListColumnSubscriberInfo{{inputAdapter, symbol}, listReaderInterface});
}

protected:
Expand Down
5 changes: 2 additions & 3 deletions cpp/csp/adapters/parquet/ParquetReaderColumnAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class MissingColumnAdapter : public ParquetColumnAdapter

bool isMissingColumn() const override{ return true; }

virtual CspTypePtr getNativeCspType() const
virtual CspTypePtr getNativeCspType() const override
{
CSP_THROW( csp::RuntimeException, "Trying to get native type of a missing column " << getColumnName() );
}
Expand Down Expand Up @@ -190,8 +190,7 @@ template< typename ValueType, typename ArrowArrayType >
class NativeTypeColumnAdapter : public BaseTypedColumnAdapter<ValueType, ArrowArrayType>
{
public:
using BASE = BaseTypedColumnAdapter<ValueType, ArrowArrayType>;
using BASE::BaseTypedColumnAdapter;
using BaseTypedColumnAdapter<ValueType, ArrowArrayType>::BaseTypedColumnAdapter;
virtual CspTypePtr getNativeCspType() const override {return CspType::fromCType<ValueType>::type();}

protected:
Expand Down
24 changes: 24 additions & 0 deletions cpp/csp/adapters/utils/JSONMessageStructConverter.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <csp/adapters/utils/JSONMessageStructConverter.h>
#include <csp/engine/CspType.h>
#include <csp/engine/PartialSwitchCspType.h>
#include <rapidjson/document.h>
#include <rapidjson/error/en.h>
Expand Down Expand Up @@ -159,6 +160,29 @@ std::vector<T> JSONMessageStructConverter::convertJSON( const char * fieldname,
return out;
}

#ifdef __clang__
template <>
boost::container::vector<bool> JSONMessageStructConverter::convertJSON( const char * fieldname, const CspType & type, const FieldEntry &, const rapidjson::Value & jValue, boost::container::vector<bool> * x )
{
if( !jValue.IsArray() )
CSP_THROW( TypeError, "expected ARRAY type for json field " << fieldname );

auto jArray = jValue.GetArray();

const CspType & elemType = *static_cast<const CspArrayType &>( type ).elemType();

boost::container::vector<bool> out;
out.reserve( jArray.Size() );
for( auto & v : jArray )
{
//note that we dont pass FieldEntry to convert here, this doesnt support arrays of structs
out.emplace_back( convertJSON( fieldname, elemType, {}, v, ( bool * ) nullptr) );
}

return out;
}
#endif

JSONMessageStructConverter::JSONMessageStructConverter( const CspTypePtr & type,
const Dictionary & properties ) : MessageStructConverter( type, properties )
{
Expand Down
7 changes: 6 additions & 1 deletion cpp/csp/adapters/utils/JSONMessageStructConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <csp/adapters/utils/MessageStructConverter.h>
#include <csp/core/Hash.h>
#include <csp/engine/CspType.h>
#include <csp/engine/Dictionary.h>
#include <rapidjson/document.h>
#include <list>
Expand Down Expand Up @@ -53,7 +54,11 @@ class JSONMessageStructConverter: public MessageStructConverter
template<typename T>
std::vector<T> convertJSON( const char * fieldname, const CspType & type, const FieldEntry & entry, const rapidjson::Value & v, std::vector<T> * );


#ifdef __clang__
template<>
boost::container::vector<bool> convertJSON( const char * fieldname, const CspType & type, const FieldEntry & entry, const rapidjson::Value & v, boost::container::vector<bool> * );
#endif

Fields m_fields;
DateTimeWireType m_datetimeType;
std::list<std::string> m_jsonkeys; //intentionally stored as list so they dont invalidate on push
Expand Down
38 changes: 32 additions & 6 deletions cpp/csp/adapters/utils/JSONMessageWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _IN_CSP_ADAPTERS_UTILS_JSONMESSAGEWRITER_H

#include <csp/adapters/utils/MessageWriter.h>
#include <csp/engine/CspType.h>
#include <csp/engine/Dictionary.h>
#include <csp/engine/PartialSwitchCspType.h>
#include <rapidjson/document.h>
Expand Down Expand Up @@ -63,14 +64,14 @@ class JSONMessageWriter : public MessageWriter
}

private:
void processTickImpl( const OutputDataMapper & dataMapper, const TimeSeriesProvider * sourcets )
void processTickImpl( const OutputDataMapper & dataMapper, const TimeSeriesProvider * sourcets ) override
{
dataMapper.apply( *this, sourcets );
}

template<typename T>
inline auto convertValue( const T & value )
{
{
return value;
}

Expand All @@ -84,6 +85,11 @@ class JSONMessageWriter : public MessageWriter
template<typename T>
auto convertValue( const std::vector<T> & value, const CspType & type, const FieldEntry & entry );

#ifdef __clang__
template<>
auto convertValue( const boost::container::vector<bool> & value, const CspType & type, const FieldEntry & entry );
#endif

rapidjson::Document m_doc;
rapidjson::StringBuffer m_stringBuffer;
utils::DateTimeWireType m_datetimeWireType;
Expand All @@ -92,13 +98,13 @@ class JSONMessageWriter : public MessageWriter
template<>
inline auto JSONMessageWriter::convertValue( const std::string & value )
{
return rapidjson::StringRef( value.c_str() );
return rapidjson::StringRef( value.c_str() );
}

template<>
inline auto JSONMessageWriter::convertValue( const csp::Date & value )
{
return rapidjson::Value( value.asYYYYMMDD().c_str(), m_doc.GetAllocator() );
return rapidjson::Value( value.asYYYYMMDD().c_str(), m_doc.GetAllocator() );
}

template<>
Expand All @@ -123,7 +129,7 @@ inline auto JSONMessageWriter::convertValue( const csp::DateTime & value )
template<>
inline auto JSONMessageWriter::convertValue( const csp::TimeDelta & value )
{
return rapidjson::Value( value.asNanoseconds() );
return rapidjson::Value( value.asNanoseconds() );
}

template<>
Expand All @@ -150,6 +156,26 @@ inline auto JSONMessageWriter::convertValue( const std::vector<T> & value, const
return array;
}

#ifdef __clang__
template<>
inline auto JSONMessageWriter::convertValue( const boost::container::vector<bool> & value, const CspType & type, const FieldEntry & entry )
{
auto & allocator = m_doc.GetAllocator();
rapidjson::Value array( rapidjson::kArrayType );
size_t sz = value.size();

const CspType & elemType = *static_cast<const CspArrayType &>( type ).elemType();

//iterating by index for vector<bool> support
for( size_t index = 0; index < sz; ++index )
{
//Note this passes an empty FieldEntry / wont work on vector of structs
array.PushBack( convertValue( value[index], elemType, {} ), allocator );
}
return array;
}
#endif

template<>
inline auto JSONMessageWriter::convertValue( const StructPtr & struct_, const CspType & type, const FieldEntry & entry )
{
Expand All @@ -159,7 +185,7 @@ inline auto JSONMessageWriter::convertValue( const StructPtr & struct_, const Cs
if( !nestedEntry.sField -> isSet( struct_.get() ) )
continue;


SupportedCspTypeSwitch::template invoke<SupportedArrayCspTypeSwitch>(
nestedEntry.sField -> type().get(),
[ & ]( auto tag )
Expand Down
36 changes: 24 additions & 12 deletions cpp/csp/adapters/utils/ProtobufHelper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <csp/adapters/utils/ProtobufHelper.h>
#include <csp/core/Exception.h>
#include <csp/core/System.h>
#include <csp/engine/CspType.h>
#include <csp/engine/PartialSwitchCspType.h>

namespace proto = google::protobuf;
Expand Down Expand Up @@ -32,7 +33,7 @@ class ProtoImporterAux : public proto::compiler::MultiFileErrorCollector
{
CSP_THROW( RuntimeException, "Failed to load proto schema " << filename << ":" << line << ":" << column << ": " << message );
}

private:
proto::DescriptorPoolDatabase m_wellKnownTypesDatabase;
proto::compiler::SourceTreeDescriptorDatabase m_database;
Expand Down Expand Up @@ -83,7 +84,7 @@ proto::FieldDescriptor::CppType ProtobufHelper::cspToProtoCppType( const CspType
case CspType::Type::DOUBLE: return proto::FieldDescriptor::CPPTYPE_DOUBLE;
case CspType::Type::STRING: return proto::FieldDescriptor::CPPTYPE_STRING;
case CspType::Type::STRUCT: return proto::FieldDescriptor::CPPTYPE_MESSAGE;
case CspType::Type::ARRAY:
case CspType::Type::ARRAY:
{
auto elemType = static_cast<const CspArrayType &>( type ).elemType();
return cspToProtoCppType( *elemType );
Expand Down Expand Up @@ -268,8 +269,7 @@ ProtobufStructMapper::Fields ProtobufStructMapper::buildFields( const CspTypePtr
return fields;
}

using SupportedArrayCspTypeSwitch = PartialSwitchCspType<csp::CspType::Type::BOOL,
csp::CspType::Type::INT32,
using SupportedArrayCspTypeSwitch = PartialSwitchCspType<csp::CspType::Type::INT32,
csp::CspType::Type::UINT32,
csp::CspType::Type::INT64,
csp::CspType::Type::UINT64,
Expand Down Expand Up @@ -366,15 +366,27 @@ void ProtobufStructMapper::mapProtoToStruct( StructPtr & struct_, const proto::M
int count = protoAccess -> FieldSize( protoMsg, pField );

auto elemType = static_cast<const CspArrayType &>( *sField -> type() ).elemType();
#ifdef __clang__
if (elemType.get()->type() == CspType::Type::BOOL) {
boost::container::vector<bool> data;
data.reserve( count );
for( int i = 0; i < count; ++i )
data.emplace_back( extractRepeatedValue<bool>( protoMsg, pField, i ) );

sField -> setValue<boost::container::vector<bool>>( struct_.get(), std::move( data ) );
break;
}
#endif
SupportedArrayCspTypeSwitch::invoke( elemType.get(), [&count,&protoMsg,&pField,&sField,&struct_]( auto tag )
{
using T = typename decltype(tag)::type;
std::vector<T> data;
data.reserve( count );
for( int i = 0; i < count; ++i )
data.emplace_back( extractRepeatedValue<T>( protoMsg, pField, i ) );
sField -> setValue<std::vector<T>>( struct_.get(), std::move( data ) );
} );
{
using T = typename decltype(tag)::type;
std::vector<T> data;
data.reserve( count );
for( int i = 0; i < count; ++i )
data.emplace_back( extractRepeatedValue<T>( protoMsg, pField, i ) );

sField -> setValue<std::vector<T>>( struct_.get(), std::move( data ) );
} );
break;
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/csp/cppnodes/statsimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ class Quantile
}

private:

#ifndef __clang__
ost<std::less_equal<double>> m_tree;
#else
Expand Down
8 changes: 4 additions & 4 deletions cpp/csp/engine/ConstInputAdapter.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef _IN_CSP_ENGINE_ALARMINPUTADAPTER_H
#ifndef _IN_CSP_ENGINE_CONSTINPUTADAPTER_H
#define _IN_CSP_ENGINE_CONSTINPUTADAPTER_H

#include <csp/engine/InputAdapter.h>
Expand All @@ -10,22 +10,22 @@ template<typename T>
class ConstInputAdapter final : public InputAdapter
{
public:
ConstInputAdapter( Engine * engine, CspTypePtr & type, const T & value,
ConstInputAdapter( Engine * engine, CspTypePtr & type, const T & value,
TimeDelta delay ) : InputAdapter( engine, type, PushMode::LAST_VALUE ), m_delay( delay ), m_value( value )
{
}

void start( DateTime start, DateTime end ) override
{
m_timerHandle = rootEngine() -> scheduleCallback( m_delay,
m_timerHandle = rootEngine() -> scheduleCallback( m_delay,
[this]
{
this -> outputTickTyped<T>( rootEngine() -> now(), m_value );
return nullptr;
} );
}

void stop() override
void stop() override
{
rootEngine() -> cancelCallback( m_timerHandle );
}
Expand Down
Loading