Skip to content
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
108 changes: 40 additions & 68 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,41 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v6
- name: Install rust
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.85.0
toolchain: 1.89.0
components: rustfmt
profile: minimal
override: true
- name: Run rustfmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- name: Check formatting
run: |
cargo fmt --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v6
with:
submodules: true
- name: Install rust
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.85.0
components: clippy
profile: minimal
override: true
toolchain: 1.89.0
components: clippy rustfmt
- run: sudo apt update && sudo apt install -y libclang-dev
- name: Run clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all --tests -- -A clippy::upper-case-acronyms -A clippy::missing_safety_doc -D warnings

audit:
name: Security audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

run: |
make clippy

valgrind:
name: valgrind
runs-on: ubuntu-latest
steps:
- run: sudo apt update && sudo apt install -y valgrind libclang-dev
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v6
with:
submodules: true
- name: run test
Expand All @@ -79,7 +61,7 @@ jobs:
- build: Linux
os: ubuntu-22.04
- build: macOS
os: macos-12
os: macos-latest
- build: windows-2022
os: windows-2022
steps:
Expand All @@ -92,67 +74,57 @@ jobs:
remove-dotnet: 'true'
remove-android: 'true'
remove-haskell: 'true'
remove-codeql: 'true'
remove-docker-images: 'true'
- name: Delete huge unnecessary tools folder
if: runner.os == 'Linux'
run: rm -rf /opt/hostedtoolcache
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v6
with:
submodules: true
- name: Install rust
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.85.0
toolchain: 1.89.0
target: ${{ matrix.target }}
profile: minimal
override: true
components: rustfmt
- name: Remove msys64 # Workaround to resolve link error with C:\msys64\mingw64\bin\libclang.dll
if: runner.os == 'Windows'
run: Remove-Item -LiteralPath "C:\msys64\" -Force -Recurse
- name: Install dependencies
if: runner.os == 'Windows'
run: choco install llvm -y
- name: Install libclang-dev
- name: Install dependencies (macOS)
if: runner.os == 'macOS'
run: brew install llvm lld
- name: Install dependencies (Linux)
if: runner.os == 'Linux'
run: sudo apt install libclang-dev
- name: Install jemalloc
if: runner.os == 'Linux'
run: sudo apt install libjemalloc-dev
- name: Install liburing
if: runner.os == 'Linux'
run: sudo apt install liburing-dev
run: sudo apt-get update && sudo apt-get install -y libclang-dev libjemalloc-dev liburing-dev
- name: Debug librocksdb-sys tests
if: runner.os == 'Linux' || runner.os == 'Windows'
run: clang --version && env
- name: Run librocksdb-sys tests
if: runner.os == 'Linux' || runner.os == 'Windows'
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path=librocksdb-sys/Cargo.toml -vvvvv
run: |
cargo test --manifest-path=librocksdb-sys/Cargo.toml -vvvvv
- name: Run rocksdb tests
if: runner.os == 'Linux' || runner.os == 'Windows'
uses: actions-rs/cargo@v1
with:
command: test
run: |
cargo test
- name: Run rocksdb tests (jemalloc)
if: runner.os == 'Linux'
uses: actions-rs/cargo@v1
with:
command: test
args: --features jemalloc
run: |
cargo test --features jemalloc
- name: Run rocksdb tests (io-uring)
if: runner.os == 'Linux'
uses: actions-rs/cargo@v1
with:
command: test
args: --features io-uring
run: |
cargo test --features io-uring
- name: Run rocksdb tests (portable)
if: runner.os == 'Linux' || runner.os == 'macOS'
uses: actions-rs/cargo@v1
with:
command: test
args: --features portable
run: |
cargo test --features portable
- name: Run rocksdb tests (march-native)
if: runner.os == 'Linux'
uses: actions-rs/cargo@v1
with:
command: test
args: --features march-native
run: |
cargo test --features march-native
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
url = https://github.com/lz4/lz4.git
[submodule "librocksdb-sys/zstd"]
path = librocksdb-sys/zstd
url = https://github.com/facebook/zstd
url = https://github.com/facebook/zstd.git
[submodule "librocksdb-sys/zlib"]
path = librocksdb-sys/zlib
url = https://github.com/madler/zlib.git
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ edition = "2024"
authors = ["Tyler Neely <t@jujit.su>", "David Greenberg <dsg123456789@gmail.com>", "Nervos Core Dev <dev@nervos.org>"]
license = "Apache-2.0"
keywords = ["database", "embedded", "LSM-tree", "persistence"]
repository = "https://github.com/nervosnetwork/rust-rocksdb"
repository = "https://github.com/nervosnetwork/ckb-rocksdb"
exclude = [
".gitignore",
"*.yml",
"tests",
"*.md",
"benches",
]
rust-version = "1.85.0"
rust-version = "1.89.0"

[features]
default = ["snappy", "lz4", "zstd", "zlib", "bzip2"]
Expand All @@ -30,6 +30,7 @@ portable = ["librocksdb-sys/portable"]
march-native = ["librocksdb-sys/march-native"]
serde1 = ["serde"]
lto = ["librocksdb-sys/lto"]
rtti = ["librocksdb-sys/rtti"]

[dependencies]
home = "0.5"
Expand All @@ -40,7 +41,7 @@ serde = { version = "1", features = ["derive"], optional = true }

[dev-dependencies]
trybuild = "1.0"
criterion = "0.5"
criterion = "0.7"

[[bench]]
name = "transaction"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
rust-rocksdb
ckb-rocksdb
============
[![Build Status](https://github.com/nervosnetwork/rust-rocksdb/actions/workflows/rust.yml/badge.svg?branch=txn)](https://github.com/nervosnetwork/rust-rocksdb/actions/workflows/rust.yml?query=branch%3Atxn)
[![Build Status](https://github.com/nervosnetwork/ckb-rocksdb/actions/workflows/rust.yml/badge.svg)](https://github.com/nervosnetwork/ckb-rocksdb/actions/workflows/rust.yml?query=branch%3Amaster)
[![crates.io](https://img.shields.io/crates/v/ckb-rocksdb.svg)](https://crates.io/crates/ckb-rocksdb)
[![documentation](https://docs.rs/ckb-rocksdb/badge.svg)](https://docs.rs/ckb-rocksdb)
[![license](https://img.shields.io/crates/l/ckb-rocksdb.svg)](https://github.com/nervosnetwork/rust-rocksdb/blob/txn/LICENSE)
[![license](https://img.shields.io/crates/l/ckb-rocksdb.svg)](https://github.com/nervosnetwork/ckb-rocksdb/blob/master/LICENSE)
[![Discord](https://img.shields.io/badge/chat-on%20Discord-7289DA.svg)](https://discord.com/invite/nervos)


Expand Down
5 changes: 3 additions & 2 deletions librocksdb-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Karl Hobley <karlhobley10@gmail.com>", "Arkadiy Paronyan <arkadiy@et
license = "MIT/Apache-2.0/BSD-3-Clause"
description = "Native bindings to librocksdb"
readme = "README.md"
repository = "https://github.com/nervosnetwork/rust-rocksdb"
repository = "https://github.com/nervosnetwork/ckb-rocksdb"
keywords = [ "ffi", "rocksdb" ]

build = "build.rs"
Expand Down Expand Up @@ -37,6 +37,7 @@ zstd = []
zlib = []
bzip2 = []
lto = []
rtti = []


[dependencies]
Expand All @@ -49,7 +50,7 @@ uuid = { version = "1.0", features = ["v4"] }

[build-dependencies]
cc = { version = "1.0", features = ["parallel"] }
bindgen = { version = "0.71.1", default-features = false }
bindgen = { version = "0.72.1" }
glob = "0.3.2"
pkg-config = "0.3"
rust-ini = "0.21"
67 changes: 48 additions & 19 deletions librocksdb-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ compile_error!("feature 'portable' and feature 'march-native' cannot be enabled

use std::env;
use std::fs;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::Command;

const RUST_TARGET: &str = "1.85.0";
const RUST_TARGET: &str = "1.89.0";
// On these platforms jemalloc-sys will use a prefixed jemalloc which cannot be linked together
// with RocksDB.
// See https://github.com/tikv/jemallocator/blob/tikv-jemalloc-sys-0.5.3/jemalloc-sys/src/env.rs#L25
const NO_JEMALLOC_TARGETS: &[&str] = &["android", "dragonfly", "musl", "darwin"];

fn get_flags_from_detect_platform_script() -> Option<Vec<String>> {
if !cfg!(target_os = "windows") {
Expand Down Expand Up @@ -138,6 +142,10 @@ fn build_rocksdb() {
config.include("bzip2/");
}

if cfg!(feature = "rtti") {
config.define("USE_RTTI", Some("1"));
}

// rust-rocksdb/rust-rocksdb:
// https://github.com/rust-rocksdb/rust-rocksdb/commit/b2dab4a0915eed72741657f783118d9220d4f070
//
Expand All @@ -147,8 +155,8 @@ fn build_rocksdb() {
config.flag("-flto");
if !config.get_compiler().is_like_clang() {
panic!(
"LTO is only supported with clang. Either disable the `lto` feature\
or set `CC=/usr/bin/clang CXX=/usr/bin/clang++` environment variables."
"LTO is only supported with clang. Either disable the `lto` feature \
or set `CC=/usr/bin/clang CXX=/usr/bin/clang++` environment variables."
);
}
}
Expand Down Expand Up @@ -286,25 +294,30 @@ fn build_rocksdb() {
config.flag("-Wno-missing-field-initializers");
config.flag("-Wno-strict-aliasing");
config.flag("-Wno-invalid-offsetof");
}

if cfg!(feature = "jemalloc") {
if let Err(e) = pkg_config::probe_library("jemalloc") {
panic!("pkg_config jemalloc {}", e);
} else {
config.define("ROCKSDB_JEMALLOC", None);
config.define("JEMALLOC_NO_DEMANGLE", None);
}
config.define("ROCKSDB_SUPPORT_THREAD_LOCAL", None);
if target.contains("linux") {
if cfg!(feature = "io-uring") {
pkg_config::probe_library("liburing")
.expect("The io-uring feature was requested but the library is not available");
config.define("ROCKSDB_IOURING_PRESENT", Some("1"));
}
}

if cfg!(feature = "io-uring") {
if let Err(e) = pkg_config::probe_library("liburing") {
panic!("pkg_config liburing {}", e);
} else {
config.define("ROCKSDB_IOURING_PRESENT", None);
}
if cfg!(feature = "jemalloc") && NO_JEMALLOC_TARGETS.iter().all(|i| !target.contains(i)) {
config.define("ROCKSDB_JEMALLOC", Some("1"));
config.define("JEMALLOC_NO_DEMANGLE", Some("1"));
if let Some(jemalloc_root) = env::var_os("DEP_JEMALLOC_ROOT") {
config.include(Path::new(&jemalloc_root).join("include"));
}
}

config.flag_if_supported("-std=c++17");
if !target.contains("windows") {
config.flag("-include").flag("cstdint");
}

for file in lib_sources {
let file = "rocksdb/".to_string() + file;
config.file(&file);
Expand All @@ -315,8 +328,6 @@ fn build_rocksdb() {

config.cpp(true);

config.flag("-include").flag("cstdint");

config.compile("librocksdb.a");
}

Expand Down Expand Up @@ -376,6 +387,8 @@ fn build_zstd() {
compiler.include("zstd/lib/common");
compiler.include("zstd/lib/legacy");

let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();

let globs = &[
"zstd/lib/common/*.c",
"zstd/lib/compress/*.c",
Expand All @@ -391,8 +404,22 @@ fn build_zstd() {
}
}

if target_arch.contains("x86_64") {
if env::var("CARGO_CFG_WINDOWS").is_ok() {
compiler.define("ZSTD_DISABLE_ASM", Some(""));
} else {
compiler.file("zstd/lib/decompress/huf_decompress_amd64.S");
}
} else {
compiler.define("ZSTD_DISABLE_ASM", Some(""));
}

compiler.opt_level(3);
compiler.extra_warnings(false);
compiler
.flag_if_supported("-ffunction-sections")
.flag_if_supported("-fdata-sections")
.flag_if_supported("-fmerge-all-constants");

compiler.define("ZSTD_LIB_DEPRECATED", Some("0"));
compiler.compile("libzstd.a");
Expand Down Expand Up @@ -501,4 +528,6 @@ fn main() {
fail_on_empty_directory("bzip2");
build_bzip2();
}

println!("cargo:out_dir={}", env::var("OUT_DIR").unwrap());
}
Loading