|
1 | 1 | extern crate bindgen; |
2 | 2 | extern crate cc; |
3 | 3 |
|
| 4 | +use std::env; |
| 5 | + |
4 | 6 | fn main() { |
5 | | - // cc::Build::new() |
6 | | - // .file("src/redisearch/redisearch_api.c") |
7 | | - // //.include("src/include/") // For redismodule.h |
8 | | - // .include("src/include/") |
9 | | - // .compile("redisearch_api"); |
| 7 | + // Generate bindings for RediSearch |
10 | 8 |
|
11 | 9 | let bindings = bindgen::Builder::default() |
12 | 10 | .header("src/include/redisearch_api.h") |
13 | 11 | //.clang_arg("-I src/include") // For redismodule.h |
14 | | - .whitelist_var("(RS|RediSearch).*") |
| 12 | + .whitelist_var("(RS|RediSearch|REDISEARCH_|GC_POLICY).*") |
| 13 | + .whitelist_function("RediSearch.*") |
| 14 | + .blacklist_item("RedisModule.*") |
| 15 | + .raw_line("use redismodule::raw::{RedisModuleCtx, RedisModuleString};") |
15 | 16 | .generate() |
16 | 17 | .expect("error generating RediSearch bindings"); |
17 | 18 |
|
18 | 19 | bindings |
19 | 20 | .write_to_file("src/raw/bindings.rs") |
20 | 21 | .expect("failed to write RediSearch bindings to file"); |
| 22 | + |
| 23 | + // Find and link statically to libredisearch.a |
| 24 | + |
| 25 | + // TODO: Instead of relying on a pre-built library, |
| 26 | + // we should build RediSearch as a static lib, like this: |
| 27 | + // |
| 28 | + // mkdir -p build |
| 29 | + // cd build |
| 30 | + // cmake -DRS_BUILD_STATIC=ON .. |
| 31 | + // make |
| 32 | + // |
| 33 | + // Take a look at some `-sys` crates for system library wrappers, and build using the |
| 34 | + // same methods that they use. |
| 35 | + // In fact, consider splitting this crate into a `-sys` crate for the low level wrappers |
| 36 | + // and another one for the high-level bindings. |
| 37 | + |
| 38 | + let lib_search_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); |
| 39 | + println!("cargo:rustc-link-search=native={}", lib_search_dir); |
| 40 | + println!("cargo:rustc-link-lib=static=redisearch"); |
21 | 41 | } |
0 commit comments