mirror of
https://github.com/servo/servo.git
synced 2025-08-11 16:35:33 +01:00
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 https://github.com/rust-lang-nursery/rust-bindgen/issues/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
This commit is contained in:
parent
b5f8edc4ae
commit
b721215a00
5 changed files with 60 additions and 128 deletions
|
@ -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,7 +239,7 @@ 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 {
|
||||
|
@ -241,16 +247,16 @@ mod bindings {
|
|||
}
|
||||
}
|
||||
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);
|
||||
|
|
|
@ -16,7 +16,7 @@ use gecko_bindings::bindings;
|
|||
use gecko_bindings::structs;
|
||||
use gecko_bindings::structs::{nsCSSKeyword, nsCSSProps_KTableEntry, nsCSSValue, nsCSSUnit};
|
||||
use gecko_bindings::structs::{nsMediaExpression_Range, nsMediaFeature};
|
||||
use gecko_bindings::structs::{nsMediaFeature_ValueType, nsMediaFeature_RangeType, nsMediaFeature_RequirementFlags};
|
||||
use gecko_bindings::structs::{nsMediaFeature_ValueType, nsMediaFeature_RangeType};
|
||||
use gecko_bindings::structs::{nsPresContext, RawGeckoPresContextOwned};
|
||||
use media_queries::MediaType;
|
||||
use parser::ParserContext;
|
||||
|
@ -236,7 +236,7 @@ impl ToCss for Expression {
|
|||
{
|
||||
dest.write_str("(")?;
|
||||
|
||||
if (self.feature.mReqFlags & nsMediaFeature_RequirementFlags::eHasWebkitPrefix as u8) != 0 {
|
||||
if (self.feature.mReqFlags & structs::nsMediaFeature_RequirementFlags_eHasWebkitPrefix) != 0 {
|
||||
dest.write_str("-webkit-")?;
|
||||
}
|
||||
match self.range {
|
||||
|
@ -612,7 +612,7 @@ impl Expression {
|
|||
|
||||
if context.in_chrome_stylesheet() ||
|
||||
context.stylesheet_origin == Origin::UserAgent {
|
||||
flags |= nsMediaFeature_RequirementFlags::eUserAgentAndChromeOnly as u8;
|
||||
flags |= structs::nsMediaFeature_RequirementFlags_eUserAgentAndChromeOnly;
|
||||
}
|
||||
|
||||
let result = {
|
||||
|
@ -621,9 +621,9 @@ impl Expression {
|
|||
if unsafe { structs::StylePrefs_sWebkitPrefixedAliasesEnabled } &&
|
||||
starts_with_ignore_ascii_case(feature_name, "-webkit-") {
|
||||
feature_name = &feature_name[8..];
|
||||
flags |= nsMediaFeature_RequirementFlags::eHasWebkitPrefix as u8;
|
||||
flags |= structs::nsMediaFeature_RequirementFlags_eHasWebkitPrefix;
|
||||
if unsafe { structs::StylePrefs_sWebkitDevicePixelRatioEnabled } {
|
||||
flags |= nsMediaFeature_RequirementFlags::eWebkitDevicePixelRatioPrefEnabled as u8;
|
||||
flags |= structs::nsMediaFeature_RequirementFlags_eWebkitDevicePixelRatioPrefEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4486,11 +4486,11 @@ fn static_assert() {
|
|||
}
|
||||
|
||||
pub fn clone_image_orientation(&self) -> longhands::image_orientation::computed_value::T {
|
||||
use gecko_bindings::structs::{nsStyleImageOrientation_Bits, nsStyleImageOrientation_Angles};
|
||||
use gecko_bindings::structs::nsStyleImageOrientation_Angles;
|
||||
use properties::longhands::image_orientation::computed_value::{Orientation, T};
|
||||
|
||||
let gecko_orientation = self.gecko.mImageOrientation.mOrientation;
|
||||
if gecko_orientation & nsStyleImageOrientation_Bits::FROM_IMAGE_MASK as u8 != 0 {
|
||||
if gecko_orientation & structs::nsStyleImageOrientation_Bits_FROM_IMAGE_MASK as u8 != 0 {
|
||||
T::FromImage
|
||||
} else {
|
||||
const ANGLE0: u8 = nsStyleImageOrientation_Angles::ANGLE_0 as u8;
|
||||
|
@ -4498,14 +4498,15 @@ fn static_assert() {
|
|||
const ANGLE180: u8 = nsStyleImageOrientation_Angles::ANGLE_180 as u8;
|
||||
const ANGLE270: u8 = nsStyleImageOrientation_Angles::ANGLE_270 as u8;
|
||||
|
||||
let flip = gecko_orientation & nsStyleImageOrientation_Bits::FLIP_MASK as u8 != 0;
|
||||
let orientation = match gecko_orientation & nsStyleImageOrientation_Bits::ORIENTATION_MASK as u8 {
|
||||
ANGLE0 => Orientation::Angle0,
|
||||
ANGLE90 => Orientation::Angle90,
|
||||
ANGLE180 => Orientation::Angle180,
|
||||
ANGLE270 => Orientation::Angle270,
|
||||
_ => unreachable!()
|
||||
};
|
||||
let flip = gecko_orientation & structs::nsStyleImageOrientation_Bits_FLIP_MASK as u8 != 0;
|
||||
let orientation =
|
||||
match gecko_orientation & structs::nsStyleImageOrientation_Bits_ORIENTATION_MASK as u8 {
|
||||
ANGLE0 => Orientation::Angle0,
|
||||
ANGLE90 => Orientation::Angle90,
|
||||
ANGLE180 => Orientation::Angle180,
|
||||
ANGLE270 => Orientation::Angle270,
|
||||
_ => unreachable!()
|
||||
};
|
||||
T::AngleWithFlipped(orientation, flip)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue