Skip to content

Commit

Permalink
Easier go bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiu128 committed Nov 25, 2024
1 parent 3119a35 commit dcfc7f4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
6 changes: 6 additions & 0 deletions bindings-go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Go bindings for seqlock.cpp

- `ffi.h` is from `seqlock.cpp/seqlock/include/seqlock/ffi.h`
- `libseqlock.a` is from `seqlock.cpp/build_rel/seqlock/libseqlock.a` after `cmake -GNinja -DCMAKE_BUILD_TYPE=Release ../` in `build_rel`

The above two files are updated on each version upgrade.
26 changes: 26 additions & 0 deletions bindings-go/ffi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <stdbool.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

struct SingleWriterSeqLock {
void* lock;
void* shm; // optional
void* shared_data;
size_t shared_data_size;
bool shared;
};

struct SingleWriterSeqLock* seqlock_single_writer_create(char* data, size_t size);
struct SingleWriterSeqLock* seqlock_single_writer_create_shared(const char* filename, size_t size);
void seqlock_single_writer_destroy(struct SingleWriterSeqLock*);
void seqlock_single_writer_load(struct SingleWriterSeqLock* wrapper_lock, char* dst, size_t size);
void seqlock_single_writer_store(struct SingleWriterSeqLock* wrapper_lock, char* src, size_t size);

#ifdef __cplusplus
}
#endif
Binary file added bindings-go/libseqlock.a
Binary file not shown.
6 changes: 3 additions & 3 deletions bindings-go/seqlock.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package seqlock

// #cgo CXXFLAGS: -std=c++20 -I/Users/sergiu/Code/my-projects/seqlock.cpp/deps_install/include
// #cgo LDFLAGS: /Users/sergiu/Code/my-projects/seqlock.cpp/deps_install/lib/libseqlock.a -lstdc++
// #cgo CXXFLAGS: -std=c++23
// #cgo LDFLAGS: ${SRCDIR}/libseqlock.a -lstdc++
// #include <stdlib.h>
// #include "/Users/sergiu/Code/my-projects/seqlock.cpp/deps_install/include/seqlock/ffi.h"
// #include "ffi.h"
import "C"

import (
Expand Down
1 change: 1 addition & 0 deletions seqlock/include/seqlock/seqlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <atomic>
#include <concepts>
#include <cstdint>
#include <new>
#include <type_traits>
#include <variant>

Expand Down

0 comments on commit dcfc7f4

Please sign in to comment.