Skip to content
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
54 changes: 54 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ hyper = "0.14.18"
im = "15.1"
imara-diff = "0.1.3"
indexmap = "2.0.0"
indicatif = "0.16"
insta = { version = "1.21.0", features = ["toml"] }
is-terminal = "0.4"
itertools = "0.11.0"
Expand Down Expand Up @@ -155,6 +156,8 @@ strum = { version = "0.25.0", features = ["derive"] }
syn = { version = "2", features = ["full", "extra-traits"] }
syntect = { version = "5.0.0", default-features = false, features = ["default-fancy"] }
tabled = "0.14.0"
tar = "0.4"
tempdir = "0.3.7"
tempfile = "3.8"
termcolor = "1.2.0"
thiserror = "1.0.37"
Expand Down
12 changes: 7 additions & 5 deletions crates/bindings-csharp/Runtime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,20 @@ public void Reset()

public class RawTableIter : IEnumerable<byte[]>
{
private readonly uint tableId;
private readonly byte[]? filterBytes;
public readonly byte[] Schema;

private readonly IEnumerator<byte[]> iter;

public RawTableIter(uint tableId, byte[]? filterBytes = null)
{
this.tableId = tableId;
this.filterBytes = filterBytes;
iter = new BufferIter(tableId, filterBytes);
iter.MoveNext();
Schema = iter.Current;
}

public IEnumerator<byte[]> GetEnumerator()
{
return new BufferIter(tableId, filterBytes);
return iter;
}

IEnumerator IEnumerable.GetEnumerator()
Expand Down
44 changes: 23 additions & 21 deletions crates/bindings-csharp/Runtime/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ static MonoArray* stdb_buffer_consume(Buffer buf);
// return out;
// }

#define STDB_IMPORT_MODULE_MINOR(minor) "spacetime_7." #minor
#define STDB_IMPORT_MODULE STDB_IMPORT_MODULE_MINOR(0)

__attribute__((import_module(STDB_IMPORT_MODULE),
__attribute__((import_module("spacetime"),
import_name("_get_table_id"))) extern uint16_t
_get_table_id(const char* name, size_t name_len, uint32_t* out);

Expand All @@ -120,7 +117,7 @@ static uint32_t stdb_get_table_id(MonoString* name_) {
return out;
}

__attribute__((import_module(STDB_IMPORT_MODULE),
__attribute__((import_module("spacetime"),
import_name("_create_index"))) extern uint16_t
_create_index(const char* index_name,
size_t index_name_len,
Expand All @@ -144,7 +141,7 @@ static void stdb_create_index(MonoString* index_name_,
check_result(result);
}

__attribute__((import_module(STDB_IMPORT_MODULE),
__attribute__((import_module("spacetime"),
import_name("_iter_by_col_eq"))) extern uint16_t
_iter_by_col_eq(uint32_t table_id,
uint32_t col_id,
Expand All @@ -166,7 +163,7 @@ static MonoArray* stdb_iter_by_col_eq(uint32_t table_id,
return stdb_buffer_consume(out);
}

__attribute__((import_module(STDB_IMPORT_MODULE),
__attribute__((import_module("spacetime"),
import_name("_insert"))) extern uint16_t
_insert(uint32_t table_id, uint8_t* row, size_t row_len);

Expand All @@ -178,7 +175,7 @@ static void stdb_insert(uint32_t table_id, MonoArray* row_) {
check_result(result);
}

// __attribute__((import_module(STDB_IMPORT_MODULE),
// __attribute__((import_module("spacetime"),
// import_name("_delete_pk"))) extern uint16_t
// _delete_pk(uint32_t table_id, const uint8_t* pk, size_t pk_len);

Expand All @@ -190,7 +187,7 @@ static void stdb_insert(uint32_t table_id, MonoArray* row_) {
// check_result(result);
// }

// __attribute__((import_module(STDB_IMPORT_MODULE),
// __attribute__((import_module("spacetime"),
// import_name("_delete_value"))) extern uint16_t
// _delete_value(uint32_t table_id, const uint8_t* row, size_t row_len);

Expand All @@ -202,7 +199,7 @@ static void stdb_insert(uint32_t table_id, MonoArray* row_) {
// check_result(result);
// }

__attribute__((import_module(STDB_IMPORT_MODULE),
__attribute__((import_module("spacetime"),
import_name("_delete_by_col_eq"))) extern uint16_t
_delete_by_col_eq(uint32_t table_id,
uint32_t col_id,
Expand All @@ -224,7 +221,7 @@ static uint32_t stdb_delete_by_col_eq(uint32_t table_id,
return out;
}

// __attribute__((import_module(STDB_IMPORT_MODULE),
// __attribute__((import_module("spacetime"),
// import_name("_delete_range"))) extern uint16_t
// _delete_range(uint32_t table_id,
// uint32_t col_id,
Expand All @@ -251,7 +248,7 @@ static uint32_t stdb_delete_by_col_eq(uint32_t table_id,
// return out;
// }

__attribute__((import_module(STDB_IMPORT_MODULE),
__attribute__((import_module("spacetime"),
import_name("_iter_start"))) extern uint16_t
_iter_start(uint32_t table_id, BufferIter* out);

Expand All @@ -261,7 +258,7 @@ static void stdb_iter_start(uint32_t table_id, BufferIter* iter) {
check_result(result);
}

__attribute__((import_module(STDB_IMPORT_MODULE),
__attribute__((import_module("spacetime"),
import_name("_iter_start_filtered"))) extern uint16_t
_iter_start_filtered(uint32_t table_id,
const uint8_t* filter,
Expand All @@ -279,7 +276,7 @@ static void stdb_iter_start_filtered(uint32_t table_id,
check_result(result);
}

__attribute__((import_module(STDB_IMPORT_MODULE),
__attribute__((import_module("spacetime"),
import_name("_iter_next"))) extern uint16_t
_iter_next(BufferIter iter, Buffer* out);

Expand All @@ -292,7 +289,7 @@ static MonoArray* stdb_iter_next(BufferIter iter) {
return stdb_buffer_consume(out);
}

__attribute__((import_module(STDB_IMPORT_MODULE),
__attribute__((import_module("spacetime"),
import_name("_iter_drop"))) extern uint16_t
_iter_drop(BufferIter iter);

Expand All @@ -310,7 +307,7 @@ static void stdb_iter_drop(BufferIter* iter) {
check_result(result);
}

__attribute__((import_module(STDB_IMPORT_MODULE),
__attribute__((import_module("spacetime"),
import_name("_console_log"))) extern void
_console_log(uint8_t level,
const char* target,
Expand Down Expand Up @@ -338,7 +335,7 @@ static void stdb_console_log(MonoString* text_,
free_string(filename);
}

__attribute__((import_module(STDB_IMPORT_MODULE),
__attribute__((import_module("spacetime"),
import_name("_schedule_reducer"))) extern void
_schedule_reducer(const char* name,
size_t name_len,
Expand All @@ -363,19 +360,19 @@ static void stdb_schedule_reducer(
free_string(name);
}

__attribute__((import_module(STDB_IMPORT_MODULE),
__attribute__((import_module("spacetime"),
import_name("_cancel_reducer"))) extern void
_cancel_reducer(ScheduleToken token);

static void stdb_cancel_reducer(ScheduleToken* token) {
_cancel_reducer(*token);
}

__attribute__((import_module(STDB_IMPORT_MODULE),
__attribute__((import_module("spacetime"),
import_name("_buffer_len"))) extern size_t
_buffer_len(Buffer buf);

__attribute__((import_module(STDB_IMPORT_MODULE),
__attribute__((import_module("spacetime"),
import_name("_buffer_consume"))) extern void
_buffer_consume(Buffer buf, uint8_t* into, size_t len);

Expand All @@ -390,7 +387,7 @@ static MonoArray* stdb_buffer_consume(Buffer buf) {
return result;
}

__attribute__((import_module(STDB_IMPORT_MODULE),
__attribute__((import_module("spacetime"),
import_name("_buffer_alloc"))) extern Buffer
_buffer_alloc(const uint8_t* data, size_t data_len);

Expand Down Expand Up @@ -779,3 +776,8 @@ __attribute__((export_name("__preinit__10_init_csharp"))) void
__preinit__10_init_csharp() {
_start();
}

// __attribute__((export_name("SPACETIME_ABI_VERSION"))) -
// doesn't work on non-functions, must specify on command line
const uint32_t SPACETIME_ABI_VERSION = /* 5.0 */ (5 << 16) | 0;
const uint8_t SPACETIME_ABI_VERSION_IS_ADDR = 1;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<ItemGroup>
<WasiNativeFileReference Include="$(MSBuildThisFileDirectory)../bindings.c" />
<WasiNativeFileReference Include="-Wl,--export=SPACETIME_ABI_VERSION,--export=SPACETIME_ABI_VERSION_IS_ADDR" />
<WasiAfterRuntimeLoaded Include="mono_stdb_attach_bindings" />
</ItemGroup>

Expand Down
30 changes: 24 additions & 6 deletions crates/bindings-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,35 @@ use std::ptr;

use alloc::boxed::Box;

use spacetimedb_primitives::{ColId, TableId};
/// The current version of the ABI.
///
/// Exported as `SPACETIME_ABI_VERSION`, a `u32` WASM global.
/// If this global contains an address into linear memory at which the version is stored,
/// then a WASM global named `SPACETIME_ABI_VERSION_IS_ADDR` is also be exported.
///
/// In rust this looks like:
/// ```rust,ignore
/// #[no_mangle]
/// static SPACETIME_ABI_VERSION: u32 = _; // right now, rust `static`s always export as an address.
/// #[no_mangle]
/// static SPACETIME_ABI_VERSION_IS_ADDR: () = ();
/// ```
///
/// The (big-endian) first 2 bytes constitute the major version (`A`) of the ABI,
/// and the last 2 bytes constitute the minor version (`B`).
///
/// The semantics of a version number `A.B` is that a host implementing version `A.B`
/// can run a module declaring `X.Y` if and only if `X == A && Y <= B`.
/// So, the minor version is intended for backwards-compatible changes, e.g. adding a new function,
/// and the major version is for fully breaking changes.
pub const ABI_VERSION: u32 = 0x0005_0000;

/// Provides a raw set of sys calls which abstractions can be built atop of.
pub mod raw {
use core::mem::ManuallyDrop;
use spacetimedb_primitives::{ColId, TableId};

// this module identifier determines the abi version that modules built with this crate depend
// on. Any non-breaking additions to the abi surface should be put in a new `extern {}` block
// with a module identifier with a minor version 1 above the previous highest minor version.
// For breaking changes, all functions should be moved into one new `spacetime_X.0` block.
#[link(wasm_import_module = "spacetime_7.0")]
#[link(wasm_import_module = "spacetime")]
extern "C" {
/*
/// Create a table with `name`, a UTF-8 slice in WASM memory lasting `name_len` bytes,
Expand Down Expand Up @@ -671,6 +688,7 @@ pub fn cancel_reducer(id: u64) {
}

pub use raw::{Buffer, BufferIter};
use spacetimedb_primitives::{ColId, TableId};

impl Buffer {
/// Returns the number of bytes of the data stored in the buffer.
Expand Down
Loading