Skip to content

Commit e6bb6e3

Browse files
authored
Merge pull request #22 from Dushistov/migrate-to-clc-master
migration to current couchbase-lite-core master
2 parents 963f4d4 + b7b8c9f commit e6bb6e3

File tree

20 files changed

+676
-74
lines changed

20 files changed

+676
-74
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ jobs:
8686
with:
8787
cmake-version: '3.9.6'
8888
github-api-token: ${{ secrets.GITHUB_TOKEN }}
89+
- name: Add fr_FR locale
90+
if: matrix.os == 'ubuntu-latest'
91+
run: |
92+
set -e
93+
sudo locale-gen fr_FR
94+
sudo update-locale
95+
shell: bash
8996
- name: Run tests
9097
run: |
9198
set -e

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
[workspace]
2-
members = ["couchbase-lite-core-sys", "couchbase-lite", "chat-demo"]
2+
members = ["couchbase-lite-core-sys", "couchbase-lite", "chat-demo"]
3+
4+
[patch.'crates-io']
5+
http = { git = "https://github.com/Dushistov/http", rev = "3ad3b825edc3a0d9048a6af5ab524f2fc51bde30" }
6+
tungstenite = { git = "https://github.com/Dushistov/tungstenite-rs", rev = "de80b9bced480d407665e46001fc2d7a6874d71e" }

chat-demo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2018"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
couchbase-lite = { path = "../couchbase-lite" }
10+
couchbase-lite = { path = "../couchbase-lite", features = ["replication"] }
1111
serde = { version = "1.0.104", features = ["derive"] }
1212
tokio = { version = "0.2.6", features = ["io-std", "io-util"] }
1313
log = "0.4.8"

chat-demo/src/main.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use couchbase_lite::{
2-
fallible_streaming_iterator::FallibleStreamingIterator, use_c4_civet_web_socket_factory,
3-
Database, DatabaseConfig, Document, ReplicatorState,
2+
fallible_streaming_iterator::FallibleStreamingIterator, use_web_sockets, Database,
3+
DatabaseConfig, Document, ReplicatorState,
44
};
55
use log::{error, trace};
66
use serde::{Deserialize, Serialize};
7-
use std::{collections::HashSet, env, path::Path};
7+
use std::{collections::HashSet, env, path::Path, sync::mpsc};
88
use tokio::prelude::*;
99

1010
#[derive(Serialize, Deserialize, Debug)]
@@ -24,7 +24,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2424
.unwrap_or_else(|| "ws://192.168.1.132:4984/demo/".to_string());
2525
let token: Option<String> = env::args().nth(3);
2626

27-
use_c4_civet_web_socket_factory();
27+
use_web_sockets(runtime.handle().clone());
2828
let (db_thread, db_exec) = run_db_thread(db_path);
2929
let db_exec_repl = db_exec.clone();
3030
db_exec.spawn(move |db| {
@@ -56,11 +56,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
5656
}
5757
});
5858

59-
let db_exec2 = db_exec.clone();
59+
let db_exec_repl = db_exec.clone();
6060
db_exec.spawn(move |db| {
6161
if let Some(db) = db.as_mut() {
6262
db.register_observer(move || {
63-
db_exec2
63+
db_exec_repl
6464
.spawn(|db| print_external_changes(db).expect("read external changes failed"));
6565
})
6666
.expect("register observer failed");
@@ -69,10 +69,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6969
}
7070
});
7171

72-
let db_exec3 = db_exec.clone();
7372
let mut stdin = tokio::io::BufReader::new(tokio::io::stdin());
7473
static EDIT_PREFIX: &'static str = "edit ";
7574

75+
let db_exec_repl = db_exec.clone();
7676
runtime.block_on(async move {
7777
let mut buf = String::new();
7878
let mut edit_id = None;
@@ -84,7 +84,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
8484
let msg = &buf;
8585
let msg = msg.trim_end();
8686
if !msg.is_empty() {
87-
if msg.starts_with(EDIT_PREFIX) {
87+
if msg == "quit" {
88+
println!("Time to quit");
89+
break;
90+
} else if msg.starts_with(EDIT_PREFIX) {
8891
edit_id = Some((&msg[EDIT_PREFIX.len()..]).to_string());
8992
println!("ready to edit message {:?}", edit_id);
9093
} else {
@@ -93,7 +96,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
9396
{
9497
let msg = msg.to_string();
9598
let edit_id = edit_id.take();
96-
db_exec.spawn(move |db| {
99+
db_exec_repl.spawn(move |db| {
97100
if let Some(mut db) = db.as_mut() {
98101
save_msg(&mut db, &msg, edit_id.as_ref().map(String::as_str))
99102
.expect("save to db failed");
@@ -108,14 +111,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
108111
}
109112
});
110113

111-
db_exec3.spawn(|db| {
114+
db_exec.spawn(|db| {
112115
if let Some(db) = db.as_mut() {
113116
db.clear_observers();
117+
db.stop_replicator();
114118
} else {
115119
eprintln!("db is NOT open");
116120
}
117121
});
118-
drop(db_exec3);
122+
drop(db_exec);
119123
db_thread.join().unwrap();
120124
println!("exiting");
121125
Ok(())
@@ -125,7 +129,7 @@ type Job<T> = Box<dyn FnOnce(&mut Option<T>) + Send>;
125129

126130
#[derive(Clone)]
127131
struct DbQueryExecutor {
128-
inner: std::sync::mpsc::Sender<Job<Database>>,
132+
inner: mpsc::Sender<Job<Database>>,
129133
}
130134

131135
impl DbQueryExecutor {

ci/build_and_run_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ def build_and_test_cpp_part(src_root: str):
3535
check_call(["ls"], cwd = cmake_build_dir)
3636
check_call(["cmake", "--build", ".", "--", "-j%d" % (cpu_count() + 1)],
3737
cwd = cmake_build_dir)
38+
os.environ["LiteCoreTestsQuiet"] = "1"
39+
check_call(["./CppTests", "-r", "list"], cwd = os.path.join(cmake_build_dir, "LiteCore", "tests"))
40+
check_call(["./C4Tests", "-r", "list"], cwd = os.path.join(cmake_build_dir, "C", "tests"))
41+
3842

3943
@show_timing
4044
def build_and_test_rust_part(src_root: str):

couchbase-lite-core-sys/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ edition = "2018"
88

99
[build-dependencies]
1010
cmake = "0.1.42"
11-
bindgen = "0.52.0"
12-
cc = "1.0.48"
11+
bindgen = "0.53.2"
12+
cc = "1.0.53"

couchbase-lite-core-sys/build.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::{
99
fn main() {
1010
let dst = cmake::Config::new(Path::new("couchbase-lite-core"))
1111
.define("DISABLE_LTO_BUILD", "True")
12+
.define("SANITIZE_FOR_DEBUG_ENABLED", "False")
1213
.build_target("LiteCore")
1314
.build()
1415
.join("build");
@@ -80,6 +81,7 @@ fn main() {
8081
.join("fleece")
8182
.join("API"),
8283
Path::new("couchbase-lite-core").into(),
84+
Path::new(".").into(),
8385
];
8486
let target = getenv_unwrap("TARGET");
8587
let mut framework_dirs = vec![];
@@ -99,11 +101,23 @@ fn main() {
99101
"fleece/FLSlice.h",
100102
"c4Document+Fleece.h",
101103
"fleece/Fleece.h",
102-
"Replicator/CivetWebSocket.hh",
104+
"couch_lite_log_retrans.hpp",
103105
],
104106
&out_dir.join("c4_header.rs"),
105107
)
106108
.expect("bindgen failed");
109+
110+
let mut cc_builder = cc::Build::new();
111+
112+
for inc in &includes {
113+
cc_builder.include(inc);
114+
}
115+
116+
cc_builder
117+
.cpp(true)
118+
.flag_if_supported("-std=c++11")
119+
.file("couch_lite_log_retrans.cpp")
120+
.compile("couch_lite_log_retrans");
107121
}
108122

109123
/// Convert something like
@@ -154,6 +168,7 @@ fn run_bindgen_for_c_headers<P: AsRef<Path>>(
154168
.header(c_file_path.to_str().unwrap())
155169
.generate_comments(false)
156170
.prepend_enum_name(true)
171+
.size_t_is_usize(true)
157172
.rustfmt_bindings(false);
158173
bindings = include_dirs.iter().fold(bindings, |acc, x| {
159174
acc.clang_arg("-I".to_string() + x.as_ref().to_str().unwrap())
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <atomic>
2+
3+
#include "couch_lite_log_retrans.hpp"
4+
5+
6+
static std::atomic<C4LogCallbackR> g_rust_log_callback{nullptr};
7+
8+
static void rust_log_callback(C4LogDomain d, C4LogLevel l,
9+
const char *fmt C4NONNULL, va_list) {
10+
C4LogCallbackR rust_log_callback = g_rust_log_callback.load(std::memory_order_relaxed);
11+
if (rust_log_callback != nullptr) {
12+
rust_log_callback(d, l, fmt);
13+
}
14+
}
15+
16+
void c4log_setRustCallback(C4LogLevel level, C4LogCallbackR callback) noexcept {
17+
g_rust_log_callback.store(callback, std::memory_order_relaxed);
18+
c4log_writeToCallback(level, rust_log_callback, true);
19+
}
20+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include "c4Base.h"
4+
5+
#ifdef __cplusplus
6+
extern "C" {
7+
#endif
8+
9+
typedef void (*C4LogCallbackR)(C4LogDomain, C4LogLevel, const char *msg C4NONNULL);
10+
11+
void c4log_setRustCallback(C4LogLevel level, C4LogCallbackR callback) C4API;
12+
13+
#ifdef __cplusplus
14+
}
15+
#endif

0 commit comments

Comments
 (0)