Skip to content

Commit

Permalink
Allow using static bindgen feature (rust-rocksdb#939)
Browse files Browse the repository at this point in the history
  • Loading branch information
Congyuwang authored Nov 13, 2024
1 parent 7cf4f8a commit 0a8d973
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 22 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: RocksDB CI

on: [ push, pull_request ]
on: [push, pull_request]
env:
RUST_VERSION: 1.71.1

Expand Down Expand Up @@ -49,7 +49,16 @@ jobs:
- name: Set PKG_CONFIG_PATH
run: echo "PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig" >> $GITHUB_ENV
- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings
run: |
cargo clippy --all-targets --features \
"jemalloc \
io-uring \
valgrind \
mt_static \
rtti \
multi-threaded-cf \
serde1" \
-- -D warnings
audit:
name: Security audit
Expand All @@ -68,7 +77,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
build: [ Linux, macOS, Windows ]
build: [Linux, macOS, Windows]
include:
- build: Linux
os: ubuntu-latest
Expand Down
28 changes: 15 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@ description = "Rust wrapper for Facebook's RocksDB embeddable database"
version = "0.22.0"
edition = "2018"
rust-version = "1.71.1"
authors = ["Tyler Neely <[email protected]>", "David Greenberg <[email protected]>"]
authors = [
"Tyler Neely <[email protected]>",
"David Greenberg <[email protected]>",
]
repository = "https://github.com/rust-rocksdb/rust-rocksdb"
license = "Apache-2.0"
categories = [ "database" ]
categories = ["database"]
keywords = ["database", "embedded", "LSM-tree", "persistence"]
homepage = "https://github.com/rust-rocksdb/rust-rocksdb"
exclude = [
".gitignore",
".travis.yml",
"deploy.sh",
"test/**/*",
]
exclude = [".gitignore", ".travis.yml", "deploy.sh", "test/**/*"]

[workspace]
members = ["librocksdb-sys"]

[features]
default = ["snappy", "lz4", "zstd", "zlib", "bzip2"]
default = ["snappy", "lz4", "zstd", "zlib", "bzip2", "bindgen-runtime"]
jemalloc = ["librocksdb-sys/jemalloc"]
io-uring = ["librocksdb-sys/io-uring"]
valgrind = []
Expand All @@ -34,15 +32,19 @@ bzip2 = ["librocksdb-sys/bzip2"]
rtti = ["librocksdb-sys/rtti"]
multi-threaded-cf = []
serde1 = ["serde"]
bindgen-runtime = ["librocksdb-sys/bindgen-runtime"]
bindgen-static = ["librocksdb-sys/bindgen-static"]

[dependencies]
libc = "0.2"
librocksdb-sys = { path = "librocksdb-sys", version = "0.17.0" }
serde = { version = "1", features = [ "derive" ], optional = true }
librocksdb-sys = { path = "librocksdb-sys", version = "0.17.0", default-features = false, features = [
"static",
] }
serde = { version = "1", features = ["derive"], optional = true }

[dev-dependencies]
trybuild = "<=1.0.89" # trybuild 1.0.90 needs MSRV 1.70
trybuild = "1"
tempfile = "3.1"
pretty_assertions = "1.0"
bincode = "1.3"
serde = { version = "1", features = [ "derive" ] }
serde = { version = "1", features = ["derive"] }
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,20 @@ The feature `mt_static` will request the library to be built with [/MT](https://
flag, which results in library using the static version of the run-time library.
*This can be useful in case there's a conflict in the dependecy tree between different
run-time versions.*

## Switch between static and dynamic linking for bindgen (features `bindgen-static` and `bindgen-runtime`)

The feature `bindgen-runtime` will enable the `runtime` feature of bindgen, which dynamically
links to libclang. This is suitable for most platforms, and is enabled by default.

The feature `bindgen-static` will enable the `static` feature of bindgen, which statically
links to libclang. This is suitable for musllinux platforms, such as Alpine linux.
To build on Alpine linux for example, make these changes to your Cargo.toml:

```toml
[dependencies.rocksdb]
default-features = false
features = ["bindgen-static", "snappy", "lz4", "zstd", "zlib", "bzip2"]
```

Notice that `runtime` and `static` features are mutually exclusive, and won't compile if both enabled.
19 changes: 13 additions & 6 deletions librocksdb-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ name = "librocksdb-sys"
version = "0.17.0+9.0.0"
edition = "2018"
rust-version = "1.71.1"
authors = ["Karl Hobley <[email protected]>", "Arkadiy Paronyan <[email protected]>"]
authors = [
"Karl Hobley <[email protected]>",
"Arkadiy Paronyan <[email protected]>",
]
license = "MIT/Apache-2.0/BSD-3-Clause"
description = "Native bindings to librocksdb"
readme = "README.md"
repository = "https://github.com/rust-rocksdb/rust-rocksdb"
keywords = [ "bindings", "ffi", "rocksdb" ]
categories = [ "api-bindings", "database", "external-ffi-bindings" ]
keywords = ["bindings", "ffi", "rocksdb"]
categories = ["api-bindings", "database", "external-ffi-bindings"]
links = "rocksdb"

[features]
default = [ "static" ]
default = ["static", "bindgen/runtime"]
jemalloc = ["tikv-jemalloc-sys"]
static = ["libz-sys?/static", "bzip2-sys?/static"]
bindgen-runtime = ["bindgen/runtime"]
bindgen-static = ["bindgen/static"]
mt_static = []
io-uring = ["pkg-config"]
snappy = []
Expand All @@ -27,7 +32,9 @@ rtti = []

[dependencies]
libc = "0.2"
tikv-jemalloc-sys = { version = "0.6", features = ["unprefixed_malloc_on_supported_platforms"], optional = true }
tikv-jemalloc-sys = { version = "0.6", features = [
"unprefixed_malloc_on_supported_platforms",
], optional = true }
lz4-sys = { version = "1.10", optional = true }
zstd-sys = { version = "2.0", features = ["zdict_builder"], optional = true }
libz-sys = { version = "1.1", default-features = false, optional = true }
Expand All @@ -38,6 +45,6 @@ uuid = { version = "1.0", features = ["v4"] }

[build-dependencies]
cc = { version = "1.0", features = ["parallel"] }
bindgen = { version = "0.69", default-features = false, features = ["runtime"] }
bindgen = { version = "0.69", default-features = false }
glob = "0.3"
pkg-config = { version = "0.3", optional = true }

0 comments on commit 0a8d973

Please sign in to comment.