Skip to content

Commit 3e1ac34

Browse files
committed
switch to servo's bindgen and include bindgen as part of the build process
0.9-pre
1 parent db997d1 commit 3e1ac34

File tree

8 files changed

+43
-43
lines changed

8 files changed

+43
-43
lines changed

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
description = "A bindgen-genderated rust wrapper around the Cassandra c++ driver plus working examples\n with no additional dependencies.\nYou probably want to use the \"cassandra\" crate that provides a safe wrapper"
44
license = "Apache-2.0"
55
name = "cassandra-sys"
6-
version = "0.8.8-pre"
6+
version = "0.9.0-pre"
77
authors = ["Tupshin Harper <[email protected]>"]
88
build = "build.rs"
99
homepage = "https://github.com/tupshin/cassandra-sys-rs"
@@ -91,6 +91,10 @@ log = "0.3"
9191
env_logger = "0.3"
9292
error-chain = "0.7"
9393

94+
[build-dependencies.libbindgen]
95+
git = "https://github.com/servo/rust-bindgen"
96+
features = ["llvm_stable"]
97+
9498
# clippy = {version = "*", optional = true}
9599

96100
[features]

build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,20 @@
1414
//use std::path::Path;
1515
//use std::process::Command;
1616

17+
extern crate libbindgen;
18+
19+
use std::env;
20+
use std::path::Path;
21+
22+
1723
fn main() {
24+
let _ = libbindgen::builder()
25+
.header("cassandra.h")
26+
.use_core()
27+
.generate().unwrap()
28+
.write_to_file(Path::new("./src/").join("cassandra.rs"));
29+
30+
1831
if let Some(datastax_dir) = option_env!("CASSANDRA_SYS_LIB_PATH") {
1932
for p in datastax_dir.split(";") {
2033
println!("cargo:rustc-link-search={}", p);
File renamed without changes.

src/examples/schema_meta.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use std::mem;
1111

1212
use cassandra_sys::*;
1313

14-
const CASS_UUID_STRING_LENGTH: usize = 37;
15-
1614
fn print_indent(indent: u32) {
1715
for _ in 0..indent {
1816
print!("\t");
@@ -25,7 +23,7 @@ unsafe fn print_schema_value(value: &CassValue) {
2523
let mut d: f64 = mem::zeroed();
2624
// let mut s:CassString=mem::zeroed();
2725
let mut u: CassUuid = mem::zeroed();
28-
let mut us: [i8; CASS_UUID_STRING_LENGTH] = mem::zeroed();
26+
let mut us: [i8; CASS_UUID_STRING_LENGTH as usize] = mem::zeroed();
2927

3028
match cass_value_type(value) {
3129
CASS_VALUE_TYPE_INT => {

src/examples/udt.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ use std::ffi::CString;
99
use std::mem;
1010
use cassandra_sys::*;
1111

12-
const CASS_UUID_STRING_LENGTH: usize = 37;
13-
1412
fn insert_into_udt(session: &mut CassSession, schema_meta: &CassSchemaMeta, uuid_gen: &mut CassUuidGen)
1513
-> Result<(), CassError> {
1614
unsafe {
17-
let mut id_str: [i8; CASS_UUID_STRING_LENGTH] = [0; CASS_UUID_STRING_LENGTH];
15+
let mut id_str: [i8; CASS_UUID_STRING_LENGTH as usize] = [0; CASS_UUID_STRING_LENGTH as usize];
1816

1917
let query = "INSERT INTO examples.udt (id, address) VALUES (?, ?)";
2018

@@ -100,7 +98,7 @@ fn select_from_udt(session: &mut CassSession) -> Result<(), CassError> {
10098
let rows = cass_iterator_from_result(result);
10199

102100
while cass_iterator_next(rows) == cass_true {
103-
let mut id_str: [i8; CASS_UUID_STRING_LENGTH] = [0; CASS_UUID_STRING_LENGTH];
101+
let mut id_str: [i8; CASS_UUID_STRING_LENGTH as usize] = [0; CASS_UUID_STRING_LENGTH as usize];
104102
let row = cass_iterator_get_row(rows);
105103
let id_value = cass_row_get_column_by_name(row, CString::new("id").unwrap().as_ptr());
106104
let address_value = cass_row_get_column_by_name(row, CString::new("address").unwrap().as_ptr());

src/examples/uuid.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ use std::str;
1414

1515
use cassandra_sys::*;
1616

17-
const CASS_UUID_STRING_LENGTH: usize = 37;
18-
1917
fn insert_into_log(session: &mut CassSession, key: &str, time: CassUuid, entry: &str) -> Result<(), CassError> {
2018
unsafe {
2119
let query = "INSERT INTO examples.log (key, time, entry) VALUES (?, ?, ?);";
@@ -69,7 +67,7 @@ fn select_from_log(session: &mut CassSession, key: &str) -> Result<(), CassError
6967
let mut time: CassUuid = mem::zeroed();
7068
let mut entry = mem::zeroed();
7169
let mut entry_length = mem::zeroed();
72-
let mut time_str: [i8; CASS_UUID_STRING_LENGTH] = [0; CASS_UUID_STRING_LENGTH];
70+
let mut time_str: [i8; CASS_UUID_STRING_LENGTH as usize] = [0; CASS_UUID_STRING_LENGTH as usize];
7371

7472
cass_value_get_string(cass_row_get_column(row, 0),
7573
&mut CString::new(key).unwrap().as_ptr(),

src/ffi_util.rs

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,21 @@ pub unsafe fn raw2utf8(data: *const i8, length: usize) -> Result<String, Utf8Err
1212
Ok(try!(str::from_utf8(slice)).to_owned())
1313
}
1414

15-
impl PartialEq for cass_bool_t {
16-
fn eq(&self, other: &cass_bool_t) -> bool {
17-
let s: bool = self.clone().into();
18-
s == other.clone().into()
19-
}
20-
}
21-
22-
impl PartialEq for CassValueType_ {
23-
fn eq(&self, other: &CassValueType_) -> bool {
24-
self == other
25-
}
26-
}
27-
28-
impl Into<bool> for cass_bool_t {
29-
fn into(self) -> bool {
30-
match self {
31-
cass_bool_t::cass_true => true,
32-
cass_bool_t::cass_false => false,
33-
}
34-
}
35-
}
36-
37-
impl From<bool> for cass_bool_t {
38-
fn from(b: bool) -> Self {
39-
if b {
40-
cass_bool_t::cass_true
41-
} else {
42-
cass_bool_t::cass_false
43-
}
44-
}
45-
}
15+
//impl Into<bool> for cass_bool_t {
16+
// fn into(self) -> bool {
17+
// match self {
18+
// cass_bool_t::cass_true => true,
19+
// cass_bool_t::cass_false => false,
20+
// }
21+
// }
22+
//}
23+
//
24+
//impl From<bool> for cass_bool_t {
25+
// fn from(b: bool) -> Self {
26+
// if b {
27+
// cass_bool_t::cass_true
28+
// } else {
29+
// cass_bool_t::cass_false
30+
// }
31+
// }
32+
//}

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
#![allow(non_camel_case_types)]
23
#![allow(non_upper_case_globals)]
34
#![cfg_attr(feature="clippy", feature(plugin))]
@@ -6,6 +7,7 @@
67
#[macro_use]
78
extern crate log;
89
extern crate libc;
10+
extern crate core;
911
#[macro_use]
1012
extern crate error_chain;
1113
mod errors {
@@ -17,7 +19,7 @@ mod error;
1719

1820
pub use ffi_util::*;
1921

20-
pub use cassandra::cass_bool_t::{cass_true, cass_false};
22+
//pub use cassandra::cass_bool_t::{cass_true, cass_false};
2123

2224
pub use cassandra::CassError_::*;
2325
pub use cassandra::CassSslVerifyFlags::*;

0 commit comments

Comments
 (0)