Skip to content
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

style: Update bindgen to 0.31.2. #19072

Merged
merged 4 commits into from Oct 31, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

style: Update bindgen to 0.31.3.

Constified enums are default now. I think I want to introduce an option to
bindgen to allow setting the default enum behavior, but it doesn't need to block
this.

The ServoBindings.toml changes are somewhat hacky, but that's because of
rust-lang/rust-bindgen#1125.

Also, the fixups now need to account for whitespace, since quote generates stuff
like root :: nsString, and we don't rustfmt the bindings if there's no rustfmt
installed.

Bug: 1412486
Reviewed-by: xidorn
MozReview-Commit-ID: EY5eNnCiTIw
  • Loading branch information
emilio committed Oct 31, 2017
commit b721215a00a8a8937a6f8edad160b7716ba1f5e2

Some generated files are not rendered by default. Learn more.

@@ -79,7 +79,7 @@ kernel32-sys = "0.2"
[build-dependencies]
lazy_static = "0.2"
log = "0.3"
bindgen = { version = "0.29.1", optional = true }
bindgen = { version = "0.31.2", optional = true }
regex = {version = "0.2", optional = true}
walkdir = "1.0"
toml = {version = "0.2.1", optional = true, default-features = false}
@@ -200,7 +200,13 @@ mod bindings {

impl BuilderExt for Builder {
fn get_initial_builder() -> Builder {
let mut builder = Builder::default();
use bindgen::RustTarget;

// Disable rust unions, because we replace some types inside of
// them.
let mut builder = Builder::default()
.rustfmt_bindings(false)
.rust_target(RustTarget::Stable_1_0);
for dir in SEARCH_PATHS.iter() {
builder = builder.clang_arg("-I").clang_arg(dir.to_str().unwrap());
}
@@ -233,24 +239,24 @@ mod bindings {
// https://github.com/nikomatsakis/rust-memory-model/issues/2
fn zero_size_type(self, ty: &str, structs_list: &HashSet<&str>) -> Builder {
if !structs_list.contains(ty) {
self.hide_type(ty)
self.blacklist_type(ty)
.raw_line(format!("enum {}Void {{ }}", ty))
.raw_line(format!("pub struct {0}({0}Void);", ty))
} else {
self
}
}
fn borrowed_type(self, ty: &str) -> Builder {
self.hide_type(format!("{}Borrowed", ty))
self.blacklist_type(format!("{}Borrowed", ty))
.raw_line(format!("pub type {0}Borrowed<'a> = &'a {0};", ty))
.hide_type(format!("{}BorrowedOrNull", ty))
.blacklist_type(format!("{}BorrowedOrNull", ty))
.raw_line(format!("pub type {0}BorrowedOrNull<'a> = Option<&'a {0}>;", ty))
}
fn mutable_borrowed_type(self, ty: &str) -> Builder {
self.borrowed_type(ty)
.hide_type(format!("{}BorrowedMut", ty))
.blacklist_type(format!("{}BorrowedMut", ty))
.raw_line(format!("pub type {0}BorrowedMut<'a> = &'a mut {0};", ty))
.hide_type(format!("{}BorrowedMutOrNull", ty))
.blacklist_type(format!("{}BorrowedMutOrNull", ty))
.raw_line(format!("pub type {0}BorrowedMutOrNull<'a> = Option<&'a mut {0}>;", ty))
}
}
@@ -342,7 +348,7 @@ mod bindings {
fn handle_common(self, fixups: &mut Vec<Fixup>) -> BuilderWithConfig<'a> {
self.handle_str_items("headers", |b, item| b.header(add_include(item)))
.handle_str_items("raw-lines", |b, item| b.raw_line(item))
.handle_str_items("hide-types", |b, item| b.hide_type(item))
.handle_str_items("hide-types", |b, item| b.blacklist_type(item))
.handle_table_items("fixups", |builder, item| {
fixups.push(Fixup {
pat: item["pat"].as_str().unwrap().into(),
@@ -391,9 +397,9 @@ mod bindings {
let builder = BuilderWithConfig::new(builder, CONFIG["structs"].as_table().unwrap())
.handle_common(&mut fixups)
.handle_str_items("bitfield-enums", |b, item| b.bitfield_enum(item))
.handle_str_items("constified-enums", |b, item| b.constified_enum(item))
.handle_str_items("whitelist-vars", |b, item| b.whitelisted_var(item))
.handle_str_items("whitelist-types", |b, item| b.whitelisted_type(item))
.handle_str_items("rusty-enums", |b, item| b.rustified_enum(item))
.handle_str_items("whitelist-vars", |b, item| b.whitelist_var(item))
.handle_str_items("whitelist-types", |b, item| b.whitelist_type(item))
.handle_str_items("opaque-types", |b, item| b.opaque_type(item))
.handle_list("constified-enum-variants", |builder, iter| {
let mut map = HashMap::new();
@@ -411,11 +417,16 @@ mod bindings {
let gecko = item["gecko"].as_str().unwrap();
let servo = item["servo"].as_str().unwrap();
let gecko_name = gecko.rsplit("::").next().unwrap();
let gecko = gecko.split("::")
.map(|s| format!("\\s*{}\\s*", s))
.collect::<Vec<_>>()
.join("::");

fixups.push(Fixup {
pat: format!("\\broot::{}\\b", gecko),
pat: format!("\\broot\\s*::\\s*{}\\b", gecko),
rep: format!("::gecko_bindings::structs::{}", gecko_name)
});
builder.hide_type(gecko)
builder.blacklist_type(gecko)
.raw_line(format!("pub type {0}{2} = {1}{2};", gecko_name, servo,
if generic { "<T>" } else { "" }))
})
@@ -480,9 +491,9 @@ mod bindings {
let mut fixups = vec![];
let mut builder = BuilderWithConfig::new(builder, config)
.handle_common(&mut fixups)
.handle_str_items("whitelist-functions", |b, item| b.whitelisted_function(item))
.handle_str_items("whitelist-functions", |b, item| b.whitelist_function(item))
.handle_str_items("structs-types", |mut builder, ty| {
builder = builder.hide_type(ty)
builder = builder.blacklist_type(ty)
.raw_line(format!("use gecko_bindings::structs::{};", ty));
structs_types.insert(ty);
// TODO this is hacky, figure out a better way to do it without
@@ -500,16 +511,16 @@ mod bindings {
.handle_table_items("array-types", |builder, item| {
let cpp_type = item["cpp-type"].as_str().unwrap();
let rust_type = item["rust-type"].as_str().unwrap();
builder.hide_type(format!("nsTArrayBorrowed_{}", cpp_type))
builder
.raw_line(format!(concat!("pub type nsTArrayBorrowed_{}<'a> = ",
"&'a mut ::gecko_bindings::structs::nsTArray<{}>;"),
cpp_type, rust_type))
})
.handle_table_items("servo-owned-types", |mut builder, item| {
let name = item["name"].as_str().unwrap();
builder = builder.hide_type(format!("{}Owned", name))
builder = builder.blacklist_type(format!("{}Owned", name))
.raw_line(format!("pub type {0}Owned = ::gecko_bindings::sugar::ownership::Owned<{0}>;", name))
.hide_type(format!("{}OwnedOrNull", name))
.blacklist_type(format!("{}OwnedOrNull", name))
.raw_line(format!(concat!("pub type {0}OwnedOrNull = ",
"::gecko_bindings::sugar::ownership::OwnedOrNull<{0}>;"), name))
.mutable_borrowed_type(name);
@@ -527,7 +538,7 @@ mod bindings {
.get_builder();
for ty in get_arc_types().iter() {
builder = builder
.hide_type(format!("{}Strong", ty))
.blacklist_type(format!("{}Strong", ty))
.raw_line(format!("pub type {0}Strong = ::gecko_bindings::sugar::ownership::Strong<{0}>;", ty))
.borrowed_type(ty)
.zero_size_type(ty, &structs_types);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.