This commit is contained in:
Ashwin Naren 2025-06-04 00:56:01 +02:00 committed by GitHub
commit a0f4410cca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 6 deletions

View file

@ -2191,7 +2191,8 @@ class CGImports(CGWrapper):
""" """
Generates the appropriate import/use statements. Generates the appropriate import/use statements.
""" """
def __init__(self, child, descriptors, callbacks, dictionaries, enums, typedefs, imports, config): def __init__(self, child, descriptors, callbacks, dictionaries, enums, typedefs, imports, config,
current_name=None):
""" """
Adds a set of imports. Adds a set of imports.
""" """
@ -2302,7 +2303,8 @@ class CGImports(CGWrapper):
parentName = descriptor.getParentName() parentName = descriptor.getParentName()
while parentName: while parentName:
descriptor = descriptorProvider.getDescriptor(parentName) descriptor = descriptorProvider.getDescriptor(parentName)
extras += [descriptor.bindingPath] if current_name != descriptor.ifaceName:
extras += [descriptor.path, descriptor.bindingPath]
parentName = descriptor.getParentName() parentName = descriptor.getParentName()
elif t.isType() and t.isRecord(): elif t.isType() and t.isRecord():
extras += ['crate::record::Record'] extras += ['crate::record::Record']
@ -7719,7 +7721,7 @@ class CGBindingRoot(CGThing):
Root codegen class for binding generation. Instantiate the class, and call Root codegen class for binding generation. Instantiate the class, and call
declare or define to generate header or cpp code (respectively). declare or define to generate header or cpp code (respectively).
""" """
def __init__(self, config, prefix, webIDLFile): def __init__(self, config, prefix, webIDLFile, name):
descriptors = config.getDescriptors(webIDLFile=webIDLFile, descriptors = config.getDescriptors(webIDLFile=webIDLFile,
hasInterfaceObject=True) hasInterfaceObject=True)
# We also want descriptors that have an interface prototype object # We also want descriptors that have an interface prototype object
@ -7787,7 +7789,7 @@ class CGBindingRoot(CGThing):
# These are the global imports (outside of the generated module) # These are the global imports (outside of the generated module)
curr = CGImports(curr, descriptors=callbackDescriptors, callbacks=mainCallbacks, curr = CGImports(curr, descriptors=callbackDescriptors, callbacks=mainCallbacks,
dictionaries=dictionaries, enums=enums, typedefs=typedefs, dictionaries=dictionaries, enums=enums, typedefs=typedefs,
imports=['crate::import::base::*'], config=config) imports=['crate::import::base::*'], config=config, current_name=name)
# Add the auto-generated comment. # Add the auto-generated comment.
curr = CGWrapper(curr, pre=f"{AUTOGENERATED_WARNING_COMMENT}{ALLOWED_WARNINGS}") curr = CGWrapper(curr, pre=f"{AUTOGENERATED_WARNING_COMMENT}{ALLOWED_WARNINGS}")

View file

@ -248,6 +248,7 @@ class Descriptor(DescriptorProvider):
self.inRealmMethods = [name for name in desc.get('inRealms', [])] self.inRealmMethods = [name for name in desc.get('inRealms', [])]
self.canGcMethods = [name for name in desc.get('canGc', [])] self.canGcMethods = [name for name in desc.get('canGc', [])]
self.additionalTraits = [name for name in desc.get('additionalTraits', [])] self.additionalTraits = [name for name in desc.get('additionalTraits', [])]
self.ifaceName = ifaceName
self.bindingPath = f"{getModuleFromObject(self.interface)}::{ifaceName}_Binding" self.bindingPath = f"{getModuleFromObject(self.interface)}::{ifaceName}_Binding"
self.outerObjectHook = desc.get('outerObjectHook', 'None') self.outerObjectHook = desc.get('outerObjectHook', 'None')
self.proxy = False self.proxy = False

View file

@ -72,8 +72,9 @@ def main():
for webidl in webidls: for webidl in webidls:
filename = os.path.join(webidls_dir, webidl) filename = os.path.join(webidls_dir, webidl)
prefix = "Bindings/%sBinding" % webidl[:-len(".webidl")] name = webidl[:-len(".webidl")]
module = CGBindingRoot(config, prefix, filename).define() prefix = "Bindings/%sBinding" % name
module = CGBindingRoot(config, prefix, filename, name).define()
if module: if module:
with open(os.path.join(out_dir, prefix + ".rs"), "wb") as f: with open(os.path.join(out_dir, prefix + ".rs"), "wb") as f:
f.write(module.encode("utf-8")) f.write(module.encode("utf-8"))