Unverified Commit b2d0f17f authored by Steven Fackler's avatar Steven Fackler
Browse files

Initial sketch of optional bindgen support

parent 869cf7a2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ vendored = ['openssl-src']
libc = "0.2"

[build-dependencies]
bindgen = { version = "0.59", optional = true }
cc = "1.0"
openssl-src = { version = "300", optional = true }
pkg-config = "0.3.9"
+7 −1
Original line number Diff line number Diff line
#![allow(clippy::inconsistent_digit_grouping, clippy::unusual_byte_groupings)]

extern crate autocfg;
#[cfg(feature = "bindgen")]
extern crate bindgen;
extern crate cc;
#[cfg(feature = "vendored")]
extern crate openssl_src;
@@ -12,12 +14,13 @@ use std::collections::HashSet;
use std::env;
use std::ffi::OsString;
use std::path::{Path, PathBuf};

mod cfgs;

mod find_normal;
#[cfg(feature = "vendored")]
mod find_vendored;
#[cfg(feature = "bindgen")]
mod run_bindgen;

#[derive(PartialEq)]
enum Version {
@@ -64,6 +67,9 @@ fn main() {

    let (lib_dir, include_dir) = find_openssl(&target);

    #[cfg(feature = "bindgen")]
    run_bindgen::run(&include_dir);

    if !Path::new(&lib_dir).exists() {
        panic!(
            "OpenSSL library directory does not exist: {}",
+32 −0
Original line number Diff line number Diff line
use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks};
use std::env;
use std::path::{Path, PathBuf};

const INCLUDES: &str = "
#include <openssl/stack.h>
";

pub fn run(include_dir: &Path) {
    let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());

    bindgen::builder()
        .parse_callbacks(Box::new(OpensslCallbacks))
        .ctypes_prefix("::libc")
        .clang_arg("-I")
        .clang_arg(include_dir.display().to_string())
        .header_contents("includes.h", INCLUDES)
        .generate()
        .unwrap()
        .write_to_file(out_dir.join("bindgen.rs"))
        .unwrap();
}

#[derive(Debug)]
struct OpensslCallbacks;

impl ParseCallbacks for OpensslCallbacks {
    // for now we'll continue hand-writing constants
    fn will_parse_macro(&self, _name: &str) -> MacroParsingBehavior {
        MacroParsingBehavior::Ignore
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@ extern crate libc;

use libc::*;

#[cfg(feature = "bindgen")]
include!(concat!(env!("OUT_DIR"), "/bindgen.rs"));

pub use aes::*;
pub use asn1::*;
pub use bio::*;
@@ -44,6 +47,7 @@ pub use sha::*;
pub use srtp::*;
pub use ssl::*;
pub use ssl3::*;
#[cfg(not(feature = "bindgen"))]
pub use stack::*;
pub use tls1::*;
pub use types::*;
@@ -82,6 +86,7 @@ mod sha;
mod srtp;
mod ssl;
mod ssl3;
#[cfg(not(feature = "bindgen"))]
mod stack;
mod tls1;
mod types;
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ v110 = []
v111 = []

vendored = ['ffi/vendored']
bindgen = ['ffi/bindgen']

[dependencies]
bitflags = "1.0"