Skip to content

Commit 1acbc47

Browse files
authored
Setup community edition (#22)
There are two editions of Couchbase Lite C: `enterprise` and `community`. In Doctolib we only use the `enterprise` version, but in order to release this crate on [crates.io](https://crates.io/) it would be beneficial to offer both options. This is the goal of this pull request. The main changes of this pull request are: 1. Two new features in Cargo.toml: `enterprise` & `community`. Exactly one must be selected or the compilation will fail in `build.rs`. 2. All the functionalities that are not available in the `community` edition (encryption & peer-to-peer) are hidden behind the `enterpise` feature. 3. Instead of the `libcblite` folder containing the enterprise lib files, there are now two folders: `libcblite_enterprise` & `libcblite_community`. 4. The file `build.rs` is modified in order to link with the right folder depending on the specified edition. 5. The script `update_cblite_c.sh` is enhanced to run the whole process for both editions. Some smaller changes are also added: 1. A custom pre-commit hook is added to check that both editions build. 2. The GH workflow `rust` is split in two worflows: `build` & `test`. 3. The three workflows `build`, `test` & `clippy` now use matrixes to check both editions. 4. The `c_playground` is modified with the new path of the `enterprise` lib files.
1 parent 9d4d45a commit 1acbc47

File tree

322 files changed

+51987
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

322 files changed

+51987
-228
lines changed

.cargo-husky/hooks/pre-commit

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh -xe
2+
3+
cargo clippy --features=community -- -D warnings
4+
cargo clippy --features=enterprise -- -D warnings
5+
6+
# Check fmt (protip: run 'cargo fmt --all -- --emit files' to apply format locally)
7+
cargo fmt --all -- --check

.github/workflows/build.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Build
2+
3+
on:
4+
push
5+
6+
env:
7+
CARGO_TERM_COLOR: always
8+
LIBCLANG_PATH: /usr/lib/llvm-14/lib/
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-22.04
13+
strategy:
14+
matrix:
15+
version: [community, enterprise]
16+
steps:
17+
- name: Install apt-get
18+
run: sudo apt-get install -y clang llvm
19+
- uses: actions/checkout@v3
20+
- name: Build
21+
run: cargo build --features=${{ matrix.version }} --verbose

.github/workflows/clippy.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
on: push
21
name: Clippy check
32

3+
on: push
4+
45
env:
56
CARGO_TERM_COLOR: always
67
LIBCLANG_PATH: /usr/lib/llvm-14/lib/
78

89
jobs:
910
clippy_check:
1011
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
version: [community, enterprise]
1115
steps:
1216
- uses: actions/checkout@v1
1317
- run: rustup component add clippy
1418
- uses: actions-rs/clippy-check@v1
1519
with:
1620
token: ${{ secrets.GITHUB_TOKEN }}
17-
name: Clippy default
21+
name: Clippy
22+
args: --features=${{ matrix.version }}

.github/workflows/rust.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Test
2+
3+
on:
4+
push
5+
6+
env:
7+
CARGO_TERM_COLOR: always
8+
LIBCLANG_PATH: /usr/lib/llvm-14/lib/
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-22.04
13+
strategy:
14+
matrix:
15+
version: [community, enterprise]
16+
steps:
17+
- name: Install apt-get
18+
run: sudo apt-get install -y clang llvm
19+
- name: Install latest nightly
20+
uses: dtolnay/rust-toolchain@v1
21+
with:
22+
toolchain: nightly
23+
components: rustfmt, clippy
24+
- uses: actions/checkout@v3
25+
- name: Run tests
26+
run: cargo test --features=${{ matrix.version }} --verbose
27+
- name: Run tests (with address sanitizer)
28+
run: LSAN_OPTIONS=suppressions=san.supp RUSTFLAGS="-Zsanitizer=address" cargo +nightly test --features=${{ matrix.version }} --verbose

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "couchbase_lite"
3-
version = "3.2.1-0"
43
# The first three numbers correspond to the Couchbase Lite C release, the fourth number corresponds to the Doctolib release
4+
version = "3.2.1-0"
55
edition = "2021"
66

77
[dependencies]
@@ -13,7 +13,7 @@ regex = "1.10.4"
1313
[dev-dependencies.cargo-husky]
1414
version = "1"
1515
default-features = false # Disable features which are enabled by default
16-
features = ["precommit-hook", "run-cargo-clippy", "run-cargo-fmt"]
16+
features = ["user-hooks"]
1717

1818
[build-dependencies]
1919
bindgen = "0.69.4"
@@ -32,5 +32,7 @@ incremental = false
3232
# See: https://github.com/johnthagen/min-sized-rust
3333

3434
[features]
35-
flaky-test = []
35+
community = []
36+
enterprise = []
37+
3638
unsafe-threads-test = []

Dockerfile

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
1-
FROM --platform=amd64 rust AS build
2-
RUN apt-get update
3-
RUN apt-get -y install clang
4-
RUN mkdir /build
5-
WORKDIR /build
6-
ENV LIBCLANG_PATH=/usr/lib/llvm-11/lib/
7-
ADD Cargo.toml Cargo.toml
8-
ADD build.rs build.rs
9-
ADD libcblite libcblite
10-
ADD src src
11-
RUN cargo c
12-
RUN cargo test -- --test-threads=1
13-
141
FROM --platform=amd64 rust AS strip-stage
2+
ARG DIRNAME
153
RUN apt-get update
164
RUN apt-get -y install binutils binutils-aarch64-linux-gnu
175
RUN mkdir /build
186
WORKDIR /build
19-
ADD libcblite libcblite
20-
RUN strip /build/libcblite/lib/x86_64-linux-android/libcblite.so -o /build/libcblite/lib/x86_64-linux-android/libcblite.stripped.so
21-
RUN strip /build/libcblite/lib/i686-linux-android/libcblite.so -o /build/libcblite/lib/i686-linux-android/libcblite.stripped.so
22-
RUN /usr/aarch64-linux-gnu/bin/strip /build/libcblite/lib/aarch64-linux-android/libcblite.so -o /build/libcblite/lib/aarch64-linux-android/libcblite.stripped.so
23-
RUN /usr/aarch64-linux-gnu/bin/strip /build/libcblite/lib/arm-linux-androideabi/libcblite.so -o /build/libcblite/lib/arm-linux-androideabi/libcblite.stripped.so
24-
RUN strip /build/libcblite/lib/x86_64-pc-windows-gnu/cblite.dll -o /build/libcblite/lib/x86_64-pc-windows-gnu/cblite.stripped.dll
7+
ADD ${DIRNAME} ${DIRNAME}
8+
RUN strip /build/${DIRNAME}/lib/x86_64-linux-android/libcblite.so -o /build/${DIRNAME}/lib/x86_64-linux-android/libcblite.stripped.so
9+
RUN strip /build/${DIRNAME}/lib/i686-linux-android/libcblite.so -o /build/${DIRNAME}/lib/i686-linux-android/libcblite.stripped.so
10+
RUN /usr/aarch64-linux-gnu/bin/strip /build/${DIRNAME}/lib/aarch64-linux-android/libcblite.so -o /build/${DIRNAME}/lib/aarch64-linux-android/libcblite.stripped.so
11+
RUN /usr/aarch64-linux-gnu/bin/strip /build/${DIRNAME}/lib/arm-linux-androideabi/libcblite.so -o /build/${DIRNAME}/lib/arm-linux-androideabi/libcblite.stripped.so
12+
RUN strip /build/${DIRNAME}/lib/x86_64-pc-windows-gnu/cblite.dll -o /build/${DIRNAME}/lib/x86_64-pc-windows-gnu/cblite.stripped.dll
2513

26-
FROM scratch AS strip
27-
COPY --from=strip-stage /build/libcblite/ .
28-
COPY --from=strip-stage /build/libcblite/ .
14+
FROM scratch AS strip
15+
COPY --from=strip-stage /build/${DIRNAME}/ .

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ Installation instructions are [here][BINDGEN_INSTALL].
2020

2121
### 2. Build!
2222

23+
You can use Couchbase Lite C community or entreprise editions:
24+
25+
```shell
26+
$ cargo build --features=enterprise
27+
```
28+
2329
```shell
24-
$ cargo build
30+
$ cargo build --features=community
2531
```
2632

2733
## Maintaining
@@ -68,12 +74,6 @@ $ LEAK_CHECK=y cargo test -- --test-threads 1
6874
$ LSAN_OPTIONS=suppressions=san.supp RUSTFLAGS="-Zsanitizer=address" cargo +nightly test
6975
```
7076

71-
**To diag flaky test**
72-
73-
```shell
74-
$ LSAN_OPTIONS=suppressions=san.supp RUSTFLAGS="-Zsanitizer=address" cargo +nightly test --verbose --features=flaky-test flaky
75-
```
76-
7777
## Learning
7878

7979
[Official Couchbase Lite documentation][CBL_DOCS]

build.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
// - https://rust-lang.github.io/rust-bindgen/tutorial-3.html
2323
// - https://doc.rust-lang.org/cargo/reference/build-scripts.html
2424

25+
#[cfg(all(not(feature = "community"), not(feature = "enterprise")))]
26+
compile_error!("You need to have one the following features activated: community, enterprise");
27+
#[cfg(all(feature = "community", feature = "enterprise"))]
28+
compile_error!("You need to have one the following features activated: community, enterprise");
29+
2530
extern crate bindgen;
2631
extern crate fs_extra;
2732

@@ -32,8 +37,15 @@ use std::path::PathBuf;
3237
use std::process::Command;
3338
use fs_extra::dir;
3439

35-
static CBL_INCLUDE_DIR: &str = "libcblite/include";
36-
static CBL_LIB_DIR: &str = "libcblite/lib";
40+
#[cfg(feature = "community")]
41+
static CBL_INCLUDE_DIR: &str = "libcblite_community/include";
42+
#[cfg(feature = "enterprise")]
43+
static CBL_INCLUDE_DIR: &str = "libcblite_enterprise/include";
44+
45+
#[cfg(feature = "community")]
46+
static CBL_LIB_DIR: &str = "libcblite_community/lib";
47+
#[cfg(feature = "enterprise")]
48+
static CBL_LIB_DIR: &str = "libcblite_enterprise/lib";
3749

3850
fn main() -> Result<(), Box<dyn Error>> {
3951
generate_bindings()?;

c_playground/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.15)
22

33
project(c_playground)
44

5-
include_directories(${CMAKE_SOURCE_DIR}/../libcblite/include)
5+
include_directories(${CMAKE_SOURCE_DIR}/../libcblite_enterprise/include)
66

77
add_executable(Main main.c)
88

9-
target_link_libraries(Main PUBLIC ${CMAKE_SOURCE_DIR}/../libcblite/lib/macos/libcblite.3.dylib)
9+
target_link_libraries(Main PUBLIC ${CMAKE_SOURCE_DIR}/../libcblite_enterprise/lib/macos/libcblite.3.dylib)

0 commit comments

Comments
 (0)