Make a bindings.h header file with the declarations, so that other projects can reuse the declared structs.

Add parseXMLString overload that supports passing in an MjVFS.

PiperOrigin-RevId: 940579266
Change-Id: I8294988bc4279e80795fab21024f64562a9e6743
This commit is contained in:
Google DeepMind
2026-06-30 11:55:24 -07:00
committed by Copybara-Service
parent e2d7955437
commit 095608ef5f
7 changed files with 7965 additions and 7813 deletions
+17 -15
View File
@@ -25,13 +25,7 @@ from wasm.codegen.generators import structs
class BindingBuilder:
"""Builds WASM bindings for MuJoCo."""
def __init__(
self,
template_path_cc: str,
):
with open(template_path_cc, "r") as f:
self.content_cc = f.readlines()
def __init__(self):
self.markers_and_content = []
def set_enums(self):
@@ -57,17 +51,25 @@ class BindingBuilder:
self.markers_and_content += functions.generate(functions_to_bind)
return self
def to_string(self) -> str:
for marker, content in self.markers_and_content:
self.content_cc = common.replace_lines_containing_marker(
self.content_cc, marker, content
def build_string(self, template_path: str) -> str:
"""Applies the accumulated bindings to a template file and returns the output."""
with open(template_path, "r") as f:
content = f.readlines()
for marker, lines in self.markers_and_content:
content = common.replace_lines_containing_marker(
content, marker, lines
)
text = "".join(self.content_cc)
return text.replace(
text = "".join(content)
text = text.replace(
"// limitations under the License.\n\n",
"// limitations under the License.\n\n// DO NOT EDIT. THIS FILE IS AUTOMATICALLY GENERATED.\n\n",
1,
)
return text
def build(self, generated_path_cc: str):
common.write_to_file(generated_path_cc, self.to_string())
def build_file(self, template_path: str, generated_path: str):
"""Applies the accumulated bindings to a template file and writes the output."""
text = self.build_string(template_path)
common.write_to_file(generated_path, text)