Skip to content

Commit 4edafd0

Browse files
committed
add ROCKSDB_AUXV_GETAUXVAL_PRESENT for supported Linux systems
This lets RocksDB know that getauxval is supported which is needed to enable hardware accelerated crc32c for ARM on Linux
1 parent fd3c716 commit 4edafd0

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

librocksdb-sys/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ tikv-jemalloc-sys = { version = "0.6", features = [
5151
"unprefixed_malloc_on_supported_platforms",
5252
], optional = true }
5353
lz4-sys = { version = "1.10", optional = true }
54-
zstd-sys = { version = "2.0", features = ["zdict_builder", "experimental"], optional = true }
54+
zstd-sys = { version = "2.0", features = [
55+
"zdict_builder",
56+
"experimental",
57+
], optional = true }
5558
libz-sys = { version = "1.1", default-features = false, optional = true }
5659
bzip2-sys = { version = "0.1", default-features = false, optional = true }
5760

@@ -64,3 +67,4 @@ cc = { version = "1.0", features = ["parallel"] }
6467
bindgen = { version = "0.69", default-features = false }
6568
glob = "0.3"
6669
pkg-config = { version = "0.3", optional = true }
70+
libc = "0.2"

librocksdb-sys/build.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use std::path::Path;
22
use std::{env, fs, path::PathBuf, process::Command};
33

4+
#[cfg(target_os = "linux")]
5+
use libc::{getauxval, AT_HWCAP};
6+
47
// On these platforms jemalloc-sys will use a prefixed jemalloc which cannot be linked together
58
// with RocksDB.
69
// See https://github.com/tikv/jemallocator/blob/f7adfca5aff272b43fd3ad896252b57fbbd9c72a/jemalloc-sys/src/env.rs#L24
@@ -50,6 +53,18 @@ fn bindgen_rocksdb() {
5053
.expect("unable to write rocksdb bindings");
5154
}
5255

56+
#[cfg(target_os = "linux")]
57+
fn check_getauxval_supported() -> bool {
58+
unsafe {
59+
let aux_value = getauxval(AT_HWCAP);
60+
if aux_value == 0 {
61+
return false;
62+
}
63+
64+
return true;
65+
}
66+
}
67+
5368
fn build_rocksdb() {
5469
let target = env::var("TARGET").unwrap();
5570

@@ -192,6 +207,11 @@ fn build_rocksdb() {
192207
config.define("ROCKSDB_PLATFORM_POSIX", None);
193208
config.define("ROCKSDB_LIB_IO_POSIX", None);
194209
config.define("ROCKSDB_SCHED_GETCPU_PRESENT", None);
210+
211+
#[cfg(target_os = "linux")]
212+
if check_getauxval_supported() {
213+
config.define("ROCKSDB_AUXV_GETAUXVAL_PRESENT", None);
214+
}
195215
} else if target.contains("dragonfly") {
196216
config.define("OS_DRAGONFLYBSD", None);
197217
config.define("ROCKSDB_PLATFORM_POSIX", None);

0 commit comments

Comments
 (0)