Skip to content

New update script & Documentation cleanup #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 27, 2025
Merged
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
Binary file removed .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
Cargo.lock

.vscode

# MacOS directory conf
.DS_Store
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @doctolib/bics
* @doctolib/bicson
76 changes: 41 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,57 @@

This is a Rust API of [Couchbase Lite][CBL], an embedded NoSQL document database engine with sync.

The crate wraps the [couchbase-lite-C][CBL_C] releases with an idiomatic Rust API.

## Disclaimer

This library is **NOT SUPPORTED BY COUCHBASE**, it was forked from Couchbase Labs' repo [couchbase-lite-rust][CBL_RUST]
and finalized.
It is currently used and maintained by Doctolib.
This library is **NOT SUPPORTED BY COUCHBASE**, it was forked from Couchbase Labs' repo [couchbase-lite-rust][CBL_RUST] and finalized.
It is currently used and maintained by [Doctolib][DOCTOLIB] ([GitHub][DOCTOLIB_GH]).

The supported platforms are Windows, macOS, Linux, Android and iOS.

## Building

### 1. Install LLVM/Clang

In addition to [Rust][RUST], you'll need to install LLVM and Clang, which are required by the
[bindgen][BINDGEN] tool that generates Rust FFI APIs from C headers.
In addition to [Rust][RUST], you'll need to install LLVM and Clang, which are required by the [bindgen][BINDGEN] tool that generates Rust FFI APIs from C headers.
Installation instructions are [here][BINDGEN_INSTALL].

### 2. Couchbase Lite For C
### 2. Build!

```shell
$ cargo build
```

## Maintaining

### Couchbase Lite For C

The Couchbase Lite For C shared library and headers ([Git repo][CBL_C]) are already embedded in this repo.
To upgrade the version, start by replacing all the necessary files in the folder libcblite-3.0.3
They are present in the directory `libcblite`.

For Android there is an extra step: stripping the libraries.
Place your terminal to the root of this repo, then follow the instructions below.
### Upgrade Couchbase Lite C

### 2.1. Download
```shell
$ ./download.sh
```
The different releases can be found in [this page][CBL_DOWNLOAD_PAGE].

### 2.2 Strip
When a new C release is available, a new Rust release must be created. Running the following script will download and setup the libraries locally:

```shell
$ DOCKER_BUILDKIT=1 docker build --file Dockerfile -t strip --output libcblite .
$ ./update_cblite_c.sh -v 3.2.1
```

### 3. Fix The Skanky Hardcoded Paths

Now edit the file `CouchbaseLite/build.rs` and edit the hardcoded paths on lines 32-37.
This tells the crate where to find Couchbase Lite's headers and library, and the Clang libraries.

### 4. Build!
If the script fails on MacOS, you might need to install wget or a recent bash version:

```shell
$ cargo build
$ brew install wget
$ brew install bash
```

### 5. Test
After that, fix the compilation & tests and you can create a pull request.

New C features should also be added to the Rust API at some point.

### Test

**The unit tests must be run single-threaded.** This is because each test case checks for leaks by
counting the number of extant Couchbase Lite objects before and after it runs, and failing if the
Expand All @@ -57,7 +62,7 @@ number increases. That works only if a single test runs at a time.
$ LEAK_CHECK=y cargo test -- --test-threads 1
```

### 6. Sanitizer
### Sanitizer

```shell
$ LSAN_OPTIONS=suppressions=san.supp RUSTFLAGS="-Zsanitizer=address" cargo +nightly test
Expand All @@ -71,31 +76,32 @@ $ LSAN_OPTIONS=suppressions=san.supp RUSTFLAGS="-Zsanitizer=address" cargo +nigh

## Learning

I've copied the doc-comments from the C API into the Rust files. But Couchbase Lite is fairly
complex, so if you're not already familiar with it, you'll want to start by reading through
the [official documentation][CBLDOCS].
[Official Couchbase Lite documentation][CBL_DOCS]

The Rust API is mostly method-for-method compatible with the languages documented there, except
down at the document property level (dictionaries, arrays, etc.) where I haven't yet written
compatible bindings. For those APIs you can check out the document "[Using Fleece][FLEECE]".

(FYI, if you want to see what bindgen's Rust translation of the C API looks like, it's in the file `bindings.rs` in
`build/couchbase-lite-*/out`, where "`*`" will be some hex string. This is super unlikely to be useful unless you want
to work on improving the high-level bindings themselves.)
[C API reference][CBL_API_REFERENCE]

[Using Fleece][FLEECE]

[RUST]: https://www.rust-lang.org

[CBL]: https://www.couchbase.com/products/lite

[CBL_DOWNLOAD_PAGE]: https://www.couchbase.com/downloads/?family=couchbase-lite

[CBL_C]: https://github.com/couchbase/couchbase-lite-C

[CBL_RUST]: https://github.com/couchbaselabs/couchbase-lite-rust

[CBLDOCS]: https://docs.couchbase.com/couchbase-lite/current/introduction.html
[CBL_DOCS]: https://docs.couchbase.com/couchbase-lite/current/introduction.html

[CBL_API_REFERENCE]: https://docs.couchbase.com/mobile/3.2.1/couchbase-lite-c/C/html/modules.html

[FLEECE]: https://github.com/couchbaselabs/fleece/wiki/Using-Fleece

[BINDGEN]: https://rust-lang.github.io/rust-bindgen/

[BINDGEN_INSTALL]: https://rust-lang.github.io/rust-bindgen/requirements.html

[DOCTOLIB]: https://www.doctolib.fr/

[DOCTOLIB_GH]: https://github.com/doctolib
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use std::path::PathBuf;
use std::process::Command;
use fs_extra::dir;

static CBL_INCLUDE_DIR: &str = "libcblite-3.0.3/include";
static CBL_LIB_DIR: &str = "libcblite-3.0.3/lib";
static CBL_INCLUDE_DIR: &str = "libcblite/include";
static CBL_LIB_DIR: &str = "libcblite/lib";

fn main() -> Result<(), Box<dyn Error>> {
generate_bindings()?;
Expand Down
70 changes: 0 additions & 70 deletions download.sh

This file was deleted.

1 change: 0 additions & 1 deletion libcblite

This file was deleted.

Binary file removed libcblite-3.0.3/.DS_Store
Binary file not shown.
Loading