mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-21 16:53:08 +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
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