Update the regen script to use the new bindgen. draft
authorEmilio Cobos Álvarez <ecoal95@gmail.com>
Wed, 14 Sep 2016 12:02:33 -0700
changeset 416734 5589058096ab68da7e29f89376016d5c8dbd8417
parent 416438 d07acc0b279f23d10b8272a564a726d09aac8c76
child 416735 e8b317f1da85c9558f038132022e1c0c16d3829e
push id30240
push userbmo:bobbyholley@gmail.com
push dateFri, 23 Sep 2016 00:05:34 +0000
milestone51.0a1
Update the regen script to use the new bindgen.
servo/ports/geckolib/binding_tools/regen.py
--- a/servo/ports/geckolib/binding_tools/regen.py
+++ b/servo/ports/geckolib/binding_tools/regen.py
@@ -18,18 +18,17 @@ import regen_atoms
 DESCRIPTION = 'Regenerate the rust version of the structs or the bindings file.'
 TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
 COMMON_BUILD_KEY = "__common__"
 
 COMPILATION_TARGETS = {
     # Flags common for all the targets.
     COMMON_BUILD_KEY: {
         "flags": [
-            "--allow-unknown-types", "--no-unstable-rust",
-            "--no-type-renaming", "--no-namespaced-constants",
+            "--no-unstable-rust", "--no-type-renaming",
         ],
         "clang_flags": [
             "-x", "c++", "-std=c++14",
             "-DTRACING=1", "-DIMPL_LIBXUL", "-DMOZ_STYLO_BINDINGS=1",
             "-DMOZILLA_INTERNAL_API", "-DRUST_BINDGEN",
         ],
         "search_dirs": [
             "{}/dist/include",
@@ -47,72 +46,129 @@ COMPILATION_TARGETS = {
         "flags": [
             "--ignore-functions",
             "--ignore-methods",
         ],
         "includes": [
             "{}/dist/include/nsThemeConstants.h",
             "{}/dist/include/mozilla/dom/AnimationEffectReadOnlyBinding.h",
             "{}/dist/include/mozilla/ServoElementSnapshot.h",
+            "{}/dist/include/mozilla/dom/Element.h",
         ],
         "files": [
             "{}/dist/include/nsStyleStruct.h",
         ],
         "build_kinds": {
             "debug": {
                 "clang_flags": [
                     "-DDEBUG=1",
                     "-DJS_DEBUG=1",
                 ]
             },
             "release": {
             }
         },
-        "match_headers": [
-            "RefCountType.h", "nscore.h", "nsError.h", "nsID.h", "nsString",
-            "nsAString", "nsSubstring", "nsTSubstring", "nsTString",
-            "nsISupportsBase.h", "nsCOMPtr.h", "nsIAtom.h", "nsIURI.h",
-            "nsAutoPtr.h", "nsColor.h", "nsCoord.h", "nsPoint.h", "nsRect.h",
-            "nsMargin.h", "nsThemeConstants.h", "nsCSSProperty.h", "nsCSSPropertyID.h",
-            "CSSVariableValues.h", "nsFont.h", "nsTHashtable.h",
-            "PLDHashTable.h", "nsColor.h", "nsStyleStruct.h", "nsStyleCoord.h",
-            "RefPtr.h", "nsISupportsImpl.h", "gfxFontConstants.h",
-            "gfxFontFamilyList.h", "gfxFontFeatures.h", "imgRequestProxy.h",
-            "nsIRequest.h", "imgIRequest.h", "CounterStyleManager.h",
-            "nsStyleConsts.h", "nsCSSValue.h", "SheetType.h", "nsIPrincipal.h",
-            "nsDataHashtable.h", "nsCSSScanner.h", "nsTArray",
-            "pair", "SheetParsingMode.h", "StaticPtr.h", "nsProxyRelease.h",
-            "mozilla/dom/AnimationEffectReadOnlyBinding.h",
-            "nsChangeHint.h", "ServoElementSnapshot.h",
-            "EventStates.h", "nsAttrValue.h", "nsAttrName.h",
-            "/Types.h",   # <- Disallow UnionTypes.h
-            "/utility",   # <- Disallow xutility
-            "nsINode.h",  # <- For `NodeFlags`.
-            "UniquePtr.h"
+        "whitelist_vars": [
+            "NS_THEME_.*",
+            "NODE_.*",
+            "NS_FONT_STYLE_.*",
+            "NS_STYLE_.*",
+            "NS_CORNER_.*",
+            "NS_RADIUS_.*",
+            "BORDER_COLOR_.*",
+            "BORDER_STYLE_.*"
         ],
-        "blacklist": [
-            "IsDestructibleFallbackImpl", "IsDestructibleFallback",
-            "ProxyReleaseEvent", "FallibleTArray", "nsTArray_Impl",
-            "__is_tuple_like_impl", "tuple_size", "tuple",
-            "__make_pair_return_impl", "__make_pair_return", "tuple_element",
-            "_Itup_cat", "AnimationEffectTimingProperties",
-            "FastAnimationEffectTimingProperties", "ComputedTimingProperties",
-            "FastComputedTimingProperties",
-            "nsINode",
-            "HasPointerType"
+        "whitelist": [
+            "Element",
+            "Side",
+            "nsTArrayHeader",
+            "nsCSSValueGradient",
+            "nsCSSValueList_heap",
+            "FrameRequestCallback",
+            "nsCSSValueTriplet_heap",
+            "nsCSSRect_heap",
+            "AnonymousContent",
+            "nsCSSValuePairList",
+            "nsCSSValuePairList_heap",
+            "nsCSSValuePair_heap",
+            "CapturingContentInfo",
+            "Runnable",
+            "AudioContext",
+            "FontFamilyListRefCnt",
+            "ImageURL",
+            "Image",
+            "nsCSSValueFloatColor",
+            "ServoAttrSnapshot",
+            "GridNamedArea",
+            "nsAttrName",
+            "nsAttrValue",
+            "nsCSSRect",
+            "gfxFontFeature",
+            "gfxAlternateValue",
+            "nsCSSValueTokenStream",
+            "nsSize",
+            "pair",
+            "StyleClipPathGeometryBox",
+            "FontFamilyName",
+            "nsCSSPropertyID",
+            "StyleAnimation",
+            "StyleTransition",
+            "nsresult",
+            "nsCSSValueGradientStop",
+            "nsBorderColors",
+            "Position",
+            "nsCSSValueList",
+            "nsCSSValue",
+            "UniquePtr", "DefaultDelete",
+            "StyleBasicShape",
+            "nsMargin",
+            "nsStyleContentData",
+            "nsStyleFilter", "nsRect", "FragmentOrURL", "nsStyleCoord",
+            "nsStyleCounterData", "StaticRefPtr", "nsTArray", "nsStyleFont",
+            "nsStyleColor", "nsStyleList", "nsStyleText", "nsStyleVisibility",
+            "nsStyleUserInterface", "nsStyleTableBorder", "nsStyleSVG",
+            "nsStyleVariables", "nsStyleBackground", "nsStylePosition",
+            "nsStyleTextReset", "nsStyleDisplay", "nsStyleContent",
+            "nsStyleUIReset", "nsStyleTable", "nsStyleMargin",
+            "nsStylePadding", "nsStyleBorder", "nsStyleOutline", "nsStyleXUL",
+            "nsStyleSVGReset", "nsStyleColumn", "nsStyleEffects",
+            "nsStyleImage", "nsStyleGradient", "nsStyleCoord",
+            "nsStyleGradientStop", "nsStyleImageLayers",
+            "nsStyleImageLayers_Layer", "nsStyleImageLayers_LayerType",
+            "nsStyleUnit", "nsStyleUnion", "nsStyleCoord", "nsRestyleHint",
+            "ServoElementSnapshot", "nsChangeHint", "SheetParsingMode",
+            "nsMainThreadPtrHandle", "nsMainThreadPtrHolder", "nscolor",
+            "nsFont", "FontFamilyList", "FontFamilyType", "nsIAtom",
+            "nsStyleContext", "StyleClipPath", "StyleBasicShapeType",
+            "StyleBasicShape", "nsCSSShadowArray",
         ],
         "opaque_types": [
-            "nsIntMargin", "nsIntPoint", "nsIntRect", "nsCOMArray",
-            "nsDependentString", "EntryStore", "gfxFontFeatureValueSet",
-            "imgRequestProxy", "imgRequestProxyStatic", "CounterStyleManager",
-            "ImageValue", "URLValue", "URLValueData", "nsIPrincipal",
-            "nsDataHashtable", "imgIRequest",
+            "nsAString_internal_char_traits",
+            "nsAString_internal_incompatible_char_type",
+            "nsACString_internal_char_traits",
+            "nsACString_internal_incompatible_char_type",
+            "RefPtr_Proxy_member_function", "nsAutoPtr_Proxy_member_function",
+            "Heap", "TenuredHeap", "Rooted", "WeakPtr",  # <- More template magic than what
+                                                         #    we support.
+            "nsTObserverArray",  # <- Inherits from nsAutoTObserverArray<T, 0>
+            "PLArenaPool",  # <- Bindgen bug
+            "nsTHashtable",  # <- Inheriting from inner typedefs that clang
+                             #    doesn't expose properly.
+            "nsRefPtrHashtable", "nsDataHashtable", "nsClassHashtable",  # <- Ditto
+            "nsIDocument_SelectorCache",  # <- Inherits from nsExpirationTracker<.., 4>
+            "nsIPresShell_ScrollAxis",  # <- For some reason the alignment of this is 4
+                                        # for clang.
+            "nsPIDOMWindow",  # <- Takes the vtable from a template parameter, and we can't
+                              #    generate it conditionally.
+            "SupportsWeakPtr",
             "Maybe",  # <- AlignedStorage, which means templated union, which
-                      # means impossible to represent in stable rust as of
-                      # right now.
+                      #    means impossible to represent in stable rust as of
+                      #    right now.
+            "gfxSize",  # <- Same, union { struct { T width; T height; }; T components[2] };
+            "gfxSize_Super",  # Ditto.
         ],
     },
     # Generation of the ffi bindings.
     "bindings": {
         "target_dir": "../gecko_bindings",
         "raw_lines": [
             "use heapsize::HeapSizeOf;",
         ],
@@ -134,41 +190,43 @@ COMPILATION_TARGETS = {
             "nsStyleVisibility", "nsStyleUserInterface", "nsStyleTableBorder",
             "nsStyleSVG", "nsStyleVariables", "nsStyleBackground",
             "nsStylePosition", "nsStyleTextReset", "nsStyleDisplay",
             "nsStyleContent", "nsStyleUIReset", "nsStyleTable",
             "nsStyleMargin", "nsStylePadding", "nsStyleBorder",
             "nsStyleOutline", "nsStyleXUL", "nsStyleSVGReset", "nsStyleColumn",
             "nsStyleEffects", "nsStyleImage", "nsStyleGradient",
             "nsStyleCoord", "nsStyleGradientStop", "nsStyleImageLayers",
-            "nsStyleImageLayers::Layer", "nsStyleImageLayers::LayerType",
-            "nsStyleUnit", "nsStyleUnion", "nsStyleCoord::CalcValue",
-            "nsStyleCoord::Calc", "nsRestyleHint", "ServoElementSnapshot",
+            "nsStyleImageLayers_Layer", "nsStyleImageLayers_LayerType",
+            "nsStyleUnit", "nsStyleUnion", "nsStyleCoord_CalcValue",
+            "nsStyleCoord_Calc", "nsRestyleHint", "ServoElementSnapshot",
             "nsChangeHint", "SheetParsingMode", "nsMainThreadPtrHandle",
             "nsMainThreadPtrHolder", "nscolor", "nsFont", "FontFamilyList",
             "FontFamilyType", "nsIAtom", "nsStyleContext", "StyleClipPath",
             "StyleBasicShapeType", "StyleBasicShape", "nsCSSShadowArray",
-        ],
-        "void_types": [
             "nsINode", "nsIDocument", "nsIPrincipal", "nsIURI",
         ],
         "servo_nullable_arc_types": [
             "ServoComputedValues", "RawServoStyleSheet",
             "ServoDeclarationBlock"
         ],
         "servo_owned_types": [
             "RawServoStyleSet",
             "ServoNodeData",
             "StyleChildrenIterator",
         ],
         "servo_immutable_borrow_types": [
             "RawGeckoNode",
             "RawGeckoElement",
             "RawGeckoDocument",
         ],
+        "whitelist_functions": [
+            "Servo_.*",
+            "Gecko_.*"
+        ]
     },
 
     "atoms": {
         "custom_build": regen_atoms.build,
     }
 }
 
 
@@ -318,60 +376,64 @@ def build(objdir, target_name, debug, de
             clang_flags.append("-I")
             clang_flags.append(dir_name.format(objdir))
 
     if "includes" in current_target:
         for file_name in current_target["includes"]:
             clang_flags.append("-include")
             clang_flags.append(file_name.format(objdir))
 
-    if "match_headers" in current_target:
-        for header in current_target["match_headers"]:
-            flags.append("--match")
-            flags.append(header.format(objdir))
+    if "whitelist" in current_target:
+        for header in current_target["whitelist"]:
+            flags.append("--whitelist-type")
+            flags.append(header)
 
-    if "blacklist" in current_target:
-        for ty in current_target["blacklist"]:
-            flags.append("--blacklist-type")
-            flags.append(ty)
+    if "whitelist_functions" in current_target:
+        for header in current_target["whitelist_functions"]:
+            flags.append("--whitelist-function")
+            flags.append(header)
+
+    if "whitelist_vars" in current_target:
+        for header in current_target["whitelist_vars"]:
+            flags.append("--whitelist-var")
+            flags.append(header)
 
     if "opaque_types" in current_target:
         for ty in current_target["opaque_types"]:
             flags.append("--opaque-type")
             flags.append(ty)
-    if "void_types" in current_target:
-        for ty in current_target["void_types"]:
-            flags.append("--raw-line")
-            flags.append("pub enum {} {{}}".format(ty))
+
     if "servo_nullable_arc_types" in current_target:
         for ty in current_target["servo_nullable_arc_types"]:
             flags.append("--blacklist-type")
             flags.append("{}Strong".format(ty))
             flags.append("--raw-line")
             flags.append("pub type {0}Strong = ::sugar::ownership::Strong<{0}>;".format(ty))
             flags.append("--blacklist-type")
             flags.append("{}BorrowedOrNull".format(ty))
             flags.append("--raw-line")
             flags.append("pub type {0}BorrowedOrNull<'a> = ::sugar::ownership::Borrowed<'a, {0}>;".format(ty))
             flags.append("--blacklist-type")
             flags.append("{}Borrowed".format(ty))
             flags.append("--raw-line")
             flags.append("pub type {0}Borrowed<'a> = &'a {0};".format(ty))
             zero_size_type(ty, flags)
+
     if "servo_immutable_borrow_types" in current_target:
         for ty in current_target["servo_immutable_borrow_types"]:
             flags.append("--blacklist-type")
             flags.append("{}Borrowed".format(ty))
             flags.append("--raw-line")
             flags.append("pub type {0}Borrowed<'a> = &'a {0};".format(ty))
             flags.append("--blacklist-type")
             flags.append("{}BorrowedOrNull".format(ty))
             flags.append("--raw-line")
             flags.append("pub type {0}BorrowedOrNull<'a> = ::sugar::ownership::Borrowed<'a, {0}>;".format(ty))
             zero_size_type(ty, flags)
+
     if "servo_owned_types" in current_target:
         for ty in current_target["servo_owned_types"]:
             flags.append("--blacklist-type")
             flags.append("{}Borrowed".format(ty))
             flags.append("--raw-line")
             flags.append("pub type {0}Borrowed<'a> = &'a {0};".format(ty))
             flags.append("--blacklist-type")
             flags.append("{}BorrowedMut".format(ty))
@@ -391,49 +453,45 @@ def build(objdir, target_name, debug, de
             flags.append("--raw-line")
             flags.append("pub type {0}BorrowedMutOrNull<'a> = ::sugar::ownership::BorrowedMut<'a, {0}>;"
                          .format(ty))
             flags.append("--blacklist-type")
             flags.append("{}OwnedOrNull".format(ty))
             flags.append("--raw-line")
             flags.append("pub type {0}OwnedOrNull = ::sugar::ownership::OwnedOrNull<{0}>;".format(ty))
             zero_size_type(ty, flags)
+
     if "structs_types" in current_target:
         for ty in current_target["structs_types"]:
-            ty_fragments = ty.split("::")
-            mangled_name = ty.replace("::", "_")
             flags.append("--blacklist-type")
-            flags.append(ty_fragments[-1])
+            flags.append(ty)
             flags.append("--raw-line")
-            if len(ty_fragments) > 1:
-                flags.append("use structs::{} as {};".format(mangled_name, ty_fragments[-1]))
-            else:
-                flags.append("use structs::{};".format(mangled_name))
+            flags.append("use structs::{};".format(ty))
+
             # TODO: this is hacky, figure out a better way to do it without
             # hardcoding everything...
-            if ty_fragments[-1].startswith("nsStyle"):
+            if ty.startswith("nsStyle"):
                 flags.extend([
                     "--raw-line",
-                    "unsafe impl Send for {} {{}}".format(ty_fragments[-1]),
+                    "unsafe impl Send for {} {{}}".format(ty),
                     "--raw-line",
-                    "unsafe impl Sync for {} {{}}".format(ty_fragments[-1]),
-                    "--raw-line",
-                    "impl HeapSizeOf for {} {{ fn heap_size_of_children(&self) -> usize {{ 0 }} }}"
-                    .format(ty_fragments[-1])
+                    "unsafe impl Sync for {} {{}}".format(ty),
                 ])
 
     flags.append("-o")
     flags.append(output_filename)
 
-    # TODO: support more files, that's the whole point of this.
     assert len(current_target["files"]) == 1
     flags.append(current_target["files"][0].format(objdir))
 
     flags = bindgen + flags + ["--"] + clang_flags
 
+    if verbose:
+        print(flags)
+
     output = ""
     try:
         if debug:
             flags = [debugger, "--args"] + flags
             subprocess.check_call(flags)
         else:
             output = subprocess.check_output(flags, stderr=subprocess.STDOUT)
             output = output.decode('utf8')