Skip to content

update to bindgen 0.51.0 #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion mbedtls-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ libc = { version = "0.2.0", optional = true }
libz-sys = { version = "1.0.0", optional = true }

[build-dependencies]
bindgen = "0.19.0"
bindgen = "0.51.0"
cmake = "0.1.17"

[features]
Expand Down
118 changes: 81 additions & 37 deletions mbedtls-sys/build/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,60 @@
* option. This file may not be copied, modified, or distributed except
* according to those terms. */

use bindgen;

use std::fs::File;
use std::io::{stderr, Write};
use std::io::Write;

use bindgen;
use bindgen::callbacks::IntKind;

use crate::headers;

#[derive(Debug)]
struct StderrLogger;
struct ParseCallback;

impl bindgen::Logger for StderrLogger {
fn error(&self, msg: &str) {
let _ = writeln!(stderr(), "Bindgen ERROR: {}", msg);
impl bindgen::callbacks::ParseCallbacks for ParseCallback {
fn int_macro(&self, name: &str, _value: i64) -> Option<IntKind> {
if name.starts_with("MBEDTLS_") {
Some(IntKind::Int)
} else {
None
}
}
fn enum_variant_name(
&self,
_enum_name: Option<&str>,
original_variant_name: &str,
_variant_value: bindgen::callbacks::EnumVariantValue,
) -> Option<String> {
if original_variant_name.starts_with("MBEDTLS_") {
Some(
original_variant_name
.trim_start_matches("MBEDTLS_")
.to_string(),
)
} else {
None
}
}
fn warn(&self, msg: &str) {
let _ = writeln!(stderr(), "Bindgen WARNING: {}", msg);

fn item_name(&self, original_item_name: &str) -> Option<String> {
if original_item_name.eq("mbedtls_time_t") {
None
} else if original_item_name.starts_with("mbedtls_") {
Some(
original_item_name
.trim_start_matches("mbedtls_")
.to_string(),
)
} else if original_item_name.starts_with("MBEDTLS_") {
Some(
original_item_name
.trim_start_matches("MBEDTLS_")
.to_string(),
)
} else {
None
}
}
}

Expand All @@ -33,49 +71,55 @@ impl super::BuildConfig {
Ok(for h in headers::enabled_ordered() {
writeln!(f, "#include <mbedtls/{}>", h)?;
})
}).expect("bindgen-input.h I/O error");
})
.expect("bindgen-input.h I/O error");

let include = self.mbedtls_src.join("include");

let logger = StderrLogger;
let mut bindgen = bindgen::Builder::new(header.into_os_string().into_string().unwrap());
let bindings = bindgen
.log(&logger)
.clang_arg("-Dmbedtls_t_udbl=mbedtls_t_udbl;") // bindgen can't handle unused uint128
let bindings = bindgen::Builder::default()
.header(header.into_os_string().into_string().unwrap())
.clang_arg(format!(
"-DMBEDTLS_CONFIG_FILE=<{}>",
self.config_h.to_str().expect("config.h UTF-8 error")
)).clang_arg(format!(
))
.clang_arg(format!(
"-I{}",
include.to_str().expect("include/ UTF-8 error")
)).match_pat(include.to_str().expect("include/ UTF-8 error"))
.match_pat(self.config_h.to_str().expect("config.h UTF-8 error"))
.use_core(true)
))
.use_core()
.derive_debug(false) // buggy :(
.ctypes_prefix(vec!["types".to_owned(), "raw_types".to_owned()])
.remove_prefix("mbedtls_")
.rust_enums(false)
.convert_macros(true)
.macro_int_types(
vec![
"sint",
"sint",
"sint",
"slonglong",
"sint",
"sint",
"sint",
"slonglong",
].into_iter(),
).generate()
.parse_callbacks(Box::new(ParseCallback))
.ctypes_prefix("crate::types::raw_types")
.blacklist_function("strtold")
.blacklist_function("qecvt_r")
.blacklist_function("qecvt")
.blacklist_function("qfcvt_r")
.blacklist_function("qgcvt")
.blacklist_function("qfcvt")
.opaque_type("std::*")
.opaque_type("time_t")
.generate_comments(false)
.prepend_enum_name(false)
.generate()
.expect("bindgen error");

let bindings_rs = self.out_dir.join("bindings.rs");
File::create(&bindings_rs)
.and_then(|mut f| {
f.write_all(br#"
#![allow(nonstandard_style)]
#![allow(unused_imports)]
"#)?;

bindings.write(Box::new(&mut f))?;
f.write_all(b"use crate::types::*;\n") // for FILE, time_t, etc.
}).expect("bindings.rs I/O error");

f.write_all(br#"
// for FILE, time_t, etc.
use crate::types::*;
"#)

})
.expect("bindings.rs I/O error");

let mod_bindings = self.out_dir.join("mod-bindings.rs");
File::create(&mod_bindings)
Expand Down