Skip to content

Commit

Permalink
cxx experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Mar 1, 2024
1 parent 320766f commit cf43513
Show file tree
Hide file tree
Showing 26 changed files with 127 additions and 5,813 deletions.
156 changes: 72 additions & 84 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
members = [
"taskchampion/taskchampion",
"taskchampion/sync-server",
"taskchampion/lib",
"taskchampion/integration-tests",
"taskchampion/xtask",
"src/tc",
#"taskchampion/integration-tests",
#"taskchampion/xtask",
]

resolver = "2"
Expand Down
7 changes: 6 additions & 1 deletion src/tc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ corrosion_import_crate(
LOCKED
CRATES "taskchampion-lib")

corrosion_add_cxxbridge(taskchampion-cpp
CRATE taskchampion-lib
FILES src/lib.rs
)

include_directories (${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/tc
Expand All @@ -29,4 +34,4 @@ set (tc_SRCS
Task.cpp Task.h)

add_library (tc STATIC ${tc_SRCS})
target_link_libraries(tc taskchampion-lib)
target_link_libraries(tc taskchampion-lib taskchampion-cpp)
15 changes: 15 additions & 0 deletions src/tc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "taskchampion-lib"
version = "0.1.0"
edition = "2021"
publish = false

[lib]
crate-type = ["staticlib"]

[dependencies]
taskchampion = { path = "../../taskchampion/taskchampion", features = ["server-sync"] }
cxx = "1.0"

[build-dependencies]
cxx-build = "1.0"
6 changes: 6 additions & 0 deletions src/tc/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[allow(unused_must_use)]
fn main() {
cxx_build::bridge("src/lib.rs");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=src/lib.rs");
}
17 changes: 17 additions & 0 deletions src/tc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use taskchampion::{Replica as RealReplica, StorageConfig};

#[cxx::bridge(namespace = "tc")]
mod ffi {
// Rust types and signatures exposed to C++.
extern "Rust" {
type Replica;
fn new_replica() -> Box<Replica>;
}
}

struct Replica(RealReplica);

fn new_replica() -> Box<Replica> {
let storage = StorageConfig::InMemory.into_storage().unwrap();
Box::new(Replica(RealReplica::new(storage)))
}
5 changes: 5 additions & 0 deletions src/tc/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "lib.rs.h"

int main() {
auto replica = tc::new_replica();
}
17 changes: 0 additions & 17 deletions taskchampion/lib/Cargo.toml

This file was deleted.

2 changes: 0 additions & 2 deletions taskchampion/lib/Makefile

This file was deleted.

Loading

0 comments on commit cf43513

Please sign in to comment.