Bug 1536584 - Remove bindings.rs. r=xidorn
☠☠ backed out by 105411e3cf06 ☠ ☠
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 26 Mar 2019 13:38:14 +0000
changeset 466099 7bd834c5800c93f54df331311d726dc571813d7b
parent 466098 f1eec8f7a3f87f9d8edbe3a2c5d6fa9c629eb6f2
child 466100 563e8fb1be5db3fa6f984c34270a35c7cf1dd4e6
push id81442
push userealvarez@mozilla.com
push dateTue, 26 Mar 2019 13:42:36 +0000
treeherderautoland@7bd834c5800c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxidorn
bugs1536584
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1536584 - Remove bindings.rs. r=xidorn I kept it building the most straight-forward way possible (pub use) because it seems to me that bindings is not a bad name, and we should probably move structs.rs to be bindings.rs rather than the other way around. But that's a different bug in any case, need to think more about it. Differential Revision: https://phabricator.services.mozilla.com/D24713
layout/style/ServoBindings.toml
servo/components/style/build_gecko.rs
servo/components/style/gecko_bindings/mod.rs
--- a/layout/style/ServoBindings.toml
+++ b/layout/style/ServoBindings.toml
@@ -21,16 +21,17 @@ headers = [
     "mozilla/ServoElementSnapshot.h",
     "mozilla/ServoElementSnapshotTable.h",
     "mozilla/dom/Element.h",
     "mozilla/dom/ChildIterator.h",
     "mozilla/dom/NameSpaceConstants.h",
     "mozilla/LookAndFeel.h",
     "mozilla/StaticPrefs.h",
     "mozilla/GeckoBindings.h",
+    "mozilla/ServoBindings.h",
     "mozilla/ComputedStyle.h",
     "mozilla/ServoTraversalStatistics.h",
     "mozilla/SizeOfState.h",
     "nsCSSProps.h",
     "nsContentUtils.h",
     "nsNameSpaceManager.h",
     "nsMediaFeatures.h",
     "nsXBLBinding.h",
@@ -41,17 +42,16 @@ raw-lines = [
     "pub use self::root::*;",
     "pub use self::root::mozilla::*;",
     "pub use self::root::mozilla::css::*;",
     "pub use self::root::mozilla::dom::*;",
     "use atomic_refcell::AtomicRefCell;",
     "use data::ElementData;",
 ]
 hide-types = [
-    "nsString",
     ".*char_traits",
     ".*incompatible_char_type",
     # https://github.com/rust-lang/rust-bindgen/issues/1503
     "mozilla::StyleTimingFunction.*",
 ]
 bitfield-enums = [
     "nsChangeHint",
     "mozilla::OriginFlags",
@@ -463,41 +463,19 @@ mapped-generic-types = [
     { generic = true, gecko = "mozilla::RustCell", servo = "::std::cell::Cell" },
     { generic = false, gecko = "ServoNodeData", servo = "AtomicRefCell<ElementData>" },
     { generic = false, gecko = "mozilla::ServoWritingMode", servo = "::logical_geometry::WritingMode" },
     { generic = false, gecko = "mozilla::ServoCustomPropertiesMap", servo = "Option<::servo_arc::Arc<::custom_properties::CustomPropertiesMap>>" },
     { generic = false, gecko = "mozilla::ServoRuleNode", servo = "Option<::rule_tree::StrongRuleNode>" },
     { generic = false, gecko = "mozilla::ServoVisitedStyle", servo = "Option<::servo_arc::RawOffsetArc<::properties::ComputedValues>>" },
     { generic = false, gecko = "mozilla::ServoComputedValueFlags", servo = "::properties::computed_value_flags::ComputedValueFlags" },
     { generic = true, gecko = "mozilla::ServoRawOffsetArc", servo = "::servo_arc::RawOffsetArc" },
-    { generic = false, gecko = "ComputedStyleStrong", servo = "::gecko_bindings::sugar::ownership::Strong<::properties::ComputedValues>" },
-]
-fixups = [
-    { pat = "\\broot\\s*::\\s*nsString\\b", rep = "::nsstring::nsStringRepr" },
-    { pat = "\\broot\\s*::\\s*nsTString\\s*<\\s*u16\\s*>", rep = "::nsstring::nsStringRepr" },
+    { generic = false, gecko = "nsACString", servo = "nsstring::nsACString" },
+    { generic = false, gecko = "nsAString", servo = "nsstring::nsAString" },
+    { generic = false, gecko = "nsCString", servo = "nsstring::nsCString" },
+    { generic = false, gecko = "nsString", servo = "nsstring::nsStringRepr" },
 ]
 
-[bindings]
-headers = [
-    "mozilla/GeckoBindings.h",
-    # We include ServoBindings.h so we can type check the C function declarations
-    # in there against the function definitions in servo/ports/gecko/glue.rs.
-    "mozilla/ServoBindings.h",
-]
-hide-types = [
-    "nsACString_internal",
-    "nsAString_internal",
+whitelist-functions = ["Servo_.*", "Gecko_.*"]
+
+fixups = [
+    { pat = "\\broot\\s*::\\s*nsTString\\s*<\\s*u16\\s*>", rep = "::nsstring::nsStringRepr" },
 ]
-raw-lines = [
-    "pub use nsstring::{nsACString, nsAString, nsCString, nsString, nsStringRepr};",
-    "use gecko_bindings::structs::*;",
-    "use gecko_bindings::structs::mozilla::gfx::*;",
-    "use gecko_bindings::structs::nsStyleTransformMatrix::*;",
-    "type nsACString_internal = nsACString;",
-    "type nsAString_internal = nsAString;",
-]
-whitelist-functions = ["Servo_.*", "Gecko_.*"]
-fixups = [
-    # Remap the templated string type to the helper type
-    { pat = "\\bnsTString\\s*<\\s*u16\\s*>", rep = "nsString" },
-    # hack for gecko-owned string
-    { pat = "<\\s*nsString\\s*", rep = "<nsStringRepr" },
-]
--- a/servo/components/style/build_gecko.rs
+++ b/servo/components/style/build_gecko.rs
@@ -27,17 +27,16 @@ mod bindings {
     use std::process::{exit, Command};
     use std::slice;
     use std::sync::Mutex;
     use std::time::SystemTime;
     use toml;
     use toml::value::Table;
 
     const STRUCTS_FILE: &'static str = "structs.rs";
-    const BINDINGS_FILE: &'static str = "bindings.rs";
 
     fn read_config(path: &PathBuf) -> Table {
         println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
         update_last_modified(&path);
 
         let mut contents = String::new();
         File::open(path)
             .expect("Failed to open config file")
@@ -290,20 +289,21 @@ mod bindings {
             }
             self.builder
         }
     }
 
     fn generate_structs() {
         let builder = Builder::get_initial_builder()
             .enable_cxx_namespaces()
-            .with_codegen_config(CodegenConfig::TYPES | CodegenConfig::VARS);
+            .with_codegen_config(CodegenConfig::TYPES | CodegenConfig::VARS | CodegenConfig::FUNCTIONS);
         let mut fixups = vec![];
         let builder = BuilderWithConfig::new(builder, CONFIG["structs"].as_table().unwrap())
             .handle_common(&mut fixups)
+            .handle_str_items("whitelist-functions", |b, item| b.whitelist_function(item))
             .handle_str_items("bitfield-enums", |b, item| b.bitfield_enum(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_table_items("cbindgen-types", |b, item| {
                 let gecko = item["gecko"].as_str().unwrap();
                 let servo = item["servo"].as_str().unwrap();
@@ -384,30 +384,16 @@ mod bindings {
             .expect("Failed to set logger.");
 
             true
         } else {
             false
         }
     }
 
-    // FIXME(emilio): Avoid this altogether.
-    fn generate_bindings() {
-        let builder = Builder::get_initial_builder()
-            .disable_name_namespacing()
-            .with_codegen_config(CodegenConfig::FUNCTIONS);
-        let config = CONFIG["bindings"].as_table().unwrap();
-        let mut fixups = vec![];
-        let builder = BuilderWithConfig::new(builder, config)
-            .handle_common(&mut fixups)
-            .handle_str_items("whitelist-functions", |b, item| b.whitelist_function(item))
-            .get_builder();
-        write_binding_file(builder, BINDINGS_FILE, &fixups);
-    }
-
     fn generate_atoms() {
         let script = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap())
             .join("gecko")
             .join("regen_atoms.py");
         println!("cargo:rerun-if-changed={}", script.display());
         let status = Command::new(&*PYTHON)
             .arg(&script)
             .arg(DISTDIR_PATH.as_os_str())
@@ -415,34 +401,19 @@ mod bindings {
             .status()
             .unwrap();
         if !status.success() {
             exit(1);
         }
     }
 
     pub fn generate() {
-        use std::thread;
-        macro_rules! run_tasks {
-            ($($task:expr,)+) => {
-                if setup_logging() {
-                    $($task;)+
-                } else {
-                    let threads = vec![$( thread::spawn(|| $task) ),+];
-                    for thread in threads.into_iter() {
-                        thread.join().unwrap();
-                    }
-                }
-            }
-        }
-        run_tasks! {
-            generate_structs(),
-            generate_bindings(),
-            generate_atoms(),
-        }
+        setup_logging();
+        generate_structs();
+        generate_atoms();
 
         for path in ADDED_PATHS.lock().unwrap().iter() {
             println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
         }
     }
 }
 
 #[cfg(not(feature = "bindgen"))]
--- a/servo/components/style/gecko_bindings/mod.rs
+++ b/servo/components/style/gecko_bindings/mod.rs
@@ -1,28 +1,25 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
 
 //! Gecko's C++ bindings, along with some rust helpers to ease its use.
 
-#[allow(dead_code, improper_ctypes, non_camel_case_types, missing_docs)]
-pub mod bindings {
-    include!(concat!(env!("OUT_DIR"), "/gecko/bindings.rs"));
-}
-
 // FIXME: We allow `improper_ctypes` (for now), because the lint doesn't allow
 // foreign structs to have `PhantomData`. We should remove this once the lint
 // ignores this case.
 
 #[allow(
     dead_code,
     improper_ctypes,
     non_camel_case_types,
     non_snake_case,
     non_upper_case_globals,
     missing_docs
 )]
 pub mod structs {
     include!(concat!(env!("OUT_DIR"), "/gecko/structs.rs"));
 }
 
+pub use self::structs as bindings;
+
 pub mod sugar;