Skip to content

Commit fb6cfb9

Browse files
Congyuwangzaidoon1
authored andcommitted
Allow using static bindgen feature (#939)
1 parent a9c284f commit fb6cfb9

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

.github/workflows/rust.yml

+17-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,24 @@ jobs:
4545
with:
4646
components: clippy
4747

48+
- name: Install dependencies
49+
run: sudo apt-get update && sudo apt-get install -y liburing-dev pkg-config
50+
- name: Set PKG_CONFIG_PATH
51+
run: echo "PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig" >> $GITHUB_ENV
52+
4853
- name: Run clippy
49-
run: cargo clippy --all --all-targets -- -Dwarnings
54+
run: |
55+
cargo clippy --all-targets --features \
56+
"jemalloc \
57+
io-uring \
58+
valgrind \
59+
mt_static \
60+
rtti \
61+
multi-threaded-cf \
62+
malloc-usable-size \
63+
zstd-static-linking-only \
64+
serde1" \
65+
-- -D warnings
5066
5167
audit:
5268
name: Security audit

Cargo.toml

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ exclude = [".gitignore", ".travis.yml", "deploy.sh", "test/**/*"]
1919
members = ["librocksdb-sys"]
2020

2121
[features]
22-
default = ["snappy", "lz4", "zstd", "zlib", "bzip2"]
22+
default = ["snappy", "lz4", "zstd", "zlib", "bzip2", "bindgen-runtime"]
2323
jemalloc = ["rust-librocksdb-sys/jemalloc"]
2424
io-uring = ["rust-librocksdb-sys/io-uring"]
2525
valgrind = []
@@ -34,10 +34,14 @@ multi-threaded-cf = []
3434
serde1 = ["serde"]
3535
malloc-usable-size = ["rust-librocksdb-sys/malloc-usable-size"]
3636
zstd-static-linking-only = ["rust-librocksdb-sys/zstd-static-linking-only"]
37+
bindgen-runtime = ["rust-librocksdb-sys/bindgen-runtime"]
38+
bindgen-static = ["rust-librocksdb-sys/bindgen-static"]
3739

3840
[dependencies]
3941
libc = "0.2"
40-
rust-librocksdb-sys = { path = "librocksdb-sys", version = "0.29.0" }
42+
rust-librocksdb-sys = { path = "librocksdb-sys", version = "0.29.0", default-features = false, features = [
43+
"static",
44+
] }
4145
serde = { version = "1", features = ["derive"], optional = true }
4246

4347
[dev-dependencies]

README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,22 @@ compression will cause Rocksdb to hold digested dictionaries in block cache to
111111
save repetitive deserialization overhead. This saves a lot of CPU for read-heavy
112112
workloads. This feature is gated behind a flag in Rocksdb because one of the
113113
digested dictionary APIs used is marked as experimental. However, this feature
114-
is still used at facebook in production per the [Preset Dictionary Compression Blog Post](https://rocksdb.org/blog/2021/05/31/dictionary-compression.html).
114+
is still used at facebook in production per the [Preset Dictionary Compression
115+
Blog Post](https://rocksdb.org/blog/2021/05/31/dictionary-compression.html).
116+
117+
### Switch between static and dynamic linking for bindgen (features `bindgen-static` and `bindgen-runtime`)
118+
119+
The feature `bindgen-runtime` will enable the `runtime` feature of bindgen, which dynamically
120+
links to libclang. This is suitable for most platforms, and is enabled by default.
121+
122+
The feature `bindgen-static` will enable the `static` feature of bindgen, which statically
123+
links to libclang. This is suitable for musllinux platforms, such as Alpine linux.
124+
To build on Alpine linux for example, make these changes to your Cargo.toml:
125+
126+
```toml
127+
[dependencies.rocksdb]
128+
default-features = false
129+
features = ["bindgen-static", "snappy", "lz4", "zstd", "zlib", "bzip2"]
130+
```
131+
132+
Notice that `runtime` and `static` features are mutually exclusive, and won't compile if both enabled.

librocksdb-sys/Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ exclude = [
2828
]
2929

3030
[features]
31-
default = ["static"]
31+
default = ["static", "bindgen/runtime"]
3232
jemalloc = ["tikv-jemalloc-sys"]
3333
static = ["libz-sys?/static", "bzip2-sys?/static"]
34+
bindgen-runtime = ["bindgen/runtime"]
35+
bindgen-static = ["bindgen/static"]
3436
mt_static = []
3537
io-uring = ["pkg-config"]
3638
snappy = []
@@ -58,6 +60,6 @@ uuid = { version = "1", features = ["v4"] }
5860

5961
[build-dependencies]
6062
cc = { version = "1.0", features = ["parallel"] }
61-
bindgen = { version = "0.69", default-features = false, features = ["runtime"] }
63+
bindgen = { version = "0.69", default-features = false }
6264
glob = "0.3"
6365
pkg-config = { version = "0.3", optional = true }

0 commit comments

Comments
 (0)