Update the regen script to use the new bindgen.

This commit is contained in:
Emilio Cobos Álvarez 2016-09-14 12:02:33 -07:00
parent 234951e4b6
commit ba89188e8b
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -23,8 +23,7 @@ COMPILATION_TARGETS = {
# Flags common for all the targets. # Flags common for all the targets.
COMMON_BUILD_KEY: { COMMON_BUILD_KEY: {
"flags": [ "flags": [
"--allow-unknown-types", "--no-unstable-rust", "--no-unstable-rust", "--no-type-renaming",
"--no-type-renaming", "--no-namespaced-constants",
], ],
"clang_flags": [ "clang_flags": [
"-x", "c++", "-std=c++14", "-x", "c++", "-std=c++14",
@ -52,6 +51,7 @@ COMPILATION_TARGETS = {
"{}/dist/include/nsThemeConstants.h", "{}/dist/include/nsThemeConstants.h",
"{}/dist/include/mozilla/dom/AnimationEffectReadOnlyBinding.h", "{}/dist/include/mozilla/dom/AnimationEffectReadOnlyBinding.h",
"{}/dist/include/mozilla/ServoElementSnapshot.h", "{}/dist/include/mozilla/ServoElementSnapshot.h",
"{}/dist/include/mozilla/dom/Element.h",
], ],
"files": [ "files": [
"{}/dist/include/nsStyleStruct.h", "{}/dist/include/nsStyleStruct.h",
@ -66,48 +66,104 @@ COMPILATION_TARGETS = {
"release": { "release": {
} }
}, },
"match_headers": [ "whitelist_vars": [
"RefCountType.h", "nscore.h", "nsError.h", "nsID.h", "nsString", "NS_THEME_.*",
"nsAString", "nsSubstring", "nsTSubstring", "nsTString", "NODE_.*",
"nsISupportsBase.h", "nsCOMPtr.h", "nsIAtom.h", "nsIURI.h", "NS_FONT_STYLE_.*",
"nsAutoPtr.h", "nsColor.h", "nsCoord.h", "nsPoint.h", "nsRect.h", "NS_STYLE_.*",
"nsMargin.h", "nsThemeConstants.h", "nsCSSProperty.h", "nsCSSPropertyID.h", "NS_CORNER_.*",
"CSSVariableValues.h", "nsFont.h", "nsTHashtable.h", "NS_RADIUS_.*",
"PLDHashTable.h", "nsColor.h", "nsStyleStruct.h", "nsStyleCoord.h", "BORDER_COLOR_.*",
"RefPtr.h", "nsISupportsImpl.h", "gfxFontConstants.h", "BORDER_STYLE_.*"
"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"
], ],
"blacklist": [ "whitelist": [
"IsDestructibleFallbackImpl", "IsDestructibleFallback", "Element",
"ProxyReleaseEvent", "FallibleTArray", "nsTArray_Impl", "Side",
"__is_tuple_like_impl", "tuple_size", "tuple", "nsTArrayHeader",
"__make_pair_return_impl", "__make_pair_return", "tuple_element", "nsCSSValueGradient",
"_Itup_cat", "AnimationEffectTimingProperties", "nsCSSValueList_heap",
"FastAnimationEffectTimingProperties", "ComputedTimingProperties", "FrameRequestCallback",
"FastComputedTimingProperties", "nsCSSValueTriplet_heap",
"nsINode", "nsCSSRect_heap",
"HasPointerType" "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": [ "opaque_types": [
"nsIntMargin", "nsIntPoint", "nsIntRect", "nsCOMArray", "nsAString_internal_char_traits",
"nsDependentString", "EntryStore", "gfxFontFeatureValueSet", "nsAString_internal_incompatible_char_type",
"imgRequestProxy", "imgRequestProxyStatic", "CounterStyleManager", "nsACString_internal_char_traits",
"ImageValue", "URLValue", "URLValueData", "nsIPrincipal", "nsACString_internal_incompatible_char_type",
"nsDataHashtable", "imgIRequest", "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 "Maybe", # <- AlignedStorage, which means templated union, which
# means impossible to represent in stable rust as of # means impossible to represent in stable rust as of
# right now. # right now.
"gfxSize", # <- Same, union { struct { T width; T height; }; T components[2] };
"gfxSize_Super", # Ditto.
], ],
}, },
# Generation of the ffi bindings. # Generation of the ffi bindings.
@ -139,15 +195,13 @@ COMPILATION_TARGETS = {
"nsStyleOutline", "nsStyleXUL", "nsStyleSVGReset", "nsStyleColumn", "nsStyleOutline", "nsStyleXUL", "nsStyleSVGReset", "nsStyleColumn",
"nsStyleEffects", "nsStyleImage", "nsStyleGradient", "nsStyleEffects", "nsStyleImage", "nsStyleGradient",
"nsStyleCoord", "nsStyleGradientStop", "nsStyleImageLayers", "nsStyleCoord", "nsStyleGradientStop", "nsStyleImageLayers",
"nsStyleImageLayers::Layer", "nsStyleImageLayers::LayerType", "nsStyleImageLayers_Layer", "nsStyleImageLayers_LayerType",
"nsStyleUnit", "nsStyleUnion", "nsStyleCoord::CalcValue", "nsStyleUnit", "nsStyleUnion", "nsStyleCoord_CalcValue",
"nsStyleCoord::Calc", "nsRestyleHint", "ServoElementSnapshot", "nsStyleCoord_Calc", "nsRestyleHint", "ServoElementSnapshot",
"nsChangeHint", "SheetParsingMode", "nsMainThreadPtrHandle", "nsChangeHint", "SheetParsingMode", "nsMainThreadPtrHandle",
"nsMainThreadPtrHolder", "nscolor", "nsFont", "FontFamilyList", "nsMainThreadPtrHolder", "nscolor", "nsFont", "FontFamilyList",
"FontFamilyType", "nsIAtom", "nsStyleContext", "StyleClipPath", "FontFamilyType", "nsIAtom", "nsStyleContext", "StyleClipPath",
"StyleBasicShapeType", "StyleBasicShape", "nsCSSShadowArray", "StyleBasicShapeType", "StyleBasicShape", "nsCSSShadowArray",
],
"void_types": [
"nsINode", "nsIDocument", "nsIPrincipal", "nsIURI", "nsINode", "nsIDocument", "nsIPrincipal", "nsIURI",
], ],
"servo_nullable_arc_types": [ "servo_nullable_arc_types": [
@ -164,6 +218,10 @@ COMPILATION_TARGETS = {
"RawGeckoElement", "RawGeckoElement",
"RawGeckoDocument", "RawGeckoDocument",
], ],
"whitelist_functions": [
"Servo_.*",
"Gecko_.*"
]
}, },
"atoms": { "atoms": {
@ -323,24 +381,26 @@ def build(objdir, target_name, debug, debugger, kind_name=None,
clang_flags.append("-include") clang_flags.append("-include")
clang_flags.append(file_name.format(objdir)) clang_flags.append(file_name.format(objdir))
if "match_headers" in current_target: if "whitelist" in current_target:
for header in current_target["match_headers"]: for header in current_target["whitelist"]:
flags.append("--match") flags.append("--whitelist-type")
flags.append(header.format(objdir)) flags.append(header)
if "blacklist" in current_target: if "whitelist_functions" in current_target:
for ty in current_target["blacklist"]: for header in current_target["whitelist_functions"]:
flags.append("--blacklist-type") flags.append("--whitelist-function")
flags.append(ty) 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: if "opaque_types" in current_target:
for ty in current_target["opaque_types"]: for ty in current_target["opaque_types"]:
flags.append("--opaque-type") flags.append("--opaque-type")
flags.append(ty) 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: if "servo_nullable_arc_types" in current_target:
for ty in current_target["servo_nullable_arc_types"]: for ty in current_target["servo_nullable_arc_types"]:
flags.append("--blacklist-type") flags.append("--blacklist-type")
@ -356,6 +416,7 @@ def build(objdir, target_name, debug, debugger, kind_name=None,
flags.append("--raw-line") flags.append("--raw-line")
flags.append("pub type {0}Borrowed<'a> = &'a {0};".format(ty)) flags.append("pub type {0}Borrowed<'a> = &'a {0};".format(ty))
zero_size_type(ty, flags) zero_size_type(ty, flags)
if "servo_immutable_borrow_types" in current_target: if "servo_immutable_borrow_types" in current_target:
for ty in current_target["servo_immutable_borrow_types"]: for ty in current_target["servo_immutable_borrow_types"]:
flags.append("--blacklist-type") flags.append("--blacklist-type")
@ -367,6 +428,7 @@ def build(objdir, target_name, debug, debugger, kind_name=None,
flags.append("--raw-line") flags.append("--raw-line")
flags.append("pub type {0}BorrowedOrNull<'a> = ::sugar::ownership::Borrowed<'a, {0}>;".format(ty)) flags.append("pub type {0}BorrowedOrNull<'a> = ::sugar::ownership::Borrowed<'a, {0}>;".format(ty))
zero_size_type(ty, flags) zero_size_type(ty, flags)
if "servo_owned_types" in current_target: if "servo_owned_types" in current_target:
for ty in current_target["servo_owned_types"]: for ty in current_target["servo_owned_types"]:
flags.append("--blacklist-type") flags.append("--blacklist-type")
@ -396,39 +458,35 @@ def build(objdir, target_name, debug, debugger, kind_name=None,
flags.append("--raw-line") flags.append("--raw-line")
flags.append("pub type {0}OwnedOrNull = ::sugar::ownership::OwnedOrNull<{0}>;".format(ty)) flags.append("pub type {0}OwnedOrNull = ::sugar::ownership::OwnedOrNull<{0}>;".format(ty))
zero_size_type(ty, flags) zero_size_type(ty, flags)
if "structs_types" in current_target: if "structs_types" in current_target:
for ty in current_target["structs_types"]: for ty in current_target["structs_types"]:
ty_fragments = ty.split("::")
mangled_name = ty.replace("::", "_")
flags.append("--blacklist-type") flags.append("--blacklist-type")
flags.append(ty_fragments[-1]) flags.append(ty)
flags.append("--raw-line") flags.append("--raw-line")
if len(ty_fragments) > 1: flags.append("use structs::{};".format(ty))
flags.append("use structs::{} as {};".format(mangled_name, ty_fragments[-1]))
else:
flags.append("use structs::{};".format(mangled_name))
# TODO: this is hacky, figure out a better way to do it without # TODO: this is hacky, figure out a better way to do it without
# hardcoding everything... # hardcoding everything...
if ty_fragments[-1].startswith("nsStyle"): if ty.startswith("nsStyle"):
flags.extend([ flags.extend([
"--raw-line", "--raw-line",
"unsafe impl Send for {} {{}}".format(ty_fragments[-1]), "unsafe impl Send for {} {{}}".format(ty),
"--raw-line", "--raw-line",
"unsafe impl Sync for {} {{}}".format(ty_fragments[-1]), "unsafe impl Sync for {} {{}}".format(ty),
"--raw-line",
"impl HeapSizeOf for {} {{ fn heap_size_of_children(&self) -> usize {{ 0 }} }}"
.format(ty_fragments[-1])
]) ])
flags.append("-o") flags.append("-o")
flags.append(output_filename) flags.append(output_filename)
# TODO: support more files, that's the whole point of this.
assert len(current_target["files"]) == 1 assert len(current_target["files"]) == 1
flags.append(current_target["files"][0].format(objdir)) flags.append(current_target["files"][0].format(objdir))
flags = bindgen + flags + ["--"] + clang_flags flags = bindgen + flags + ["--"] + clang_flags
if verbose:
print(flags)
output = "" output = ""
try: try:
if debug: if debug: