Skip to content

Commit a148760

Browse files
author
Jethro Beekman
committed
rustfmt
1 parent 83b2cc2 commit a148760

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4583
-3816
lines changed

mbedtls-sys/build/bindgen.rs

Lines changed: 64 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,85 @@
11
/* Copyright (c) Fortanix, Inc.
22
*
3-
* Licensed under the GNU General Public License, version 2 <LICENSE-GPL or
4-
* https://www.gnu.org/licenses/gpl-2.0.html> or the Apache License, Version
5-
* 2.0 <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>, at your
6-
* option. This file may not be copied, modified, or distributed except
3+
* Licensed under the GNU General Public License, version 2 <LICENSE-GPL or
4+
* https://www.gnu.org/licenses/gpl-2.0.html> or the Apache License, Version
5+
* 2.0 <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>, at your
6+
* option. This file may not be copied, modified, or distributed except
77
* according to those terms. */
88

99
use bindgen;
1010

1111
use std::fs::File;
12-
use std::io::{stderr,Write};
12+
use std::io::{stderr, Write};
1313

1414
use headers;
1515

1616
#[derive(Debug)]
1717
struct StderrLogger;
1818

1919
impl bindgen::Logger for StderrLogger {
20-
fn error(&self, msg: &str) { let _=writeln!(stderr(),"Bindgen ERROR: {}",msg); }
21-
fn warn(&self, msg: &str) { let _=writeln!(stderr(),"Bindgen WARNING: {}",msg); }
20+
fn error(&self, msg: &str) {
21+
let _ = writeln!(stderr(), "Bindgen ERROR: {}", msg);
22+
}
23+
fn warn(&self, msg: &str) {
24+
let _ = writeln!(stderr(), "Bindgen WARNING: {}", msg);
25+
}
2226
}
2327

2428
impl super::BuildConfig {
25-
pub fn bindgen(&self) {
26-
let header=self.out_dir.join("bindgen-input.h");
27-
File::create(&header).and_then(|mut f|Ok(
28-
for h in headers::enabled_ordered() {
29-
try!(writeln!(f,"#include <mbedtls/{}>",h));
30-
}
31-
)).expect("bindgen-input.h I/O error");
29+
pub fn bindgen(&self) {
30+
let header = self.out_dir.join("bindgen-input.h");
31+
File::create(&header)
32+
.and_then(|mut f| {
33+
Ok(for h in headers::enabled_ordered() {
34+
try!(writeln!(f, "#include <mbedtls/{}>", h));
35+
})
36+
}).expect("bindgen-input.h I/O error");
3237

33-
let include=self.mbedtls_src.join("include");
34-
35-
let logger=StderrLogger;
36-
let mut bindgen=bindgen::Builder::new(header.into_os_string().into_string().unwrap());
37-
let bindings=bindgen
38-
.log(&logger)
39-
.clang_arg("-Dmbedtls_t_udbl=mbedtls_t_udbl;") // bindgen can't handle unused uint128
40-
.clang_arg(format!("-DMBEDTLS_CONFIG_FILE=<{}>",self.config_h.to_str().expect("config.h UTF-8 error")))
41-
.clang_arg(format!("-I{}",include.to_str().expect("include/ UTF-8 error")))
42-
.match_pat(include.to_str().expect("include/ UTF-8 error"))
43-
.match_pat(self.config_h.to_str().expect("config.h UTF-8 error"))
44-
.use_core(true)
45-
.derive_debug(false) // buggy :(
46-
.ctypes_prefix(vec!["types".to_owned(),"raw_types".to_owned()])
47-
.remove_prefix("mbedtls_")
48-
.rust_enums(false)
49-
.convert_macros(true)
50-
.macro_int_types(vec!["sint","sint","sint","slonglong","sint","sint","sint","slonglong"].into_iter())
51-
.generate().expect("bindgen error");
38+
let include = self.mbedtls_src.join("include");
5239

53-
let bindings_rs=self.out_dir.join("bindings.rs");
54-
File::create(&bindings_rs).and_then(|mut f|{
55-
try!(bindings.write(Box::new(&mut f)));
56-
f.write_all(b"use ::types::*;\n") // for FILE, time_t, etc.
57-
}).expect("bindings.rs I/O error");
40+
let logger = StderrLogger;
41+
let mut bindgen = bindgen::Builder::new(header.into_os_string().into_string().unwrap());
42+
let bindings = bindgen
43+
.log(&logger)
44+
.clang_arg("-Dmbedtls_t_udbl=mbedtls_t_udbl;") // bindgen can't handle unused uint128
45+
.clang_arg(format!(
46+
"-DMBEDTLS_CONFIG_FILE=<{}>",
47+
self.config_h.to_str().expect("config.h UTF-8 error")
48+
)).clang_arg(format!(
49+
"-I{}",
50+
include.to_str().expect("include/ UTF-8 error")
51+
)).match_pat(include.to_str().expect("include/ UTF-8 error"))
52+
.match_pat(self.config_h.to_str().expect("config.h UTF-8 error"))
53+
.use_core(true)
54+
.derive_debug(false) // buggy :(
55+
.ctypes_prefix(vec!["types".to_owned(), "raw_types".to_owned()])
56+
.remove_prefix("mbedtls_")
57+
.rust_enums(false)
58+
.convert_macros(true)
59+
.macro_int_types(
60+
vec![
61+
"sint",
62+
"sint",
63+
"sint",
64+
"slonglong",
65+
"sint",
66+
"sint",
67+
"sint",
68+
"slonglong",
69+
].into_iter(),
70+
).generate()
71+
.expect("bindgen error");
5872

59-
let mod_bindings=self.out_dir.join("mod-bindings.rs");
60-
File::create(&mod_bindings).and_then(|mut f|
61-
f.write_all(b"mod bindings;\n")
62-
).expect("mod-bindings.rs I/O error");
63-
}
73+
let bindings_rs = self.out_dir.join("bindings.rs");
74+
File::create(&bindings_rs)
75+
.and_then(|mut f| {
76+
try!(bindings.write(Box::new(&mut f)));
77+
f.write_all(b"use ::types::*;\n") // for FILE, time_t, etc.
78+
}).expect("bindings.rs I/O error");
79+
80+
let mod_bindings = self.out_dir.join("mod-bindings.rs");
81+
File::create(&mod_bindings)
82+
.and_then(|mut f| f.write_all(b"mod bindings;\n"))
83+
.expect("mod-bindings.rs I/O error");
84+
}
6485
}

mbedtls-sys/build/build.rs

Lines changed: 83 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,114 @@
11
/* Copyright (c) Fortanix, Inc.
22
*
3-
* Licensed under the GNU General Public License, version 2 <LICENSE-GPL or
4-
* https://www.gnu.org/licenses/gpl-2.0.html> or the Apache License, Version
5-
* 2.0 <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>, at your
6-
* option. This file may not be copied, modified, or distributed except
3+
* Licensed under the GNU General Public License, version 2 <LICENSE-GPL or
4+
* https://www.gnu.org/licenses/gpl-2.0.html> or the Apache License, Version
5+
* 2.0 <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>, at your
6+
* option. This file may not be copied, modified, or distributed except
77
* according to those terms. */
88

99
extern crate bindgen;
1010
extern crate cmake;
1111

1212
mod config;
1313
mod headers;
14-
#[path="cmake.rs"]
15-
mod mod_cmake;
16-
#[path="bindgen.rs"]
14+
#[path = "bindgen.rs"]
1715
mod mod_bindgen;
16+
#[path = "cmake.rs"]
17+
mod mod_cmake;
1818

1919
use std::collections::HashMap;
20-
use std::path::{Path,PathBuf};
2120
use std::env;
2221
use std::fs::File;
2322
use std::io::Write;
23+
use std::path::{Path, PathBuf};
2424

2525
pub fn have_feature(feature: &'static str) -> bool {
26-
env::var_os(format!("CARGO_FEATURE_{}",feature).to_uppercase().replace("-","_")).is_some()
26+
env::var_os(
27+
format!("CARGO_FEATURE_{}", feature)
28+
.to_uppercase()
29+
.replace("-", "_"),
30+
).is_some()
2731
}
2832

2933
struct BuildConfig {
30-
out_dir: PathBuf,
31-
mbedtls_src: PathBuf,
32-
config_h: PathBuf,
34+
out_dir: PathBuf,
35+
mbedtls_src: PathBuf,
36+
config_h: PathBuf,
3337
}
3438

3539
impl BuildConfig {
36-
fn create_config_h(&self) {
37-
let mut defines=config::DEFAULT_DEFINES.iter().cloned().collect::<HashMap<_,_>>();
38-
for &(feat,def) in config::FEATURE_DEFINES {
39-
if have_feature(feat) {
40-
defines.insert(def.0,def.1);
41-
}
42-
}
43-
44-
File::create(&self.config_h).and_then(|mut f|{
45-
try!(f.write_all(config::PREFIX.as_bytes()));
46-
for (name,def) in defines {
47-
try!(f.write_all(def.define(name).as_bytes()));
48-
}
49-
if have_feature("custom_printf") {
50-
try!(writeln!(f,"int mbedtls_printf(const char *format, ...);"));
51-
}
52-
if have_feature("custom_has_support") {
53-
try!(writeln!(f,"int mbedtls_aesni_has_support( unsigned int what ) __attribute__((weak));"));
54-
try!(writeln!(f,"int mbedtls_padlock_has_support( int feature ) __attribute__((weak));"));
55-
}
56-
if have_feature("custom_threading") {
57-
try!(writeln!(f,"typedef void* mbedtls_threading_mutex_t;"));
58-
}
59-
f.write_all(config::SUFFIX.as_bytes())
60-
}).expect("config.h I/O error");
61-
}
40+
fn create_config_h(&self) {
41+
let mut defines = config::DEFAULT_DEFINES
42+
.iter()
43+
.cloned()
44+
.collect::<HashMap<_, _>>();
45+
for &(feat, def) in config::FEATURE_DEFINES {
46+
if have_feature(feat) {
47+
defines.insert(def.0, def.1);
48+
}
49+
}
50+
51+
File::create(&self.config_h)
52+
.and_then(|mut f| {
53+
try!(f.write_all(config::PREFIX.as_bytes()));
54+
for (name, def) in defines {
55+
try!(f.write_all(def.define(name).as_bytes()));
56+
}
57+
if have_feature("custom_printf") {
58+
try!(writeln!(f, "int mbedtls_printf(const char *format, ...);"));
59+
}
60+
if have_feature("custom_has_support") {
61+
try!(writeln!(
62+
f,
63+
"int mbedtls_aesni_has_support( unsigned int what ) __attribute__((weak));"
64+
));
65+
try!(writeln!(
66+
f,
67+
"int mbedtls_padlock_has_support( int feature ) __attribute__((weak));"
68+
));
69+
}
70+
if have_feature("custom_threading") {
71+
try!(writeln!(f, "typedef void* mbedtls_threading_mutex_t;"));
72+
}
73+
f.write_all(config::SUFFIX.as_bytes())
74+
}).expect("config.h I/O error");
75+
}
6276

63-
fn print_rerun_files(&self) {
77+
fn print_rerun_files(&self) {
6478
println!("cargo:rerun-if-env-changed=RUST_MBEDTLS_SYS_SOURCE");
65-
println!("cargo:rerun-if-changed={}",self.mbedtls_src.join("CMakeLists.txt").display());
66-
let include=self.mbedtls_src.join(Path::new("include").join("mbedtls"));
79+
println!(
80+
"cargo:rerun-if-changed={}",
81+
self.mbedtls_src.join("CMakeLists.txt").display()
82+
);
83+
let include = self.mbedtls_src.join(Path::new("include").join("mbedtls"));
6784
for h in headers::enabled_ordered() {
68-
println!("cargo:rerun-if-changed={}",include.join(h).display());
69-
}
70-
for f in self.mbedtls_src.join("library").read_dir().expect("read_dir failed") {
71-
println!("cargo:rerun-if-changed={}",f.expect("DirEntry failed").path().display());
72-
}
73-
}
85+
println!("cargo:rerun-if-changed={}", include.join(h).display());
86+
}
87+
for f in self
88+
.mbedtls_src
89+
.join("library")
90+
.read_dir()
91+
.expect("read_dir failed")
92+
{
93+
println!(
94+
"cargo:rerun-if-changed={}",
95+
f.expect("DirEntry failed").path().display()
96+
);
97+
}
98+
}
7499
}
75100

76101
fn main() {
77-
let out_dir=PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR environment not set?"));
78-
let src=PathBuf::from(env::var("RUST_MBEDTLS_SYS_SOURCE").unwrap_or("vendor".to_owned()));
79-
let cfg=BuildConfig {
80-
config_h: out_dir.join("config.h"),
81-
out_dir: out_dir,
82-
mbedtls_src: src,
83-
};
102+
let out_dir = PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR environment not set?"));
103+
let src = PathBuf::from(env::var("RUST_MBEDTLS_SYS_SOURCE").unwrap_or("vendor".to_owned()));
104+
let cfg = BuildConfig {
105+
config_h: out_dir.join("config.h"),
106+
out_dir: out_dir,
107+
mbedtls_src: src,
108+
};
84109

85-
cfg.create_config_h();
86-
cfg.print_rerun_files();
87-
cfg.cmake();
88-
cfg.bindgen();
110+
cfg.create_config_h();
111+
cfg.print_rerun_files();
112+
cfg.cmake();
113+
cfg.bindgen();
89114
}

mbedtls-sys/build/cmake.rs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
11
/* Copyright (c) Fortanix, Inc.
22
*
3-
* Licensed under the GNU General Public License, version 2 <LICENSE-GPL or
4-
* https://www.gnu.org/licenses/gpl-2.0.html> or the Apache License, Version
5-
* 2.0 <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>, at your
6-
* option. This file may not be copied, modified, or distributed except
3+
* Licensed under the GNU General Public License, version 2 <LICENSE-GPL or
4+
* https://www.gnu.org/licenses/gpl-2.0.html> or the Apache License, Version
5+
* 2.0 <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>, at your
6+
* option. This file may not be copied, modified, or distributed except
77
* according to those terms. */
88

99
use cmake;
1010

1111
use have_feature;
1212

1313
impl super::BuildConfig {
14-
pub fn cmake(&self) {
15-
let mut cmk=cmake::Config::new(&self.mbedtls_src);
16-
cmk
17-
.cflag(format!(r#"-DMBEDTLS_CONFIG_FILE="<{}>""#,self.config_h.to_str().expect("config.h UTF-8 error")))
18-
.define("ENABLE_PROGRAMS","OFF")
19-
.define("ENABLE_TESTING","OFF")
20-
.build_target("lib");
21-
if !have_feature("std") || ::std::env::var("TARGET").map(|s|s=="x86_64-unknown-none-gnu")==Ok(true) {
22-
println!("cargo:rustc-link-lib=gcc");
23-
cmk.cflag("-fno-builtin").cflag("-D_FORTIFY_SOURCE=0").cflag("-fno-stack-protector");
24-
}
25-
let mut dst=cmk.build();
26-
dst.push("build");
27-
dst.push("library");
28-
println!("cargo:rustc-link-search=native={}",dst.to_str().expect("link-search UTF-8 error"));
14+
pub fn cmake(&self) {
15+
let mut cmk = cmake::Config::new(&self.mbedtls_src);
16+
cmk.cflag(format!(
17+
r#"-DMBEDTLS_CONFIG_FILE="<{}>""#,
18+
self.config_h.to_str().expect("config.h UTF-8 error")
19+
)).define("ENABLE_PROGRAMS", "OFF")
20+
.define("ENABLE_TESTING", "OFF")
21+
.build_target("lib");
22+
if !have_feature("std")
23+
|| ::std::env::var("TARGET").map(|s| s == "x86_64-unknown-none-gnu") == Ok(true)
24+
{
25+
println!("cargo:rustc-link-lib=gcc");
26+
cmk.cflag("-fno-builtin")
27+
.cflag("-D_FORTIFY_SOURCE=0")
28+
.cflag("-fno-stack-protector");
29+
}
30+
let mut dst = cmk.build();
31+
dst.push("build");
32+
dst.push("library");
33+
println!(
34+
"cargo:rustc-link-search=native={}",
35+
dst.to_str().expect("link-search UTF-8 error")
36+
);
2937
println!("cargo:rustc-link-lib=mbedtls");
30-
println!("cargo:rustc-link-lib=mbedx509");
38+
println!("cargo:rustc-link-lib=mbedx509");
3139
println!("cargo:rustc-link-lib=mbedcrypto");
32-
}
40+
}
3341
}

0 commit comments

Comments
 (0)