From c4aa7cd862b7ea3de2315b227717380c387a857c Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Tue, 1 Mar 2016 11:02:07 -0800 Subject: [PATCH 1/4] Update gecko bindings. I'm in the process of making the binding generator easier to use, so that we can check it into the tree. More patches in that direction soon, but I wanted to first just update the existing bindings to match the state of the world in gecko. --- ports/geckolib/bindings.rs | 118 +++++++++++++++---------------------- ports/geckolib/data.rs | 4 +- ports/geckolib/glue.rs | 32 +++++----- 3 files changed, 64 insertions(+), 90 deletions(-) diff --git a/ports/geckolib/bindings.rs b/ports/geckolib/bindings.rs index 845cca32e13..d441f44c8e5 100644 --- a/ports/geckolib/bindings.rs +++ b/ports/geckolib/bindings.rs @@ -1,25 +1,25 @@ /* automatically generated by rust-bindgen */ -pub type int64_t = ::libc::c_longlong; -pub type uint64_t = ::libc::c_ulonglong; +pub type int64_t = i64; +pub type uint64_t = u64; pub type int_least64_t = int64_t; pub type uint_least64_t = uint64_t; pub type int_fast64_t = int64_t; pub type uint_fast64_t = uint64_t; -pub type int32_t = ::libc::c_int; -pub type uint32_t = ::libc::c_uint; +pub type int32_t = i32; +pub type uint32_t = u32; pub type int_least32_t = int32_t; pub type uint_least32_t = uint32_t; pub type int_fast32_t = int32_t; pub type uint_fast32_t = uint32_t; -pub type int16_t = ::libc::c_short; -pub type uint16_t = ::libc::c_ushort; +pub type int16_t = i16; +pub type uint16_t = u16; pub type int_least16_t = int16_t; pub type uint_least16_t = uint16_t; pub type int_fast16_t = int16_t; pub type uint_fast16_t = uint16_t; pub type int8_t = ::libc::c_char; -pub type uint8_t = ::libc::c_uchar; +pub type uint8_t = u8; pub type int_least8_t = int8_t; pub type uint_least8_t = uint8_t; pub type int_fast8_t = int8_t; @@ -28,43 +28,16 @@ pub type intptr_t = int64_t; pub type uintptr_t = uint64_t; pub type intmax_t = ::libc::c_long; pub type uintmax_t = ::libc::c_ulong; -#[derive(Clone, Copy)] -#[repr(u32)] -pub enum Enum_NodeType { - ELEMENT_NODE = 1, - ATTRIBUTE_NODE = 2, - TEXT_NODE = 3, - CDATA_SECTION_NODE = 4, - ENTITY_REFERENCE_NODE = 5, - ENTITY_NODE = 6, - PROCESSING_INSTRUCTION_NODE = 7, - COMMENT_NODE = 8, - DOCUMENT_NODE = 9, - DOCUMENT_TYPE_NODE = 10, - DOCUMENT_FRAGMENT_NODE = 11, - NOTATION_NODE = 12, -} -pub enum Struct_RawGeckoNode { } -pub type RawGeckoNode = Struct_RawGeckoNode; -pub enum Struct_RawGeckoElement { } -pub type RawGeckoElement = Struct_RawGeckoElement; -pub enum Struct_RawGeckoDocument { } -pub type RawGeckoDocument = Struct_RawGeckoDocument; -pub enum Struct_ServoNodeData { } -pub type ServoNodeData = Struct_ServoNodeData; -pub enum Struct_ServoArcStyleSheet { } -pub type ServoArcStyleSheet = Struct_ServoArcStyleSheet; -pub enum Struct_ServoStyleSetData { } -pub type ServoStyleSetData = Struct_ServoStyleSetData; +pub enum RawGeckoNode { } +pub enum RawGeckoElement { } +pub enum RawGeckoDocument { } +pub enum ServoNodeData { } +pub enum RawServoStyleSheet { } +pub enum RawServoStyleSet { } extern "C" { - pub fn Gecko_ElementState(element: *mut RawGeckoElement) -> uint8_t; - pub fn Gecko_GetAttrAsUTF8(element: *mut RawGeckoElement, - ns: *const uint8_t, name: *const uint8_t, - length: *mut uint32_t) - -> *const ::libc::c_char; pub fn Gecko_ChildrenCount(node: *mut RawGeckoNode) -> uint32_t; - pub fn Gecko_GetDocumentElement(document: *mut RawGeckoDocument) - -> *mut RawGeckoElement; + pub fn Gecko_NodeIsElement(node: *mut RawGeckoNode) -> i32; + pub fn Gecko_GetParentNode(node: *mut RawGeckoNode) -> *mut RawGeckoNode; pub fn Gecko_GetFirstChild(node: *mut RawGeckoNode) -> *mut RawGeckoNode; pub fn Gecko_GetLastChild(node: *mut RawGeckoNode) -> *mut RawGeckoNode; pub fn Gecko_GetPrevSibling(node: *mut RawGeckoNode) -> *mut RawGeckoNode; @@ -79,40 +52,41 @@ extern "C" { -> *mut RawGeckoElement; pub fn Gecko_GetNextSiblingElement(element: *mut RawGeckoElement) -> *mut RawGeckoElement; - pub fn Gecko_GetNodeData(node: *mut RawGeckoNode) -> *mut ServoNodeData; - pub fn Gecko_GetParentNode(node: *mut RawGeckoNode) -> *mut RawGeckoNode; - pub fn Gecko_LocalName(element: *mut RawGeckoElement, - length: *mut uint32_t) -> *const uint16_t; + pub fn Gecko_GetDocumentElement(document: *mut RawGeckoDocument) + -> *mut RawGeckoElement; + pub fn Gecko_ElementState(element: *mut RawGeckoElement) -> uint8_t; pub fn Gecko_IsHTMLElementInHTMLDocument(element: *mut RawGeckoElement) - -> ::libc::c_int; - pub fn Gecko_IsLink(element: *mut RawGeckoElement) -> ::libc::c_int; - pub fn Gecko_IsTextNode(node: *mut RawGeckoNode) -> ::libc::c_int; - pub fn Gecko_IsVisitedLink(element: *mut RawGeckoElement) - -> ::libc::c_int; - pub fn Gecko_IsUnvisitedLink(element: *mut RawGeckoElement) - -> ::libc::c_int; - pub fn Gecko_IsRootElement(element: *mut RawGeckoElement) - -> ::libc::c_int; - pub fn Gecko_Namespace(element: *mut RawGeckoElement, - length: *mut uint32_t) -> *const uint16_t; - pub fn Gecko_NodeIsElement(node: *mut RawGeckoNode) -> ::libc::c_int; + -> i32; + pub fn Gecko_IsLink(element: *mut RawGeckoElement) -> i32; + pub fn Gecko_IsTextNode(node: *mut RawGeckoNode) -> i32; + pub fn Gecko_IsVisitedLink(element: *mut RawGeckoElement) -> i32; + pub fn Gecko_IsUnvisitedLink(element: *mut RawGeckoElement) -> i32; + pub fn Gecko_IsRootElement(element: *mut RawGeckoElement) -> i32; + pub fn Gecko_GetNodeData(node: *mut RawGeckoNode) -> *mut ServoNodeData; pub fn Gecko_SetNodeData(node: *mut RawGeckoNode, data: *mut ServoNodeData); - pub fn Servo_RestyleDocument(doc: *mut RawGeckoDocument, - data: *mut ServoStyleSetData); pub fn Servo_DropNodeData(data: *mut ServoNodeData); pub fn Servo_StylesheetFromUTF8Bytes(bytes: *const uint8_t, length: uint32_t) - -> *mut ServoArcStyleSheet; - pub fn Servo_AppendStyleSheet(sheet: *mut ServoArcStyleSheet, - data: *mut ServoStyleSetData); - pub fn Servo_PrependStyleSheet(sheet: *mut ServoArcStyleSheet, - data: *mut ServoStyleSetData); - pub fn Servo_RemoveStyleSheet(sheet: *mut ServoArcStyleSheet, - data: *mut ServoStyleSetData); - pub fn Servo_StyleSheetHasRules(sheet: *mut ServoArcStyleSheet) - -> ::libc::c_int; - pub fn Servo_DropStylesheet(sheet: *mut ServoArcStyleSheet); - pub fn Servo_InitStyleSetData() -> *mut ServoStyleSetData; - pub fn Servo_DropStyleSetData(data: *mut ServoStyleSetData); + -> *mut RawServoStyleSheet; + pub fn Servo_ReleaseStylesheet(sheet: *mut RawServoStyleSheet); + pub fn Servo_AppendStyleSheet(sheet: *mut RawServoStyleSheet, + set: *mut RawServoStyleSet); + pub fn Servo_PrependStyleSheet(sheet: *mut RawServoStyleSheet, + set: *mut RawServoStyleSet); + pub fn Servo_RemoveStyleSheet(sheet: *mut RawServoStyleSheet, + set: *mut RawServoStyleSet); + pub fn Servo_StyleSheetHasRules(sheet: *mut RawServoStyleSheet) -> i32; + pub fn Servo_InitStyleSet() -> *mut RawServoStyleSet; + pub fn Servo_DropStyleSet(set: *mut RawServoStyleSet); + pub fn Gecko_GetAttrAsUTF8(element: *mut RawGeckoElement, + ns: *const uint8_t, name: *const uint8_t, + length: *mut uint32_t) + -> *const ::libc::c_char; + pub fn Gecko_LocalName(element: *mut RawGeckoElement, + length: *mut uint32_t) -> *const uint16_t; + pub fn Gecko_Namespace(element: *mut RawGeckoElement, + length: *mut uint32_t) -> *const uint16_t; + pub fn Servo_RestyleDocument(doc: *mut RawGeckoDocument, + set: *mut RawServoStyleSet); } diff --git a/ports/geckolib/data.rs b/ports/geckolib/data.rs index 38351d70e2a..bc1c398e6c0 100644 --- a/ports/geckolib/data.rs +++ b/ports/geckolib/data.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use bindings::ServoStyleSetData; +use bindings::RawServoStyleSet; use euclid::Size2D; use euclid::size::TypedSize2D; use num_cpus; @@ -61,7 +61,7 @@ impl PerDocumentStyleData { } } - pub fn borrow_mut_from_raw<'a>(data: *mut ServoStyleSetData) -> &'a mut Self { + pub fn borrow_mut_from_raw<'a>(data: *mut RawServoStyleSet) -> &'a mut Self { unsafe { &mut *(data as *mut PerDocumentStyleData) } } } diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index d536a65bcb0..b63453f9559 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -6,7 +6,7 @@ use app_units::Au; use bindings::RawGeckoDocument; -use bindings::{ServoArcStyleSheet, ServoNodeData, ServoStyleSetData, uint8_t, uint32_t}; +use bindings::{ServoNodeData, RawServoStyleSet, RawServoStyleSheet, uint8_t, uint32_t}; use data::PerDocumentStyleData; use euclid::Size2D; use selector_impl::{SharedStyleContext, Stylesheet}; @@ -34,7 +34,7 @@ use wrapper::{GeckoDocument, GeckoNode, NonOpaqueStyleData}; */ #[no_mangle] -pub extern "C" fn Servo_RestyleDocument(doc: *mut RawGeckoDocument, raw_data: *mut ServoStyleSetData) -> () { +pub extern "C" fn Servo_RestyleDocument(doc: *mut RawGeckoDocument, raw_data: *mut RawServoStyleSet) -> () { let document = unsafe { GeckoDocument::from_raw(doc) }; let node = match document.root_node() { Some(x) => x, @@ -75,7 +75,7 @@ pub extern "C" fn Servo_DropNodeData(data: *mut ServoNodeData) -> () { #[no_mangle] pub extern "C" fn Servo_StylesheetFromUTF8Bytes(bytes: *const uint8_t, - length: uint32_t) -> *mut ServoArcStyleSheet { + length: uint32_t) -> *mut RawServoStyleSheet { let input = unsafe { from_utf8_unchecked(slice::from_raw_parts(bytes, length as usize)) }; @@ -87,7 +87,7 @@ pub extern "C" fn Servo_StylesheetFromUTF8Bytes(bytes: *const uint8_t, } } -fn with_arc_stylesheet(raw: *mut ServoArcStyleSheet, cb: F) -> Output +fn with_arc_stylesheet(raw: *mut RawServoStyleSheet, cb: F) -> Output where F: FnOnce(&Arc) -> Output { let owned = unsafe { consume_arc_stylesheet(raw) }; let result = cb(&owned); @@ -95,13 +95,13 @@ fn with_arc_stylesheet(raw: *mut ServoArcStyleSheet, cb: F) -> Output result } -unsafe fn consume_arc_stylesheet(raw: *mut ServoArcStyleSheet) -> Arc { +unsafe fn consume_arc_stylesheet(raw: *mut RawServoStyleSheet) -> Arc { transmute(raw) } #[no_mangle] -pub extern "C" fn Servo_AppendStyleSheet(raw_sheet: *mut ServoArcStyleSheet, - raw_data: *mut ServoStyleSetData) { +pub extern "C" fn Servo_AppendStyleSheet(raw_sheet: *mut RawServoStyleSheet, + raw_data: *mut RawServoStyleSet) { let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data); with_arc_stylesheet(raw_sheet, |sheet| { data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet)); @@ -111,8 +111,8 @@ pub extern "C" fn Servo_AppendStyleSheet(raw_sheet: *mut ServoArcStyleSheet, } #[no_mangle] -pub extern "C" fn Servo_PrependStyleSheet(raw_sheet: *mut ServoArcStyleSheet, - raw_data: *mut ServoStyleSetData) { +pub extern "C" fn Servo_PrependStyleSheet(raw_sheet: *mut RawServoStyleSheet, + raw_data: *mut RawServoStyleSet) { let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data); with_arc_stylesheet(raw_sheet, |sheet| { data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet)); @@ -122,8 +122,8 @@ pub extern "C" fn Servo_PrependStyleSheet(raw_sheet: *mut ServoArcStyleSheet, } #[no_mangle] -pub extern "C" fn Servo_RemoveStyleSheet(raw_sheet: *mut ServoArcStyleSheet, - raw_data: *mut ServoStyleSetData) { +pub extern "C" fn Servo_RemoveStyleSheet(raw_sheet: *mut RawServoStyleSheet, + raw_data: *mut RawServoStyleSet) { let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data); with_arc_stylesheet(raw_sheet, |sheet| { data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet)); @@ -132,27 +132,27 @@ pub extern "C" fn Servo_RemoveStyleSheet(raw_sheet: *mut ServoArcStyleSheet, } #[no_mangle] -pub extern "C" fn Servo_StyleSheetHasRules(raw_sheet: *mut ServoArcStyleSheet) -> ::libc::c_int { +pub extern "C" fn Servo_StyleSheetHasRules(raw_sheet: *mut RawServoStyleSheet) -> ::libc::c_int { with_arc_stylesheet(raw_sheet, |sheet| if sheet.rules.is_empty() { 0 } else { 1 }) } #[no_mangle] -pub extern "C" fn Servo_DropStylesheet(sheet: *mut ServoArcStyleSheet) -> () { +pub extern "C" fn Servo_ReleaseStylesheet(sheet: *mut RawServoStyleSheet) -> () { unsafe { let _ = consume_arc_stylesheet(sheet); } } #[no_mangle] -pub extern "C" fn Servo_InitStyleSetData() -> *mut ServoStyleSetData { +pub extern "C" fn Servo_InitStyleSet() -> *mut RawServoStyleSet { let data = Box::new(PerDocumentStyleData::new()); - Box::into_raw(data) as *mut ServoStyleSetData + Box::into_raw(data) as *mut RawServoStyleSet } #[no_mangle] -pub extern "C" fn Servo_DropStyleSetData(data: *mut ServoStyleSetData) -> () { +pub extern "C" fn Servo_DropStyleSet(data: *mut RawServoStyleSet) -> () { unsafe { let _ = Box::::from_raw(data as *mut PerDocumentStyleData); } From 4da1171474cd905a1d4d81487f2e8b5b5b430bd3 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Wed, 2 Mar 2016 16:38:53 -0800 Subject: [PATCH 2/4] Stop using servo UA stylesheets for geckolib. Gecko will provide these. This also removes the need to reference the servo resource directory. --- components/style/selector_impl.rs | 6 +-- components/style/selector_matching.rs | 4 +- ports/geckolib/glue.rs | 5 --- ports/geckolib/selector_impl.rs | 58 ++------------------------- 4 files changed, 9 insertions(+), 64 deletions(-) diff --git a/components/style/selector_impl.rs b/components/style/selector_impl.rs index 1aa2469b6f5..77aa23ca808 100644 --- a/components/style/selector_impl.rs +++ b/components/style/selector_impl.rs @@ -19,7 +19,7 @@ pub trait SelectorImplExt : SelectorImpl + Sized { fn get_user_or_user_agent_stylesheets() -> &'static [Stylesheet]; - fn get_quirks_mode_stylesheet() -> &'static Stylesheet; + fn get_quirks_mode_stylesheet() -> Option<&'static Stylesheet>; } #[derive(Clone, Debug, PartialEq, Eq, HeapSizeOf, Hash)] @@ -135,7 +135,7 @@ impl SelectorImplExt for ServoSelectorImpl { } #[inline] - fn get_quirks_mode_stylesheet() -> &'static Stylesheet { - &*QUIRKS_MODE_STYLESHEET + fn get_quirks_mode_stylesheet() -> Option<&'static Stylesheet> { + Some(&*QUIRKS_MODE_STYLESHEET) } } diff --git a/components/style/selector_matching.rs b/components/style/selector_matching.rs index a6c93cebcbc..614ea681e18 100644 --- a/components/style/selector_matching.rs +++ b/components/style/selector_matching.rs @@ -146,7 +146,9 @@ impl Stylist { } if self.quirks_mode { - self.add_stylesheet(&Impl::get_quirks_mode_stylesheet()); + if let Some(s) = Impl::get_quirks_mode_stylesheet() { + self.add_stylesheet(s); + } } for ref stylesheet in doc_stylesheets.iter() { diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index b63453f9559..9185d701c18 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -22,7 +22,6 @@ use style::stylesheets::Origin; use traversal::RecalcStyleOnly; use url::Url; use util::arc_ptr_eq; -use util::resource_files::set_resources_path; use wrapper::{GeckoDocument, GeckoNode, NonOpaqueStyleData}; /* @@ -42,10 +41,6 @@ pub extern "C" fn Servo_RestyleDocument(doc: *mut RawGeckoDocument, raw_data: *m }; let data = unsafe { &mut *(raw_data as *mut PerDocumentStyleData) }; - // FIXME(bholley): Don't hardcode resources path. We may want to use Gecko's UA stylesheets - // anyway. - set_resources_path(Some("/files/mozilla/stylo/servo/resources/".to_owned())); - let _needs_dirtying = data.stylist.update(&data.stylesheets, data.stylesheets_changed); data.stylesheets_changed = false; diff --git a/ports/geckolib/selector_impl.rs b/ports/geckolib/selector_impl.rs index 2b2b3a3eb2b..45ded949052 100644 --- a/ports/geckolib/selector_impl.rs +++ b/ports/geckolib/selector_impl.rs @@ -10,7 +10,6 @@ use style::error_reporting::StdoutErrorReporter; use style::selector_impl::SelectorImplExt; use style::stylesheets::Origin; use url::Url; -use util::resource_files::read_resource_file; pub type Stylist = style::selector_matching::Stylist; pub type Stylesheet = style::stylesheets::Stylesheet; @@ -19,56 +18,6 @@ pub type PrivateStyleData = style::data::PrivateStyleData; pub struct GeckoSelectorImpl; -// TODO: Replace this with Gecko's stylesheets -lazy_static! { - static ref USER_OR_USER_AGENT_STYLESHEETS: Vec = { - let mut stylesheets = vec!(); - // FIXME: presentational-hints.css should be at author origin with zero specificity. - // (Does it make a difference?) - for &filename in &["user-agent.css", "servo.css", "presentational-hints.css"] { - match read_resource_file(&[filename]) { - Ok(res) => { - let ua_stylesheet = Stylesheet::from_bytes( - &res, - Url::parse(&format!("chrome:///{:?}", filename)).unwrap(), - None, - None, - Origin::UserAgent, - box StdoutErrorReporter); - stylesheets.push(ua_stylesheet); - } - Err(..) => { - error!("Failed to load UA stylesheet {}!", filename); - process::exit(1); - } - } - } - - stylesheets - }; -} - -lazy_static! { - static ref QUIRKS_MODE_STYLESHEET: Stylesheet = { - match read_resource_file(&["quirks-mode.css"]) { - Ok(res) => { - Stylesheet::from_bytes( - &res, - url!("chrome:///quirks-mode.css"), - None, - None, - Origin::UserAgent, - box StdoutErrorReporter) - }, - Err(..) => { - error!("Stylist failed to load 'quirks-mode.css'!"); - process::exit(1); - } - } - }; -} - - #[derive(Clone, Debug, PartialEq, Eq, HeapSizeOf, Hash)] pub enum PseudoElement { Before, @@ -294,14 +243,13 @@ impl SelectorImplExt for GeckoSelectorImpl { pc.state_flag() } - // FIXME: Don't use Servo's UA stylesheets, use Gecko's instead #[inline] fn get_user_or_user_agent_stylesheets() -> &'static [Stylesheet] { - &*USER_OR_USER_AGENT_STYLESHEETS + &[] } #[inline] - fn get_quirks_mode_stylesheet() -> &'static Stylesheet { - &*QUIRKS_MODE_STYLESHEET + fn get_quirks_mode_stylesheet() -> Option<&'static Stylesheet> { + None } } From 23ace489b97117fc19bd19ecb134cdebe192e170 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Tue, 12 Jan 2016 16:00:27 -0800 Subject: [PATCH 3/4] Binding generator tooling. This should make it a lot easier for people to bootstrap and run the binding generator. --- ports/geckolib/tools/build_custom_clang.sh | 26 +++++++++++++ ports/geckolib/tools/regen_bindings.sh | 33 +++++++++++++++++ ports/geckolib/tools/regen_style_structs.sh | 41 +++++++++++++++++++++ ports/geckolib/tools/setup_bindgen.sh | 30 +++++++++++++++ 4 files changed, 130 insertions(+) create mode 100755 ports/geckolib/tools/build_custom_clang.sh create mode 100755 ports/geckolib/tools/regen_bindings.sh create mode 100755 ports/geckolib/tools/regen_style_structs.sh create mode 100755 ports/geckolib/tools/setup_bindgen.sh diff --git a/ports/geckolib/tools/build_custom_clang.sh b/ports/geckolib/tools/build_custom_clang.sh new file mode 100755 index 00000000000..40b3c86f5aa --- /dev/null +++ b/ports/geckolib/tools/build_custom_clang.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Run in the tools directory. +cd `dirname $0` + +# Don't run twice. +if [ -d llvm ]; then + echo "llvm directory already exists." + exit 1 +fi + +# Download and build a custom llvm +git clone https://github.com/llvm-mirror/llvm +cd llvm +git checkout release_37 +cd tools +git clone https://github.com/llvm-mirror/clang +cd clang +git remote add mwu https://github.com/michaelwu/clang +git fetch mwu +git checkout release_37_smhacks +cd ../.. # llvm root dir +mkdir build +cd build +../configure --enable-optimized +make diff --git a/ports/geckolib/tools/regen_bindings.sh b/ports/geckolib/tools/regen_bindings.sh new file mode 100755 index 00000000000..4795910c70d --- /dev/null +++ b/ports/geckolib/tools/regen_bindings.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Run in the tools directory. +cd `dirname $0` + +if [ $# -ne 1 ]; then + echo "Usage: $0 /path/to/objdir/" + exit 1 +fi + +# Check for rust-bindgen +if [ ! -d rust-bindgen ]; then + echo "rust-bindgen not found. Run setup_bindgen.sh first." + exit 1 +fi + +export RUST_BACKTRACE=1 +export LIBCLANG_PATH=`pwd`/llvm/build/Release+Asserts/lib +export DYLD_LIBRARY_PATH=`pwd`/llvm/build/Release+Asserts/lib +export DIST_INCLUDE=$1/dist/include + +# Check for the include directory. +if [ ! -d $DIST_INCLUDE ]; then + echo "$DIST_INCLUDE: directory not found" + exit 1 +fi + +# Uncomment the following line to run rust-bindgen in a debugger on mac. +# The absolute path is required to allow launching lldb with an untrusted +# library in DYLD_LIBRARY_PATH. +# +# /Applications/Xcode.app/Contents/Developer/usr/bin/lldb -- +./rust-bindgen/target/debug/bindgen -I$DIST_INCLUDE -o ../bindings.rs $DIST_INCLUDE/mozilla/ServoBindings.h diff --git a/ports/geckolib/tools/regen_style_structs.sh b/ports/geckolib/tools/regen_style_structs.sh new file mode 100755 index 00000000000..b8d84651ebb --- /dev/null +++ b/ports/geckolib/tools/regen_style_structs.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Run in the tools directory. +cd `dirname $0` + +if [ $# -ne 1 ]; then + echo "Usage: $0 /path/to/objdir/" + exit 1 +fi + +# Check for rust-bindgen +if [ ! -d rust-bindgen ]; then + echo "rust-bindgen not found. Run setup_bindgen.sh first." + exit 1 +fi + +# Need to find a way to avoid hardcoding these +STD_LIB_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include +STDXX_LIB_PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1 +if [ ! -d $STD_LIB_PATH ] || [ ! -d $STDXX_LIB_PATH ]; then + echo "Please update the above environmental variables to point to your standard library." + exit 1 +fi + +export RUST_BACKTRACE=1 +export LIBCLANG_PATH=`pwd`/llvm/build/Release+Asserts/lib +export DYLD_LIBRARY_PATH=`pwd`/llvm/build/Release+Asserts/lib +export DIST_INCLUDE=$1/dist/include + +# Check for the include directory. +if [ ! -d $DIST_INCLUDE ]; then + echo "$DIST_INCLUDE: directory not found" + exit 1 +fi + +# Uncomment the following line to run rust-bindgen in a debugger on mac. +# The absolute path is required to allow launching lldb with an untrusted +# library in DYLD_LIBRARY_PATH. +# +# /Applications/Xcode.app/Contents/Developer/usr/bin/lldb -- +./rust-bindgen/target/debug/bindgen -x c++ -std=gnu++0x -ignore-functions -allow-unknown-types -isystem $STDXX_LIB_PATH -isystem $STD_LIB_PATH -I$DIST_INCLUDE -I$DIST_INCLUDE/nspr -DDEBUG=1 -DTRACING=1 -DOS_POSIX=1 -DOS_MACOSX=1 -DMOZILLA_INTERNAL_API -DIMPL_LIBXUL -include $1/mozilla-config.h -o ../gecko_style_structs.rs $DIST_INCLUDE/nsStyleStruct.h diff --git a/ports/geckolib/tools/setup_bindgen.sh b/ports/geckolib/tools/setup_bindgen.sh new file mode 100755 index 00000000000..d1fae60f6ae --- /dev/null +++ b/ports/geckolib/tools/setup_bindgen.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Run in the tools directory. +cd `dirname $0` + +# Make sure we have a custom clang set up. +if [ ! -d llvm ]; then + echo "Custom LLVM/Clang not found. Run build_custom_clang.sh first." + exit 1 +fi + +# Don't run twice. +if [ -d rust-bindgen ]; then + echo "rust-bindgen directory already exists." + exit 1 +fi + +# Check for multirust +if [ ! -x "$(command -v multirust)" ]; then + echo 'multirust must be installed.' + exit 1 +fi + +# Setup and build bindgen. +export LIBCLANG_PATH=`pwd`/llvm/build/Release+Asserts/lib +git clone https://github.com/bholley/rust-bindgen.git +cd rust-bindgen +git checkout sm-hacks +multirust override nightly +cargo build From dbbbebd66436f83d55465fd304195f77af259858 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Wed, 2 Mar 2016 20:34:23 -0800 Subject: [PATCH 4/4] Parse ServoBindings.h as C++. This allows us to remove the bool-as-int contortions we were doing before. --- ports/geckolib/bindings.rs | 25 ++++++++++++++----------- ports/geckolib/glue.rs | 4 ++-- ports/geckolib/tools/regen_bindings.sh | 2 +- ports/geckolib/wrapper.rs | 14 +++++++------- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/ports/geckolib/bindings.rs b/ports/geckolib/bindings.rs index d441f44c8e5..ba761f17d78 100644 --- a/ports/geckolib/bindings.rs +++ b/ports/geckolib/bindings.rs @@ -28,15 +28,18 @@ pub type intptr_t = int64_t; pub type uintptr_t = uint64_t; pub type intmax_t = ::libc::c_long; pub type uintmax_t = ::libc::c_ulong; -pub enum RawGeckoNode { } -pub enum RawGeckoElement { } -pub enum RawGeckoDocument { } +pub enum nsINode { } +pub type RawGeckoNode = nsINode; +pub enum Element { } +pub type RawGeckoElement = Element; +pub enum nsIDocument { } +pub type RawGeckoDocument = nsIDocument; pub enum ServoNodeData { } pub enum RawServoStyleSheet { } pub enum RawServoStyleSet { } extern "C" { pub fn Gecko_ChildrenCount(node: *mut RawGeckoNode) -> uint32_t; - pub fn Gecko_NodeIsElement(node: *mut RawGeckoNode) -> i32; + pub fn Gecko_NodeIsElement(node: *mut RawGeckoNode) -> bool; pub fn Gecko_GetParentNode(node: *mut RawGeckoNode) -> *mut RawGeckoNode; pub fn Gecko_GetFirstChild(node: *mut RawGeckoNode) -> *mut RawGeckoNode; pub fn Gecko_GetLastChild(node: *mut RawGeckoNode) -> *mut RawGeckoNode; @@ -56,12 +59,12 @@ extern "C" { -> *mut RawGeckoElement; pub fn Gecko_ElementState(element: *mut RawGeckoElement) -> uint8_t; pub fn Gecko_IsHTMLElementInHTMLDocument(element: *mut RawGeckoElement) - -> i32; - pub fn Gecko_IsLink(element: *mut RawGeckoElement) -> i32; - pub fn Gecko_IsTextNode(node: *mut RawGeckoNode) -> i32; - pub fn Gecko_IsVisitedLink(element: *mut RawGeckoElement) -> i32; - pub fn Gecko_IsUnvisitedLink(element: *mut RawGeckoElement) -> i32; - pub fn Gecko_IsRootElement(element: *mut RawGeckoElement) -> i32; + -> bool; + pub fn Gecko_IsLink(element: *mut RawGeckoElement) -> bool; + pub fn Gecko_IsTextNode(node: *mut RawGeckoNode) -> bool; + pub fn Gecko_IsVisitedLink(element: *mut RawGeckoElement) -> bool; + pub fn Gecko_IsUnvisitedLink(element: *mut RawGeckoElement) -> bool; + pub fn Gecko_IsRootElement(element: *mut RawGeckoElement) -> bool; pub fn Gecko_GetNodeData(node: *mut RawGeckoNode) -> *mut ServoNodeData; pub fn Gecko_SetNodeData(node: *mut RawGeckoNode, data: *mut ServoNodeData); @@ -76,7 +79,7 @@ extern "C" { set: *mut RawServoStyleSet); pub fn Servo_RemoveStyleSheet(sheet: *mut RawServoStyleSheet, set: *mut RawServoStyleSet); - pub fn Servo_StyleSheetHasRules(sheet: *mut RawServoStyleSheet) -> i32; + pub fn Servo_StyleSheetHasRules(sheet: *mut RawServoStyleSheet) -> bool; pub fn Servo_InitStyleSet() -> *mut RawServoStyleSet; pub fn Servo_DropStyleSet(set: *mut RawServoStyleSet); pub fn Gecko_GetAttrAsUTF8(element: *mut RawGeckoElement, diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 9185d701c18..510e39cc041 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -127,8 +127,8 @@ pub extern "C" fn Servo_RemoveStyleSheet(raw_sheet: *mut RawServoStyleSheet, } #[no_mangle] -pub extern "C" fn Servo_StyleSheetHasRules(raw_sheet: *mut RawServoStyleSheet) -> ::libc::c_int { - with_arc_stylesheet(raw_sheet, |sheet| if sheet.rules.is_empty() { 0 } else { 1 }) +pub extern "C" fn Servo_StyleSheetHasRules(raw_sheet: *mut RawServoStyleSheet) -> bool { + with_arc_stylesheet(raw_sheet, |sheet| !sheet.rules.is_empty()) } diff --git a/ports/geckolib/tools/regen_bindings.sh b/ports/geckolib/tools/regen_bindings.sh index 4795910c70d..157877b0c72 100755 --- a/ports/geckolib/tools/regen_bindings.sh +++ b/ports/geckolib/tools/regen_bindings.sh @@ -30,4 +30,4 @@ fi # library in DYLD_LIBRARY_PATH. # # /Applications/Xcode.app/Contents/Developer/usr/bin/lldb -- -./rust-bindgen/target/debug/bindgen -I$DIST_INCLUDE -o ../bindings.rs $DIST_INCLUDE/mozilla/ServoBindings.h +./rust-bindgen/target/debug/bindgen -x c++ -std=gnu++0x -I$DIST_INCLUDE -o ../bindings.rs $DIST_INCLUDE/mozilla/ServoBindings.h diff --git a/ports/geckolib/wrapper.rs b/ports/geckolib/wrapper.rs index a05e08d5227..272b89f64d6 100644 --- a/ports/geckolib/wrapper.rs +++ b/ports/geckolib/wrapper.rs @@ -103,13 +103,13 @@ impl<'ln> TNode<'ln> for GeckoNode<'ln> { fn is_text_node(&self) -> bool { unsafe { - Gecko_IsTextNode(self.node) != 0 + Gecko_IsTextNode(self.node) } } fn is_element(&self) -> bool { unsafe { - Gecko_NodeIsElement(self.node) != 0 + Gecko_NodeIsElement(self.node) } } @@ -392,7 +392,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { fn is_root(&self) -> bool { unsafe { - Gecko_IsRootElement(self.element) != 0 + Gecko_IsRootElement(self.element) } } @@ -425,9 +425,9 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { fn match_non_ts_pseudo_class(&self, pseudo_class: NonTSPseudoClass) -> bool { match pseudo_class { // https://github.com/servo/servo/issues/8718 - NonTSPseudoClass::AnyLink => unsafe { Gecko_IsLink(self.element) != 0 }, - NonTSPseudoClass::Link => unsafe { Gecko_IsUnvisitedLink(self.element) != 0 }, - NonTSPseudoClass::Visited => unsafe { Gecko_IsVisitedLink(self.element) != 0 }, + NonTSPseudoClass::AnyLink => unsafe { Gecko_IsLink(self.element) }, + NonTSPseudoClass::Link => unsafe { Gecko_IsUnvisitedLink(self.element) }, + NonTSPseudoClass::Visited => unsafe { Gecko_IsVisitedLink(self.element) }, NonTSPseudoClass::Active | NonTSPseudoClass::Focus | NonTSPseudoClass::Hover | @@ -480,7 +480,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { fn is_html_element_in_html_document(&self) -> bool { unsafe { - Gecko_IsHTMLElementInHTMLDocument(self.element) != 0 + Gecko_IsHTMLElementInHTMLDocument(self.element) } } }