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

[C] Add wrapper for rust ffi doublets #302

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
eb2d279
Add `FfiLinks`
FreePhoenix888 Feb 9, 2022
13be416
Add `CMakeLists`
FreePhoenix888 Feb 9, 2022
4545006
Add `FfiTest`
FreePhoenix888 Feb 9, 2022
167e6d9
Add `Platform.Data.Doublets.h`
FreePhoenix888 Feb 9, 2022
c94787a
Merge branch 'cpp/feature/add_wrapper_around_rust_ffi' into c/feature…
FreePhoenix888 Mar 8, 2022
f0e7447
Use pragma once
FreePhoenix888 Mar 8, 2022
ff2550f
Update `CMakeLists`
FreePhoenix888 Mar 8, 2022
19d0de2
Update `FfiLinks`
FreePhoenix888 Mar 9, 2022
669ecf8
Move includes to `Platform.Data.Doublets.h`
FreePhoenix888 Mar 9, 2022
2294620
Remove unused code
FreePhoenix888 Mar 9, 2022
66ca2e0
Move `FfiLinks`. Use macros
FreePhoenix888 Mar 11, 2022
63d9c07
Add FfiTest.c draft
FreePhoenix888 Mar 11, 2022
7499c1b
Update FfiLinks.h path
FreePhoenix888 Mar 11, 2022
03045ad
Add Tests
FreePhoenix888 Mar 11, 2022
e85807c
Use CStandard 17
FreePhoenix888 Mar 11, 2022
353ce0f
Fix typo
FreePhoenix888 Mar 11, 2022
bb79d9e
Update `FfiTests`
FreePhoenix888 Mar 11, 2022
08c5c2a
Update `FfiLinks`
FreePhoenix888 Mar 11, 2022
649a938
Merge branch 'master' into c/feature/add_ffi_links
FreePhoenix888 Mar 11, 2022
8f5f908
Rename `UnitedMemoryLinks` to `Links` according to renamed function i…
FreePhoenix888 Mar 11, 2022
2c61671
Rename `UnitedMemoryLinks` to `Links` according to renamed function i…
FreePhoenix888 Mar 11, 2022
b2a1cbf
Add `-pthread -ldl` flags
FreePhoenix888 Mar 11, 2022
1afbd37
Update `FfiTest`
FreePhoenix888 Mar 12, 2022
442dabc
Update `FfiLinks`
FreePhoenix888 Mar 12, 2022
dde37b4
Update tests
FreePhoenix888 Mar 12, 2022
b25e452
Update `FfiTests`
FreePhoenix888 Mar 12, 2022
247bb00
Merge branch 'master' into c/feature/add_ffi_links
FreePhoenix888 Mar 12, 2022
87ecbb7
Update `FfiTests`
FreePhoenix888 Mar 12, 2022
4501643
Update `LinksConstants`
FreePhoenix888 Mar 12, 2022
5c73e78
Remove unused code
FreePhoenix888 Mar 12, 2022
8338df4
Rename folders to `src` and `tests`
FreePhoenix888 Mar 12, 2022
c91a3e1
Update paths
FreePhoenix888 Mar 12, 2022
b7d5d63
Move Range and LinksExtensions to separate files. Rename struct fields
FreePhoenix888 Mar 12, 2022
f764cbf
Add `LinksConstants`
FreePhoenix888 Mar 12, 2022
449d22d
Add `Range`
FreePhoenix888 Mar 12, 2022
ca40dd2
Rename functions
FreePhoenix888 Mar 12, 2022
5c97a7f
Update CMakeLists
FreePhoenix888 Mar 12, 2022
d2b944c
Add if cpp then extern
FreePhoenix888 Mar 12, 2022
84c1c02
Use gtest
FreePhoenix888 Mar 12, 2022
9944611
Update tests
FreePhoenix888 Mar 12, 2022
b7c908e
Rename to Links
FreePhoenix888 Apr 15, 2022
f6012ed
Rename query to restriction/substitution. Rename restrictions to rest…
FreePhoenix888 Apr 15, 2022
7242497
Rename void* to storage
FreePhoenix888 Apr 15, 2022
f864aa4
Rename constants field according to name conventions
FreePhoenix888 Apr 15, 2022
8114766
Rename uint64FfiStorage to storage
FreePhoenix888 Apr 15, 2022
e478034
Include Links.h
FreePhoenix888 Apr 15, 2022
4f513e5
Move flags to LINKS_PLATFORM_EXTRA_FLAGS
FreePhoenix888 May 27, 2022
517e7c1
Remove extra line
FreePhoenix888 May 27, 2022
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: 42 additions & 0 deletions c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.13)

set(LINKS_PLATFORM_TESTS OFF CACHE BOOL "Whether to compile tests")
set(LINKS_PLATFORM_BENCHMARKS OFF CACHE BOOL "Whether to compile benchmarks")
set(LINKS_PLATFORM_EXTRA_FLAGS "" CACHE STRING "Extra compiler flags")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -ldl")
FreePhoenix888 marked this conversation as resolved.
Show resolved Hide resolved
set(CONAN_DISABLE_CHECK_COMPILER TRUE)
set(LINKS_PLATFORM_TESTS TRUE)
set(LINKS_PLATFORM_BENCHMARKS TRUE)
Comment on lines +6 to +8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were banned in the terminal?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't joke


project(Platform.Data.Doublets)

set(CONAN_DISABLE_CHECK_COMPILER TRUE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

o_o

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
list(APPEND LINKS_PLATFORM_EXTRA_FLAGS ${CONAN_USER_PLATFORM.HASHING_suggested_flags})


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

add_library(${PROJECT_NAME}.Library INTERFACE)
target_include_directories(${PROJECT_NAME}.Library INTERFACE src)

target_link_directories(${PROJECT_NAME}.Library INTERFACE ${CMAKE_CURRENT_LIST_DIR})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not bad. Remove it style from your mind

target_link_libraries(${PROJECT_NAME}.Library INTERFACE doublets_ffi)
target_link_libraries(${PROJECT_NAME}.Library INTERFACE ${CMAKE_DL_LIBS})

target_compile_options(${PROJECT_NAME}.Library INTERFACE ${LINKS_PLATFORM_EXTRA_FLAGS})

if(${LINKS_PLATFORM_TESTS})
add_executable(${PROJECT_NAME}.Tests tests/FfiTests.cpp)
set_target_properties(${PROJECT_NAME}.Tests PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(${PROJECT_NAME}.Tests PRIVATE CONAN_PKG::gtest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -ldl")

target_link_libraries(${PROJECT_NAME}.Tests PRIVATE ${PROJECT_NAME}.Library)
endif()
#
#if(${LINKS_PLATFORM_BENCHMARKS})
# add_executable(${PROJECT_NAME}.Benchmarks ${PROJECT_NAME}.Benchmarks/AllBenchmarks.cpp)
# target_link_libraries(${PROJECT_NAME}.Benchmarks PRIVATE CONAN_PKG::gtest)
# target_link_libraries(${PROJECT_NAME}.Benchmarks PRIVATE CONAN_PKG::benchmark)
# target_link_libraries(${PROJECT_NAME}.Benchmarks PRIVATE ${PROJECT_NAME}.Library)
#endif()
Comment on lines +34 to +40
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

168 changes: 0 additions & 168 deletions c/ffi.h

This file was deleted.

98 changes: 98 additions & 0 deletions c/src/FfiLinks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#pragma once

#define CALL_MACRO_WITH_SUPPORTED_FUNCTION_PREFIX_TYPES($Macro) \
$Macro(UInt8); \
$Macro(UInt16); \
$Macro(UInt32); \
$Macro(UInt64);

#define CALL_MACRO_WITH_SUPPORTED_TLINKADDRESS_TYPES_AND_PREFIX_TYPES($Macro) \
$Macro(uint8_t, UInt8); \
$Macro(uint16_t, UInt16); \
$Macro(uint32_t, UInt32); \
$Macro(uint64_t, UInt64);

#define DECLARE_LINK($TLinkAddress, $Prefix) \
typedef struct $Prefix##Link \
{ \
$TLinkAddress Index; \
$TLinkAddress Source; \
$TLinkAddress Target; \
} $Prefix##Link;

#define DECLARE_WRITE_HANDLER($TLinkAddress, $Prefix) \
typedef $TLinkAddress (*$Prefix##CUDCallback)($Prefix##Link before, $Prefix##Link after);

#define DECLARE_READ_HANDLER($TLinkAddress, $Prefix) \
typedef $TLinkAddress (*$Prefix##EachCallback)($Prefix##Link);

//typedef struct SharedLogger {
// void (* formatter)(const Record*);
//} SharedLogger;

#define DECLARE_UNITED_MEMORY_LINKS_NEW($Prefix) \
void* $Prefix##Links_New(const char* path);

#define DECLARE_UNITED_MEMORY_LINKS_NEW_WITH_CONSTANTS($Prefix) \
void* $Prefix##Links_NewWithConstants(const char* path, $Prefix##LinksConstantsType* constants);

#define DECLARE_UNITED_MEMORY_LINKS_DROP($Prefix) \
void $Prefix##Links_Drop(void* this_);
FreePhoenix888 marked this conversation as resolved.
Show resolved Hide resolved

#define DECLARE_UNITED_MEMORY_LINKS_CREATE($TLinkAddress, $Prefix) \
$TLinkAddress $Prefix##Links_Create(void* this_, \
const $TLinkAddress* query, \
FreePhoenix888 marked this conversation as resolved.
Show resolved Hide resolved
uintptr_t len, \
$Prefix##CUDCallback callback);

#define DECLARE_UNITED_MEMORY_LINKS_EACH($TLinkAddress, $Prefix) \
$TLinkAddress $Prefix##Links_Each(void* this_, \
const $TLinkAddress* query, \
FreePhoenix888 marked this conversation as resolved.
Show resolved Hide resolved
uintptr_t len, \
$Prefix##EachCallback callback);

#define DECLARE_UNITED_MEMORY_LINKS_COUNT($TLinkAddress, $Prefix) \
uintptr_t $Prefix##Links_Count(void* this_, \
const $TLinkAddress* query, \
FreePhoenix888 marked this conversation as resolved.
Show resolved Hide resolved
uintptr_t len);

#define DECLARE_UNITED_MEMORY_LINKS_UPDATE($TLinkAddress, $Prefix) \
$TLinkAddress $Prefix##Links_Update(void* this_, \
const $TLinkAddress* restrictions, \
FreePhoenix888 marked this conversation as resolved.
Show resolved Hide resolved
uintptr_t len_r, \
const $TLinkAddress* substitution, \
uintptr_t len_s, \
$Prefix##CUDCallback callback);

#define DECLARE_UNITED_MEMORY_LINKS_DELETE($TLinkAddress, $Prefix) \
void $Prefix##Links_Delete(void* this_, \
const $TLinkAddress* query, \
FreePhoenix888 marked this conversation as resolved.
Show resolved Hide resolved
uintptr_t len, \
$Prefix##CUDCallback callback);


//void setup_shared_logger(struct SharedLogger logger);

//void init_fmt_logger(void);

#if defined(__cplusplus)
extern "C" {
#endif
CALL_MACRO_WITH_SUPPORTED_TLINKADDRESS_TYPES_AND_PREFIX_TYPES(DECLARE_RANGE);
DECLARE_LINKS_CONSTANTS(uint8_t, UInt8, UINT8);
DECLARE_LINKS_CONSTANTS(uint16_t, UInt16, UINT16);
DECLARE_LINKS_CONSTANTS(uint32_t, UInt32, UINT32);
DECLARE_LINKS_CONSTANTS(uint64_t, UInt64, UINT64);
CALL_MACRO_WITH_SUPPORTED_TLINKADDRESS_TYPES_AND_PREFIX_TYPES(DECLARE_LINK);
CALL_MACRO_WITH_SUPPORTED_TLINKADDRESS_TYPES_AND_PREFIX_TYPES(DECLARE_WRITE_HANDLER);
CALL_MACRO_WITH_SUPPORTED_TLINKADDRESS_TYPES_AND_PREFIX_TYPES(DECLARE_READ_HANDLER);
CALL_MACRO_WITH_SUPPORTED_FUNCTION_PREFIX_TYPES(DECLARE_UNITED_MEMORY_LINKS_NEW);
CALL_MACRO_WITH_SUPPORTED_FUNCTION_PREFIX_TYPES(DECLARE_UNITED_MEMORY_LINKS_DROP);
CALL_MACRO_WITH_SUPPORTED_TLINKADDRESS_TYPES_AND_PREFIX_TYPES(DECLARE_UNITED_MEMORY_LINKS_CREATE);
CALL_MACRO_WITH_SUPPORTED_TLINKADDRESS_TYPES_AND_PREFIX_TYPES(DECLARE_UNITED_MEMORY_LINKS_EACH);
CALL_MACRO_WITH_SUPPORTED_TLINKADDRESS_TYPES_AND_PREFIX_TYPES(DECLARE_UNITED_MEMORY_LINKS_COUNT);
CALL_MACRO_WITH_SUPPORTED_TLINKADDRESS_TYPES_AND_PREFIX_TYPES(DECLARE_UNITED_MEMORY_LINKS_UPDATE);
CALL_MACRO_WITH_SUPPORTED_TLINKADDRESS_TYPES_AND_PREFIX_TYPES(DECLARE_UNITED_MEMORY_LINKS_DELETE);
#if defined(__cplusplus)
}
#endif
38 changes: 38 additions & 0 deletions c/src/LinksConstants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#define DECLARE_LINKS_CONSTANTS($TLinkAddress, $Prefix, $PrefixUpperCase) \
typedef struct $Prefix##LinksConstantsType \
{ \
$TLinkAddress Index_part; \
FreePhoenix888 marked this conversation as resolved.
Show resolved Hide resolved
$TLinkAddress Source_part; \
$TLinkAddress Target_part; \
$TLinkAddress Null; \
$TLinkAddress Continue; \
$TLinkAddress Break; \
$TLinkAddress Skip; \
$TLinkAddress Any; \
$TLinkAddress Itself; \
$TLinkAddress Error; \
$Prefix##Range Internal_range; \
FreePhoenix888 marked this conversation as resolved.
Show resolved Hide resolved
$Prefix##Range External_range; \
bool _opt_marker; \
} $Prefix##LinksConstantsType; \
\
$Prefix##LinksConstantsType Default##$Prefix##LinksConstants = { \
.Index_part = 0, \
.Source_part = 1, \
.Target_part = 2, \
.Null = 0, \
.Continue = $PrefixUpperCase##_MAX, \
.Break = $PrefixUpperCase##_MAX - 1, \
.Skip = $PrefixUpperCase##_MAX - 2, \
.Any = $PrefixUpperCase##_MAX - 3, \
.Itself = $PrefixUpperCase##_MAX - 4, \
.Error = $PrefixUpperCase##_MAX - 5, \
.Internal_range = { \
.Minimum = 0, \
.Maximum = $PrefixUpperCase##_MAX - 6, \
}, \
.External_range = { \
.Minimum = ($PrefixUpperCase##_MAX / 2) + 1, \
.Maximum = $PrefixUpperCase##_MAX, \
}, \
};
12 changes: 12 additions & 0 deletions c/src/Platform.Data.Doublets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "Range.h"
#include "LinksConstants.h"
#include "FfiLinks.h"
6 changes: 6 additions & 0 deletions c/src/Range.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#define DECLARE_RANGE($TLinkAddress, $Prefix) \
typedef struct $Prefix##Range \
{ \
$TLinkAddress Minimum; \
$TLinkAddress Maximum; \
} $Prefix##Range;
Loading