mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
first bits of a dynamc lib
This commit is contained in:
parent
8576e7ffa7
commit
33f5f056b1
13 changed files with 6942 additions and 1 deletions
27
Cargo.lock
generated
27
Cargo.lock
generated
|
@ -591,6 +591,25 @@ dependencies = [
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cbindgen"
|
||||||
|
version = "0.20.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "51e3973b165dc0f435831a9e426de67e894de532754ff7a3f307c03ee5dec7dc"
|
||||||
|
dependencies = [
|
||||||
|
"clap",
|
||||||
|
"heck",
|
||||||
|
"indexmap",
|
||||||
|
"log",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"syn",
|
||||||
|
"tempfile",
|
||||||
|
"toml",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.68"
|
version = "1.0.68"
|
||||||
|
@ -3008,6 +3027,14 @@ dependencies = [
|
||||||
"toml_edit",
|
"toml_edit",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "taskchampion-lib"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"cbindgen",
|
||||||
|
"taskchampion",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "taskchampion-sync-server"
|
name = "taskchampion-sync-server"
|
||||||
version = "0.4.1"
|
version = "0.4.1"
|
||||||
|
|
|
@ -4,5 +4,6 @@ members = [
|
||||||
"taskchampion",
|
"taskchampion",
|
||||||
"cli",
|
"cli",
|
||||||
"sync-server",
|
"sync-server",
|
||||||
"replica-server-tests"
|
"replica-server-tests",
|
||||||
|
"lib"
|
||||||
]
|
]
|
||||||
|
|
2
binding-tests/.gitignore
vendored
Normal file
2
binding-tests/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
*.o
|
||||||
|
doctest
|
19
binding-tests/Makefile
Normal file
19
binding-tests/Makefile
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
CXX=g++
|
||||||
|
INC=-I ../lib
|
||||||
|
LIB=-L ../target/debug
|
||||||
|
RPATH=-Wl,-rpath,../target/debug
|
||||||
|
|
||||||
|
TESTS = uuid.cpp
|
||||||
|
|
||||||
|
.PHONY: all test
|
||||||
|
|
||||||
|
all: test
|
||||||
|
|
||||||
|
test: doctest
|
||||||
|
@./doctest --no-version --no-intro
|
||||||
|
|
||||||
|
%.o: %.cpp ../lib/taskchampion.h
|
||||||
|
$(CXX) $(INC) -c $< -o $@
|
||||||
|
|
||||||
|
doctest: doctest.o $(subst .cpp,.o,$(TESTS))
|
||||||
|
$(CXX) $(LIB) $(RPATH) $< $(subst .cpp,.o,$(TESTS)) -ltaskchampion -o $@
|
2
binding-tests/doctest.cpp
Normal file
2
binding-tests/doctest.cpp
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||||
|
#include "doctest.h"
|
6816
binding-tests/doctest.h
Normal file
6816
binding-tests/doctest.h
Normal file
File diff suppressed because it is too large
Load diff
7
binding-tests/uuid.cpp
Normal file
7
binding-tests/uuid.cpp
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#include "doctest.h"
|
||||||
|
#include "taskchampion.h"
|
||||||
|
|
||||||
|
TEST_CASE("creating a UUID") {
|
||||||
|
StoragePtr *storage = storage_new_in_memory();
|
||||||
|
storage_free(storage);
|
||||||
|
}
|
15
lib/Cargo.toml
Normal file
15
lib/Cargo.toml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
[package]
|
||||||
|
name = "taskchampion-lib"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
build = "build.rs"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "taskchampion"
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
taskchampion = { path = "../taskchampion" }
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
cbindgen = "0.20.0"
|
2
lib/Makefile
Normal file
2
lib/Makefile
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
taskchampion.h: cbindgen.toml ../target/debug/libtaskchampion.so
|
||||||
|
cbindgen --config cbindgen.toml --crate taskchampion-lib --output $@
|
18
lib/build.rs
Normal file
18
lib/build.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
use cbindgen::*;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||||
|
|
||||||
|
Builder::new()
|
||||||
|
.with_crate(crate_dir)
|
||||||
|
.with_language(Language::C)
|
||||||
|
.with_config(Config {
|
||||||
|
cpp_compat: true,
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.generate()
|
||||||
|
.expect("Unable to generate bindings")
|
||||||
|
.write_to_file("taskchampion.h");
|
||||||
|
}
|
1
lib/src/lib.rs
Normal file
1
lib/src/lib.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod storage;
|
16
lib/src/storage.rs
Normal file
16
lib/src/storage.rs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
use taskchampion::{storage::Storage, StorageConfig};
|
||||||
|
|
||||||
|
pub struct StoragePtr(Box<dyn Storage>);
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn storage_new_in_memory() -> *mut StoragePtr {
|
||||||
|
// TODO: this is a box containing a fat pointer
|
||||||
|
Box::into_raw(Box::new(StoragePtr(
|
||||||
|
StorageConfig::InMemory.into_storage().unwrap(),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn storage_free(storage: *mut StoragePtr) {
|
||||||
|
drop(unsafe { Box::from_raw(storage) });
|
||||||
|
}
|
15
lib/taskchampion.h
Normal file
15
lib/taskchampion.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <ostream>
|
||||||
|
#include <new>
|
||||||
|
|
||||||
|
struct StoragePtr;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
StoragePtr *storage_new_in_memory();
|
||||||
|
|
||||||
|
void storage_free(StoragePtr *storage);
|
||||||
|
|
||||||
|
} // extern "C"
|
Loading…
Add table
Add a link
Reference in a new issue