Skip to content

Commit 1f7f6c0

Browse files
Add support for server events (redis 6) (#87)
* Update to latest redis 6 redismodule.h, no need to use the hacked redismodule.h from RediSearch. * Remove all API calls that use long double, this is because of and issue in bindgen: rust-lang/rust-bindgen#1549 * Added support for server events API. * Remove "static" from global const event id structs so they can be accessed from outside the c code. * cleanup * Use bindgen's parse_callbacks to avoid ugly explicit casts (#88) Co-authored-by: Gavrie Philipson <[email protected]>
1 parent 905e2a5 commit 1f7f6c0

File tree

3 files changed

+813
-279
lines changed

3 files changed

+813
-279
lines changed

build.rs

+27
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
11
extern crate bindgen;
22
extern crate cc;
33

4+
use bindgen::callbacks::{IntKind, ParseCallbacks};
45
use std::env;
56
use std::path::PathBuf;
67

8+
#[derive(Debug)]
9+
struct RedisModuleCallback;
10+
11+
impl ParseCallbacks for RedisModuleCallback {
12+
fn int_macro(&self, name: &str, _value: i64) -> Option<IntKind> {
13+
if name.starts_with("REDISMODULE_SUBEVENT_") || name.starts_with("REDISMODULE_EVENT_") {
14+
Some(IntKind::U64)
15+
} else if name.starts_with("REDISMODULE_REPLY_")
16+
|| name.starts_with("REDISMODULE_KEYTYPE_")
17+
|| name.starts_with("REDISMODULE_AUX_")
18+
|| name == "REDISMODULE_OK"
19+
|| name == "REDISMODULE_ERR"
20+
{
21+
// These values are used as `enum` discriminants, and thus must be `isize`.
22+
Some(IntKind::Custom {
23+
name: "isize",
24+
is_signed: true,
25+
})
26+
} else {
27+
None
28+
}
29+
}
30+
}
31+
732
fn main() {
833
// Build a Redis pseudo-library so that we have symbols that we can link
934
// against while building Rust code.
@@ -40,6 +65,8 @@ fn main() {
4065
.header("src/include/redismodule.h")
4166
.whitelist_var("(REDIS|Redis).*")
4267
.blacklist_type("__darwin_.*")
68+
.whitelist_type("RedisModule.*")
69+
.parse_callbacks(Box::new(RedisModuleCallback))
4370
.size_t_is_usize(true)
4471
.generate()
4572
.expect("error generating bindings");

0 commit comments

Comments
 (0)