Skip to content

Commit f89b4f6

Browse files
Nao-risclaude
andauthored
refactor: make enterprise feature additive per Rust conventions (#80)
## Changes Refactored the `community` and `enterprise` features to follow Rust's requirement that cfg flags must be additive. - **Removed** `community` feature - community edition is now the default - **Kept** `enterprise` feature as an additive flag that enables enterprise-only APIs - Updated build.rs, CI workflows, and documentation accordingly ## Motivation Previously, `community` and `enterprise` were mutually exclusive (XOR enforcement), which violates Rust's cfg additivity rules. Since enterprise edition is a strict superset of community (adds encryption, P2P replication, etc.), it should be modeled as an additive feature. ## Usage ```shell cargo build # Community edition (default) cargo build --features=enterprise # Enterprise edition ``` All existing `#[cfg(feature = "enterprise")]` guards remain unchanged - they correctly gate enterprise-only functionality. Co-authored-by: Claude <[email protected]>
1 parent 98d4701 commit f89b4f6

File tree

7 files changed

+45
-27
lines changed

7 files changed

+45
-27
lines changed

.cargo-husky/hooks/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh -xe
22

3-
cargo clippy --features=community -- -D warnings
3+
cargo clippy -- -D warnings
44
cargo clippy --features=enterprise -- -D warnings
55

66
# Check fmt (protip: run 'cargo fmt --all -- --emit files' to apply format locally)

.github/workflows/build.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ jobs:
1212
runs-on: ubuntu-22.04
1313
strategy:
1414
matrix:
15-
version: [community, enterprise]
15+
edition: [community, enterprise]
16+
include:
17+
- edition: community
18+
cargo_flags: ""
19+
- edition: enterprise
20+
cargo_flags: "--features=enterprise"
1621
steps:
1722
- name: Install apt-get
1823
run: sudo apt-get install -y clang llvm
1924
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
2025
- name: Build
21-
run: cargo build --features=${{ matrix.version }} --verbose
26+
run: cargo build ${{ matrix.cargo_flags }} --verbose

.github/workflows/clippy.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
version: [community, enterprise]
13+
edition: [community, enterprise]
14+
include:
15+
- edition: community
16+
cargo_flags: ""
17+
- edition: enterprise
18+
cargo_flags: "--features=enterprise"
1419
steps:
1520
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
1621

@@ -29,4 +34,4 @@ jobs:
2934
shell: bash
3035
run: |
3136
# shellcheck disable=SC2046
32-
cargo clippy --color always --features=${{ matrix.version }}
37+
cargo clippy --color always ${{ matrix.cargo_flags }}

.github/workflows/test.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ jobs:
1212
runs-on: ubuntu-22.04
1313
strategy:
1414
matrix:
15-
version: [community, enterprise]
15+
edition: [community, enterprise]
16+
include:
17+
- edition: community
18+
cargo_flags: ""
19+
- edition: enterprise
20+
cargo_flags: "--features=enterprise"
1621
steps:
1722
- name: Install apt-get
1823
run: sudo apt-get install -y clang llvm
@@ -23,8 +28,8 @@ jobs:
2328
components: rustfmt, clippy
2429
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
2530
- name: Run tests
26-
run: cargo test --features=${{ matrix.version }} --verbose
31+
run: cargo test ${{ matrix.cargo_flags }} --verbose
2732
- name: Run tests with Couchbase Lite C leak check
28-
run: LEAK_CHECK=y cargo test --features=${{ matrix.version }} --verbose -- --test-threads 1
33+
run: LEAK_CHECK=y cargo test ${{ matrix.cargo_flags }} --verbose -- --test-threads 1
2934
- name: Run tests (with address sanitizer)
30-
run: LSAN_OPTIONS=suppressions=san.supp RUSTFLAGS="-Zsanitizer=address" cargo +nightly test --target x86_64-unknown-linux-gnu --features=${{ matrix.version }} --verbose
35+
run: LSAN_OPTIONS=suppressions=san.supp RUSTFLAGS="-Zsanitizer=address" cargo +nightly test --target x86_64-unknown-linux-gnu ${{ matrix.cargo_flags }} --verbose

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ incremental = false
4747
# See: https://github.com/johnthagen/min-sized-rust
4848

4949
[features]
50-
community = []
50+
# Enable this feature for Enterprise edition capabilities:
51+
# - Database encryption
52+
# - P2P replication (local database endpoints)
53+
# - Document property encryption/decryption during replication
54+
# - TLS identity management
5155
enterprise = []
5256

5357
unsafe-threads-test = []

README.md

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

2121
### 2. Build!
2222

23-
There two different editions of Couchbase Lite C: community & enterprise.
23+
There are two different editions of Couchbase Lite C: community & enterprise.
2424
You can find the differences [here][CBL_EDITIONS_DIFF].
2525

26-
When building or declaring this repository as a dependency, you need to specify the edition through a cargo feature:
26+
**By default, the community edition is used.** To enable enterprise features, use the `enterprise` cargo feature:
2727

2828
```shell
29-
$ cargo build --features=community
29+
$ cargo build # Uses community edition
3030
```
3131

3232
```shell
33-
$ cargo build --features=enterprise
33+
$ cargo build --features=enterprise # Uses enterprise edition
3434
```
3535

36+
The enterprise feature is additive and provides additional capabilities:
37+
- Database encryption
38+
- P2P replication (local database endpoints)
39+
- Document property encryption/decryption during replication
40+
- TLS identity management
41+
3642
## Maintaining
3743

3844
### Couchbase Lite For C
@@ -70,14 +76,15 @@ New C features should also be added to the Rust API at some point.
7076
### Test
7177

7278
Tests can be found in the `tests` subdirectory.
73-
Test are run in the GitHub wrokflow `Test`. You can find the commands used there.
79+
Tests are run in the GitHub workflow `Test`. You can find the commands used there.
7480

7581
There are three variations:
7682

7783
### Nominal run
7884

7985
```shell
80-
$ cargo test --features=enterprise
86+
$ cargo test # Tests community edition
87+
$ cargo test --features=enterprise # Tests enterprise edition
8188
```
8289

8390
### Run with Couchbase Lite C leak check
@@ -90,6 +97,7 @@ If this step fails in one of your pull requests, you should look into the `take_
9097
- `reference` just references the pointer, it will increase the ref count of CBL pointers so releasing it will not free the pointer
9198

9299
```shell
100+
$ LEAK_CHECK=y cargo test -- --test-threads 1
93101
$ LEAK_CHECK=y cargo test --features=enterprise -- --test-threads 1
94102
```
95103

build.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@
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!(
27-
"You need to have at least one the following features activated: community, enterprise"
28-
);
29-
#[cfg(all(feature = "community", feature = "enterprise"))]
30-
compile_error!(
31-
"You need to have at most one the following features activated: community, enterprise"
32-
);
33-
3425
extern crate bindgen;
3526
extern crate fs_extra;
3627

@@ -41,12 +32,12 @@ use std::path::PathBuf;
4132
use std::process::Command;
4233
use fs_extra::dir;
4334

44-
#[cfg(feature = "community")]
35+
#[cfg(not(feature = "enterprise"))]
4536
static CBL_INCLUDE_DIR: &str = "libcblite_community/include";
4637
#[cfg(feature = "enterprise")]
4738
static CBL_INCLUDE_DIR: &str = "libcblite_enterprise/include";
4839

49-
#[cfg(feature = "community")]
40+
#[cfg(not(feature = "enterprise"))]
5041
static CBL_LIB_DIR: &str = "libcblite_community/lib";
5142
#[cfg(feature = "enterprise")]
5243
static CBL_LIB_DIR: &str = "libcblite_enterprise/lib";

0 commit comments

Comments
 (0)